31 #include <boost/algorithm/string.hpp>
91 if (categories &
CPU) {
103 if (categories &
SWAP) {
107 if (categories &
NET) {
111 if (categories &
PROC) {
121 for (
size_t i = 0; i < dirs.size(); i++) {
122 boost::trim_right_if(dirs[i], boost::is_any_of(
"/"));
127 if (categories &
DISK) {
130 for (
size_t i = 0; i < dirs.size(); i++)
133 if (categories &
FS) {
136 for (
size_t i = 0; i < dirs.size(); i++)
155 for (
size_t i = 0; i <
disk_stat.size(); i++)
160 for (
size_t i = 0; i <
fs_stat.size(); i++) {
162 if (simulate_disk_full)
169 if (StatsSerializable::operator!=(other))
209 for (
size_t i = 0; i <
disk_stat.size(); i++) {
217 for (
size_t i = 0; i <
fs_stat.size(); i++) {
226 if (group == CPUINFO_GROUP) {
230 else if (group == CPU_GROUP) {
233 else if (group == LOADAVG_GROUP) {
236 else if (group == MEMORY_GROUP) {
239 else if (group == DISK_GROUP) {
241 for (
size_t i = 0; i <
disk_stat.size(); i++) {
247 else if (group == SWAP_GROUP) {
250 else if (group == NETINFO_GROUP) {
256 else if (group == NET_GROUP) {
259 else if (group == OSINFO_GROUP) {
271 else if (group == PROCINFO_GROUP) {
281 else if (group == PROC_GROUP) {
284 else if (group == FS_GROUP) {
286 for (
size_t i = 0; i <
fs_stat.size(); i++) {
292 else if (group == TERMINFO_GROUP) {
296 HT_FATALF(
"Invalid group number (%d)", group);
301 if (group == CPUINFO_GROUP) {
310 else if (group == CPU_GROUP) {
321 else if (group == LOADAVG_GROUP) {
326 else if (group == MEMORY_GROUP) {
334 else if (group == DISK_GROUP) {
336 for (
size_t i = 0; i <
disk_stat.size(); i++) {
344 else if (group == SWAP_GROUP) {
351 else if (group == NETINFO_GROUP) {
357 else if (group == NET_GROUP) {
366 else if (group == OSINFO_GROUP) {
381 else if (group == PROCINFO_GROUP) {
391 else if (group == PROC_GROUP) {
405 else if (group == FS_GROUP) {
407 for (
size_t i = 0; i <
fs_stat.size(); i++) {
418 else if (group == TERMINFO_GROUP) {
424 HT_FATALF(
"Invalid group number (%d)", group);
429 if (group == CPUINFO_GROUP) {
439 else if (group == CPU_GROUP) {
451 else if (group == LOADAVG_GROUP) {
457 else if (group == MEMORY_GROUP) {
466 else if (group == DISK_GROUP) {
469 for (
size_t i = 0; i < count; i++) {
478 else if (group == SWAP_GROUP) {
486 else if (group == NETINFO_GROUP) {
493 else if (group == NET_GROUP) {
503 else if (group == OSINFO_GROUP) {
519 else if (group == PROCINFO_GROUP) {
526 for (
size_t i = 0; i < len; i++)
530 else if (group == PROC_GROUP) {
545 else if (group == FS_GROUP) {
548 for (
size_t i = 0; i < count; i++) {
560 else if (group == TERMINFO_GROUP) {
567 HT_WARNF(
"Unrecognized StatsSystem group %d, skipping...", group);
Abstract base class for managing serialized statistics.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
bool operator==(const StatsSystem &other) const
Equal operator.
virtual void encode_group(int group, uint8_t **bufp) const
Serializes a statistics group to memory.
int encoded_length_double()
Length of an encoded double (16 bytes)
#define HT_WARNF(msg,...)
The FailureInducer simulates errors.
struct NetInfo net_info
Network information (host name, primary interface, gateway etc)
virtual size_t encoded_length_group(int group) const
Returns the encoded length of a statistics group.
struct NetStat net_stat
Network statistics (transfer rates, receiving rate etc)
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
virtual void decode_group(int group, uint16_t len, const uint8_t **bufp, size_t *remainp)
Deserializes a statistics group from memory.
Collecting and (de)serializing system-wide statistics.
struct CpuInfo cpu_info
CPU information (vendor, model, cores, cache sizes etc)
struct TermInfo term_info
Terminal information (number of lines, number of columns etc)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
uint8_t group_count
Number of groups in group_ids.
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
int encoded_length_vi32(uint32_t val)
Length of a variable length encoded 32-bit integer (up to 5 bytes)
StatsSystem()
Default constructor; creates an empty object.
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
Logging routines and macros.
void refresh()
Refreshes the statistics.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_i16(uint8_t **bufp, uint16_t val)
Encode a 16-bit integer in little-endian order.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
struct ProcStat proc_stat
Process statistics (CPU user time, system time, vm size etc)
struct ProcInfo proc_info
Process information (pid, user, working directory etc)
Collects, serializes and deserializes system-wide statistics.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
#define HT_FATALF(msg,...)
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
std::vector< String > args
struct MemStat mem_stat
Memory statistics (total size, free space, used etc)
double decode_double(const uint8_t **bufp, size_t *remainp)
Decodes a double as 64-bit left-of-decimal, followed by 64-bit right-of-decimal, both in little-endia...
#define HT_FAILURE_SIGNALLED(_label_)
struct OsInfo os_info
OS information (name, architecture, version etc)
struct LoadAvgStat loadavg_stat
Load average normalized over number of cores.
std::vector< struct FsStat > fs_stat
Filesystem statistics (free space, used space, aggregate files etc)
struct SwapStat swap_stat
Swapping statistics (page in, page out etc)
void add_categories(int32_t categories)
Adds more categories to the already existing categories.
uint8_t group_ids[32]
The actual group IDs.
std::vector< struct DiskStat > disk_stat
Per-Disk statistics (read-rate, write-rate, etc)
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
struct CpuStat cpu_stat
CPU statistics (user load, system load, idle etc)
void encode_double(uint8_t **bufp, double val)
Encodes a double with 18 decimal digits of precision as 64-bit left-of-decimal, followed by 64-bit ri...