DataAcInnerStruct.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* from CIMS-Project */
  2. /* 数据采集模块内部结构 */
  3. /* 扩充请参考man proc */
  4. #ifndef __DATAAC_INNER_STRUCT_H
  5. #define __DATAAC_INNER_STRUCT_H
  6. /* common */
  7. #include "Types.h"
  8. /* perforence monitor */
  9. #include "MAS_Definition.h"
  10. NAMESPACE_MAS_BEGIN
  11. #define TZ_SYS_CLOCK sysconf(2)
  12. /* 查询系统信息相关结构 */
  13. /* !!结构内只定义需要的数据项 */
  14. /* /proc/stat */
  15. struct SysStatInfo {
  16. TZ_LONG user; /* 用户态的CPU时间(单位:jiffies),不包含低优先级用户模式 */
  17. TZ_LONG nice; /* 低优先级用户模式占用的CPU时间(单位:jiffies)*/
  18. TZ_LONG system; /* 系统核心态的CPU时间(单位:jiffies)*/
  19. TZ_LONG idle; /* 空闲状态下的CPU时间(单位:jiffies)*/
  20. TZ_LONG iowait; /* 硬盘IO等待占用的CPU时间(单位:jiffies)*/
  21. TZ_LONG irq; /* 硬中断占用的CPU时间(单位:jiffies) */
  22. TZ_LONG softirq; /* 软中断占用的CPU时间(单位:jiffies) */
  23. /* 返回总的cpu时间 */
  24. TZ_LONG GetCPUTime()
  25. {
  26. return user + nice + system + idle + iowait + irq + softirq;
  27. }
  28. SysStatInfo():user(0), nice(0), system(0),
  29. idle(0), iowait(0), irq(0), softirq(0) {};
  30. };
  31. /* /proc/meminfo */
  32. struct SysMemInfo {
  33. TZ_ULONG MemTotal; /* 所有可用的RAM大小 */
  34. TZ_ULONG MemAvailable; /* 系统实际可用内存,Linux 3.10后必含有参数 */
  35. SysMemInfo():MemTotal(0), MemAvailable(0) {};
  36. TZ_DOUBLE GetMemRate()
  37. {
  38. return TZ_DOUBLE(MemTotal - MemAvailable) / TZ_DOUBLE(MemTotal) * 100;
  39. }
  40. };
  41. /* /proc/diskstats */
  42. struct SysDiskStatInfo {
  43. TZ_LONG MainDevIndex; /* 主设备号 */
  44. TZ_LONG SubDevIndex; /* 次设备号 */
  45. std::string DevName; /* 设备名称 */
  46. TZ_LONG ReadFinishCount; /* 读完成次数。成功完成读磁盘的总次数 */
  47. TZ_LONG MergeReadFinishedCount; /* 合并读完成次数。为了效率可能会合并相邻的读和写 */
  48. TZ_LONG ReadSectionCount; /* 读扇区的总数 */
  49. TZ_LONG ReadMilinSeconds; /* 读花费的毫秒数,这是所有读操作所花费的毫秒数 */
  50. TZ_LONG WriteFinishedCount; /* 写完成次数。对应第1个域的读次数 */
  51. TZ_LONG MergeWriteFinishedCount; /* 合并写完成次数。对应第2个域的合并读次数 */
  52. TZ_LONG WriteSectionCount; /* 写扇区的总数。对应第3个域的读扇区总数 */
  53. TZ_LONG WriteMilinSeconds; /* 写操作花费的毫秒数。对应第4个域的读操作 */
  54. TZ_LONG ProcingIO; /* 正在处理的输入/输出请求数 */
  55. TZ_LONG IOMilinSeconds; /* 输入/输出操作花费的毫秒数 */
  56. TZ_LONG IOMilinSecondsAvg; /* 输入/输出操作花费的加权毫秒数 */
  57. TZ_LONG collectTime;
  58. SysDiskStatInfo():MainDevIndex(0), SubDevIndex(0), ReadFinishCount(0),
  59. MergeReadFinishedCount(0), ReadSectionCount(0), ReadMilinSeconds(0),
  60. WriteFinishedCount(0), MergeWriteFinishedCount(0), WriteSectionCount(0),
  61. WriteMilinSeconds(0), ProcingIO(0), IOMilinSeconds(0), IOMilinSecondsAvg(0),
  62. collectTime(0) {};
  63. };
  64. /* /proc/net/dev */
  65. struct SysNetBandInfo {
  66. private:
  67. struct _receive {
  68. TZ_ULONG bytes;
  69. TZ_ULONG packets;
  70. TZ_ULONG errs;
  71. TZ_ULONG drop;
  72. TZ_ULONG fifo;
  73. TZ_ULONG frame;
  74. TZ_ULONG compressed;
  75. TZ_ULONG multicast;
  76. _receive():bytes(0), packets(0), errs(0), drop(0),
  77. fifo(0), frame(0), compressed(0), multicast(0) {};
  78. };
  79. struct _transmit {
  80. TZ_ULONG bytes;
  81. TZ_ULONG packets;
  82. TZ_ULONG errs;
  83. TZ_ULONG drop;
  84. TZ_ULONG fifo;
  85. TZ_ULONG colls;
  86. TZ_ULONG carrier;
  87. TZ_ULONG compressed;
  88. _transmit():bytes(0), packets(0), errs(0), drop(0),
  89. fifo(0), colls(0), carrier(0), compressed(0) {};
  90. };
  91. public:
  92. std::string NicName;
  93. _receive Receive;
  94. _transmit Transmit;
  95. TZ_LONG BandWidth; /* 网口带宽 */
  96. TZ_LONG collectTime;
  97. };
  98. /* 系统信息 */
  99. struct SystemInfo {
  100. std::string Origin; /* 原始信息 */
  101. std::string KernelName; /* 内核名称 */
  102. std::string NodeName; /* 网络节点上的主机名*/
  103. std::string KernelRelease; /* 内核发行号 */
  104. std::string KernelVesion; /* 内核版本号 */
  105. std::string Machine; /* 主机架构名称 */
  106. std::string Processor; /* 处理器类型 */
  107. std::string HardwarePlatform; /* 硬件平台 */
  108. std::string OperatingSystem; /* 操作系统名称 */
  109. };
  110. /* CPU信息 */
  111. /* FIXME: !!不支持获取装有多个不同型号的CPU的机器的信息 */
  112. struct CPUInfo {
  113. std::string CPUName; /* CPU名称 */
  114. TZ_INT CPUPhysicalNum; /* 物理CPU个数 */
  115. TZ_INT CPUCoreNum; /* 单个物理CPU核心数 */
  116. TZ_INT CPULogicNum; /* 逻辑CPU个数 */
  117. CPUInfo() : CPUPhysicalNum(0), CPUCoreNum(0), CPULogicNum(0) {};
  118. /* 是否支持超线程技术 */
  119. TZ_BOOL IsHyperThreading()
  120. {
  121. return CPUPhysicalNum * CPUCoreNum == CPULogicNum ? FALSE : TRUE;
  122. }
  123. };
  124. /* netstat */
  125. struct NetstatInfo {
  126. std::string Proto;
  127. std::string RecvQ; /* 网络接收队列 */
  128. std::string SendQ; /* 网络发送队列 */
  129. std::string LocalAddress;
  130. std::string ForeignAddress;
  131. std::string State;
  132. std::string Pid_Pname;
  133. };
  134. /* df */
  135. struct DiskstatInfo {
  136. std::string Filesystem;
  137. TZ_ULONGLONG Blocks_1K; /* 1K-块 单位KiB */
  138. TZ_ULONGLONG Used; /* 1K-块 已使用 单位KiB */
  139. TZ_ULONGLONG Available; /* 1K-块 可利用 单位KiB */
  140. std::string UseRate; /* 使用率 */
  141. std::string MountedOn; /* 挂载于 */
  142. DiskstatInfo() : Blocks_1K(0), Used(0), Available(0) {};
  143. };
  144. /* 查询进程信息相关结构 */
  145. /* /proc/$(PID)/stat */
  146. struct ProcStatInfo {
  147. TZ_INT pid; // The process ID.
  148. std::string comm; // The filename of the executable, in parentheses. This is visible whether or not the executable is swapped out.
  149. TZ_CHAR state; // One of the following characters, indicating process state:
  150. TZ_INT ppid; // The PID of the parent of this process.
  151. TZ_INT pgrp; // The process group ID of the process.
  152. TZ_INT session; // The session ID of the process.
  153. TZ_INT tty_nr; // The controlling terminal of the process.
  154. TZ_INT tpgid; // The ID of the foreground process group of the controlling terminal of the process.
  155. 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.
  156. TZ_ULONG minflt; // The number of minor faults the process has made which have not required loading a memory page from disk.
  157. TZ_ULONG cminflt; // The number of minor faults that the process's waited-for children have made.
  158. TZ_ULONG majflt; // The number of major faults the process has made which have required loading a memory page from disk.
  159. TZ_ULONG cmajflt; // The number of major faults that the process's waited-for children have made.
  160. TZ_ULONG utime; // Amount of time that this process has been scheduled in user mode, measured in clock ticks
  161. 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)).
  162. TZ_LONG cutime; // Amount of time that this process's waited-for children have been scheduled in user mode, measured in clock ticks
  163. 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)).
  164. TZ_LONG priority; //
  165. TZ_LONG nice; // The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority).
  166. 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.
  167. /* 剩余字段参见 man proc 的/proc/[pid]/stat条目*/
  168. TZ_LONG collectTime;
  169. };
  170. /* /proc/$(PID)/status */
  171. struct ProcStatusInfo {
  172. TZ_ULONG Vmrss;
  173. TZ_ULONG ThreadNum; /* 线程数量 */
  174. ProcStatusInfo() : Vmrss(0), ThreadNum(0) {};
  175. };
  176. /* /proc/$(PID)/io */
  177. struct ProcDiskStatInfo {
  178. TZ_ULONGLONG rchar;
  179. TZ_ULONGLONG wchar;
  180. TZ_ULONGLONG syscr;
  181. TZ_ULONGLONG syscw;
  182. TZ_ULONGLONG read_bytes;
  183. TZ_ULONGLONG write_bytes;
  184. TZ_ULONGLONG cancelled_write_bytes;
  185. TZ_LONG collectTime;
  186. ProcDiskStatInfo() : rchar(0), wchar(0), syscr(0), syscw(0),
  187. read_bytes(0), write_bytes(0), cancelled_write_bytes(0), collectTime(0) {};
  188. };
  189. struct InterfaceInfo {
  190. InterfaceInfo() : Status(0) {}
  191. std::string Name; /* 网络接口名称 */
  192. std::string HwAddr; /* 硬件地址 */
  193. std::string InetAddr; /* ipv4地址 */
  194. std::string Inet6Addr; /* ipv6地址 */
  195. std::string Netmask; /* 子网掩码 */
  196. TZ_INT Status; /* 网卡开启状态: 0:down;1;up */
  197. };
  198. struct ProcNetBandInfo {
  199. TZ_INT pid;
  200. std::string device_name;
  201. TZ_ULONGLONG sent_bytes;
  202. TZ_ULONGLONG recv_bytes;
  203. TZ_DOUBLE sent_kbs;
  204. TZ_DOUBLE recv_kbs;
  205. TZ_LONG collectTime;
  206. ProcNetBandInfo() : pid(0), sent_bytes(0), recv_bytes(0),
  207. sent_kbs(0), recv_kbs(0), collectTime(0) {};
  208. };
  209. /* 进程运行时间信息 */
  210. struct ProcTimeInfo {
  211. TZ_LONG Pid; /* 进程PID */
  212. std::string StartTime; /* 进程启动时间 */
  213. std::string RunTime; /* 进程运行时长 */
  214. };
  215. NAMESPACE_MAS_END
  216. #endif