Repository navigation
Expand file tree
/
Copy pathsystem_info.h
More file actions
157 lines (132 loc) · 3.75 KB
/
Copy pathsystem_info.h
File metadata and controls
157 lines (132 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2019, The Jackson Laboratory, Bar Harbor, Maine - all rights reserved
#ifndef SYSTEM_INFO_H
#define SYSTEM_INFO_H
#include <exception>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <sys/sysinfo.h>
#include <sys/types.h>
/**
* @brief store information about a monitored directory
*
*/
struct DiskInfo {
unsigned long capacity; ///capacity of mount in megabytes
unsigned long available; ///available disk space of mount in megabytes
};
/**
* @brief exception thrown if there is an error registering a directory to monitor
*
*/
class DiskRegistrationException : public std::exception {
private:
std::string message;
public:
DiskRegistrationException(std::string msg = "Error registering path") : message(msg) {}
virtual const char *what() const throw() {
return this->message.c_str();
}
};
/**
* @brief system information
*
* this class gathers system information such as total physical memory, memory available,
* available disk space, load average. This uses functionality only available on Linux
* and is non-portable.
*/
class SysInfo {
private:
float load_;
unsigned long mem_available_;
unsigned long mem_total_;
struct sysinfo system_info;
std::string hostname_;
std::string release_;
std::set <std::string> mount_points;
std::map <std::string, DiskInfo> disk_information;
void UpdateMemInfo();
unsigned long BlocksToMb(fsblkcnt_t blocks, unsigned long bsize);
public:
/**
* @brief constructor
*
* creates new SysInfo instance and calls the sample() method to initialize the
* state
*
*/
SysInfo();
/**
* @brief sample system information
*
* refreshes the view of the system by getting updated memory usage, load,
* disk usage, etc
*
* @return void
*/
void Sample();
std::string hostname() { return hostname_; }
/**
* @brief get amount of physical memory in kB
*
* @return amount of RAM
*/
unsigned long mem_total() { return mem_total_; }
/**
* @brief get memory available in kB
*
* @return memory available
*/
unsigned long mem_available() { return mem_available_; }
/**
* @brief get 1 minute load average
*
* @return floating point load average
*/
float load() { return load_; }
/**
* @brief get uptime in seconds
*
* @return number of seconds since boot
*/
unsigned long uptime() { return system_info.uptime; }
/**
* @brief get release string
*
* @return release (NVidia Tegra release string or Kernel Release)
*/
std::string release() { return release_; }
/**
* @brief register mount point
*
* register a mount point so that we will gather information about it (capacity,
* available space)
*
* @param path string containing path to mount
*/
void AddMount(const std::string path);
/**
* @brief clear list of registered mount points
*
*/
void ClearMounts();
/**
* @brief get mount points that have been registered for monitoring
*
* @return a vector of strings listing all registered mounts
*/
std::vector <std::string> registered_mounts();
/**
* @brief returns information about capacity and available disk space
*
* this method looks up a mount point, specified as a string, and returns the
* capacity and available disk space in a struct. This mount point must have been
* registered prior to the last call to sample(), otherwise reported capacity and
* available space will be zero
*
* @return a struct containing disk capacity and available space
*/
DiskInfo disk_info(const std::string mount);
};
#endif