123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- /* from CIMS-Project */
- /* 数据采集模块内部结构 */
- /* 扩充请参考man proc */
- #ifndef __DATAAC_INNER_STRUCT_H
- #define __DATAAC_INNER_STRUCT_H
- /* common */
- #include "Types.h"
- /* perforence monitor */
- #include "MAS_Definition.h"
- NAMESPACE_MAS_BEGIN
- #define TZ_SYS_CLOCK sysconf(2)
- /* 查询系统信息相关结构 */
- /* !!结构内只定义需要的数据项 */
- /* /proc/stat */
- struct SysStatInfo {
- TZ_LONG user; /* 用户态的CPU时间(单位:jiffies),不包含低优先级用户模式 */
- TZ_LONG nice; /* 低优先级用户模式占用的CPU时间(单位:jiffies)*/
- TZ_LONG system; /* 系统核心态的CPU时间(单位:jiffies)*/
- TZ_LONG idle; /* 空闲状态下的CPU时间(单位:jiffies)*/
- TZ_LONG iowait; /* 硬盘IO等待占用的CPU时间(单位:jiffies)*/
- TZ_LONG irq; /* 硬中断占用的CPU时间(单位:jiffies) */
- TZ_LONG softirq; /* 软中断占用的CPU时间(单位:jiffies) */
- /* 返回总的cpu时间 */
- TZ_LONG GetCPUTime()
- {
- return user + nice + system + idle + iowait + irq + softirq;
- }
- SysStatInfo():user(0), nice(0), system(0),
- idle(0), iowait(0), irq(0), softirq(0) {};
- };
- /* /proc/meminfo */
- struct SysMemInfo {
- TZ_ULONG MemTotal; /* 所有可用的RAM大小 */
- TZ_ULONG MemAvailable; /* 系统实际可用内存,Linux 3.10后必含有参数 */
- SysMemInfo():MemTotal(0), MemAvailable(0) {};
- TZ_DOUBLE GetMemRate()
- {
- return TZ_DOUBLE(MemTotal - MemAvailable) / TZ_DOUBLE(MemTotal) * 100;
- }
- };
- /* /proc/diskstats */
- struct SysDiskStatInfo {
- TZ_LONG MainDevIndex; /* 主设备号 */
- TZ_LONG SubDevIndex; /* 次设备号 */
- std::string DevName; /* 设备名称 */
- TZ_LONG ReadFinishCount; /* 读完成次数。成功完成读磁盘的总次数 */
- TZ_LONG MergeReadFinishedCount; /* 合并读完成次数。为了效率可能会合并相邻的读和写 */
- TZ_LONG ReadSectionCount; /* 读扇区的总数 */
- TZ_LONG ReadMilinSeconds; /* 读花费的毫秒数,这是所有读操作所花费的毫秒数 */
- TZ_LONG WriteFinishedCount; /* 写完成次数。对应第1个域的读次数 */
- TZ_LONG MergeWriteFinishedCount; /* 合并写完成次数。对应第2个域的合并读次数 */
- TZ_LONG WriteSectionCount; /* 写扇区的总数。对应第3个域的读扇区总数 */
- TZ_LONG WriteMilinSeconds; /* 写操作花费的毫秒数。对应第4个域的读操作 */
- TZ_LONG ProcingIO; /* 正在处理的输入/输出请求数 */
- TZ_LONG IOMilinSeconds; /* 输入/输出操作花费的毫秒数 */
- TZ_LONG IOMilinSecondsAvg; /* 输入/输出操作花费的加权毫秒数 */
- TZ_LONG collectTime;
- SysDiskStatInfo():MainDevIndex(0), SubDevIndex(0), ReadFinishCount(0),
- MergeReadFinishedCount(0), ReadSectionCount(0), ReadMilinSeconds(0),
- WriteFinishedCount(0), MergeWriteFinishedCount(0), WriteSectionCount(0),
- WriteMilinSeconds(0), ProcingIO(0), IOMilinSeconds(0), IOMilinSecondsAvg(0),
- collectTime(0) {};
- };
- /* /proc/net/dev */
- struct SysNetBandInfo {
- private:
- struct _receive {
- TZ_ULONG bytes;
- TZ_ULONG packets;
- TZ_ULONG errs;
- TZ_ULONG drop;
- TZ_ULONG fifo;
- TZ_ULONG frame;
- TZ_ULONG compressed;
- TZ_ULONG multicast;
- _receive():bytes(0), packets(0), errs(0), drop(0),
- fifo(0), frame(0), compressed(0), multicast(0) {};
- };
- struct _transmit {
- TZ_ULONG bytes;
- TZ_ULONG packets;
- TZ_ULONG errs;
- TZ_ULONG drop;
- TZ_ULONG fifo;
- TZ_ULONG colls;
- TZ_ULONG carrier;
- TZ_ULONG compressed;
- _transmit():bytes(0), packets(0), errs(0), drop(0),
- fifo(0), colls(0), carrier(0), compressed(0) {};
- };
- public:
- std::string NicName;
- _receive Receive;
- _transmit Transmit;
- TZ_LONG BandWidth; /* 网口带宽 */
- TZ_LONG collectTime;
- };
- /* 系统信息 */
- struct SystemInfo {
- std::string Origin; /* 原始信息 */
- std::string KernelName; /* 内核名称 */
- std::string NodeName; /* 网络节点上的主机名*/
- std::string KernelRelease; /* 内核发行号 */
- std::string KernelVesion; /* 内核版本号 */
- std::string Machine; /* 主机架构名称 */
- std::string Processor; /* 处理器类型 */
- std::string HardwarePlatform; /* 硬件平台 */
- std::string OperatingSystem; /* 操作系统名称 */
- };
- /* CPU信息 */
- /* FIXME: !!不支持获取装有多个不同型号的CPU的机器的信息 */
- struct CPUInfo {
- std::string CPUName; /* CPU名称 */
- TZ_INT CPUPhysicalNum; /* 物理CPU个数 */
- TZ_INT CPUCoreNum; /* 单个物理CPU核心数 */
- TZ_INT CPULogicNum; /* 逻辑CPU个数 */
- CPUInfo() : CPUPhysicalNum(0), CPUCoreNum(0), CPULogicNum(0) {};
- /* 是否支持超线程技术 */
- TZ_BOOL IsHyperThreading()
- {
- return CPUPhysicalNum * CPUCoreNum == CPULogicNum ? FALSE : TRUE;
- }
- };
- /* netstat */
- struct NetstatInfo {
- std::string Proto;
- std::string RecvQ; /* 网络接收队列 */
- std::string SendQ; /* 网络发送队列 */
- std::string LocalAddress;
- std::string ForeignAddress;
- std::string State;
- std::string Pid_Pname;
- };
- /* df */
- struct DiskstatInfo {
- std::string Filesystem;
- TZ_ULONGLONG Blocks_1K; /* 1K-块 单位KiB */
- TZ_ULONGLONG Used; /* 1K-块 已使用 单位KiB */
- TZ_ULONGLONG Available; /* 1K-块 可利用 单位KiB */
- std::string UseRate; /* 使用率 */
- std::string MountedOn; /* 挂载于 */
- DiskstatInfo() : Blocks_1K(0), Used(0), Available(0) {};
- };
- /* 查询进程信息相关结构 */
- /* /proc/$(PID)/stat */
- struct ProcStatInfo {
- TZ_INT pid; // The process ID.
- std::string comm; // The filename of the executable, in parentheses. This is visible whether or not the executable is swapped out.
- TZ_CHAR state; // One of the following characters, indicating process state:
- TZ_INT ppid; // The PID of the parent of this process.
- TZ_INT pgrp; // The process group ID of the process.
- TZ_INT session; // The session ID of the process.
- TZ_INT tty_nr; // The controlling terminal of the process.
- TZ_INT tpgid; // The ID of the foreground process group of the controlling terminal of the process.
- TZ_UINT flags; // The kernel flags word of the process. For bit meanings, see the PF_* defines in the Linux kernel source file include/linux/sched.h. Details depend on the kernel version.
- TZ_ULONG minflt; // The number of minor faults the process has made which have not required loading a memory page from disk.
- TZ_ULONG cminflt; // The number of minor faults that the process's waited-for children have made.
- TZ_ULONG majflt; // The number of major faults the process has made which have required loading a memory page from disk.
- TZ_ULONG cmajflt; // The number of major faults that the process's waited-for children have made.
- TZ_ULONG utime; // Amount of time that this process has been scheduled in user mode, measured in clock ticks
- TZ_ULONG stime; // Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- TZ_LONG cutime; // Amount of time that this process's waited-for children have been scheduled in user mode, measured in clock ticks
- TZ_LONG cstime; // Amount of time that this process's waited-for children have been scheduled in kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- TZ_LONG priority; //
- TZ_LONG nice; // The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority).
- TZ_LONG num_threads; // Number of threads in this process (since Linux 2.6). Before kernel 2.6, this field was hard coded to 0 as a placeholder for an earlier removed field.
- /* 剩余字段参见 man proc 的/proc/[pid]/stat条目*/
- TZ_LONG collectTime;
- };
- /* /proc/$(PID)/status */
- struct ProcStatusInfo {
- TZ_ULONG Vmrss;
- TZ_ULONG ThreadNum; /* 线程数量 */
- ProcStatusInfo() : Vmrss(0), ThreadNum(0) {};
- };
- /* /proc/$(PID)/io */
- struct ProcDiskStatInfo {
- TZ_ULONGLONG rchar;
- TZ_ULONGLONG wchar;
- TZ_ULONGLONG syscr;
- TZ_ULONGLONG syscw;
- TZ_ULONGLONG read_bytes;
- TZ_ULONGLONG write_bytes;
- TZ_ULONGLONG cancelled_write_bytes;
- TZ_LONG collectTime;
- ProcDiskStatInfo() : rchar(0), wchar(0), syscr(0), syscw(0),
- read_bytes(0), write_bytes(0), cancelled_write_bytes(0), collectTime(0) {};
- };
- struct InterfaceInfo {
- InterfaceInfo() : Status(0) {}
- std::string Name; /* 网络接口名称 */
- std::string HwAddr; /* 硬件地址 */
- std::string InetAddr; /* ipv4地址 */
- std::string Inet6Addr; /* ipv6地址 */
- std::string Netmask; /* 子网掩码 */
- TZ_INT Status; /* 网卡开启状态: 0:down;1;up */
- };
- struct ProcNetBandInfo {
- TZ_INT pid;
- std::string device_name;
- TZ_ULONGLONG sent_bytes;
- TZ_ULONGLONG recv_bytes;
- TZ_DOUBLE sent_kbs;
- TZ_DOUBLE recv_kbs;
- TZ_LONG collectTime;
- ProcNetBandInfo() : pid(0), sent_bytes(0), recv_bytes(0),
- sent_kbs(0), recv_kbs(0), collectTime(0) {};
- };
- /* 进程运行时间信息 */
- struct ProcTimeInfo {
- TZ_LONG Pid; /* 进程PID */
- std::string StartTime; /* 进程启动时间 */
- std::string RunTime; /* 进程运行时长 */
- };
- NAMESPACE_MAS_END
- #endif
|