All parameters System.CPU.Usage implemented
[public/netxms.git] / src / agent / subagents / sunos / main.cpp
1 /*
2 ** NetXMS subagent for SunOS/Solaris
3 ** Copyright (C) 2004, 2005 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** $module: main.cpp
20 **
21 **/
22
23 #include "sunos_subagent.h"
24
25
26 //
27 // Hanlder functions
28 //
29
30 LONG H_CPUCount(char *pszParam, char *pArg, char *pValue);
31 LONG H_CPUUsage(char *pszParam, char *pArg, char *pValue);
32 LONG H_DiskInfo(char *pszParam, char *pArg, char *pValue);
33 LONG H_Hostname(char *pszParam, char *pArg, char *pValue);
34 LONG H_KStat(char *pszParam, char *pArg, char *pValue);
35 LONG H_LoadAvg(char *pszParam, char *pArg, char *pValue);
36 LONG H_NetIfList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
37 LONG H_NetIfAdminStatus(char *pszParam, char *pArg, char *pValue);
38 LONG H_NetIfDescription(char *pszParam, char *pArg, char *pValue);
39 LONG H_NetInterfaceStats(char *pszParam, char *pArg, char *pValue);
40 LONG H_ProcessCount(char *pszParam, char *pArg, char *pValue);
41 LONG H_ProcessInfo(char *pszParam, char *pArg, char *pValue);
42 LONG H_ProcessList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
43 LONG H_SysProcCount(char *pszParam, char *pArg, char *pValue);
44 LONG H_Uname(char *pszParam, char *pArg, char *pValue);
45 LONG H_Uptime(char *pszParam, char *pArg, char *pValue);
46
47
48 //
49 // Global variables
50 //
51
52 BOOL g_bShutdown = FALSE;
53
54
55 //
56 // Static data
57 //
58
59 static THREAD m_hCPUStatThread = INVALID_THREAD_HANDLE;
60
61
62 //
63 // Detect support for source packages
64 //
65
66 static LONG H_SourcePkg(char *pszParam, char *pArg, char *pValue)
67 {
68 ret_int(pValue, 1);
69 return SYSINFO_RC_SUCCESS;
70 }
71
72
73 //
74 // Called by master agent at unload
75 //
76
77 static void UnloadHandler(void)
78 {
79 g_bShutdown = TRUE;
80 ThreadJoin(m_hCPUStatThread);
81 }
82
83
84 //
85 // Subagent information
86 //
87
88 static NETXMS_SUBAGENT_PARAM m_parameters[] =
89 {
90 { "Agent.SourcePackageSupport", H_SourcePkg, NULL, DCI_DT_INT, "" },
91 { "Disk.Free(*)", H_DiskInfo, (char *)DISK_FREE, DCI_DT_UINT64, "Free disk space on *" },
92 { "Disk.Total(*)", H_DiskInfo, (char *)DISK_TOTAL, DCI_DT_UINT64, "Total disk space on *" },
93 { "Disk.Used(*)", H_DiskInfo, (char *)DISK_USED, DCI_DT_UINT64, "Used disk space on *" },
94 { "Net.Interface.AdminStatus(*)", H_NetIfAdminStatus, NULL, DCI_DT_INT, "Administrative status of interface {instance}" },
95 { "Net.Interface.BytesIn(*)", H_NetInterfaceStats, "rbytes", DCI_DT_UINT, "Number of input bytes on interface {instance}" },
96 { "Net.Interface.BytesOut(*)", H_NetInterfaceStats, "obytes", DCI_DT_UINT, "Number of output bytes on interface {instance}" },
97 { "Net.Interface.Description(*)", H_NetIfDescription, NULL, DCI_DT_STRING, "" },
98 { "Net.Interface.InErrors(*)", H_NetInterfaceStats, "ierrors", DCI_DT_UINT, "Number of input errors on interface {instance}" },
99 { "Net.Interface.Link(*)", H_NetInterfaceStats, "link_up", DCI_DT_INT, "Link status for interface {instance}" },
100 { "Net.Interface.OutErrors(*)", H_NetInterfaceStats, "oerrors", DCI_DT_UINT, "Number of output errors on interface {instance}" },
101 { "Net.Interface.PacketsIn(*)", H_NetInterfaceStats, "ipackets", DCI_DT_UINT, "Number of input packets on interface {instance}" },
102 { "Net.Interface.PacketsOut(*)", H_NetInterfaceStats, "opackets", DCI_DT_UINT, "Number of output packets on interface {instance}" },
103 { "Net.Interface.Speed(*)", H_NetInterfaceStats, "ifspeed", DCI_DT_UINT, "Speed of interface {instance}" },
104 { "Process.Count(*)", H_ProcessCount, NULL, DCI_DT_UINT, "Number of proceses {instance}" },
105 { "Process.KernelTime(*)", H_ProcessInfo, (char *)PROCINFO_KTIME, DCI_DT_UINT64, "" },
106 { "Process.PageFaults(*)", H_ProcessInfo, (char *)PROCINFO_PF, DCI_DT_UINT64, "" },
107 { "Process.UserTime(*)", H_ProcessInfo, (char *)PROCINFO_UTIME, DCI_DT_UINT64, "" },
108 { "System.CPU.Count", H_CPUCount, NULL, DCI_DT_UINT, "Number of CPU in the system" },
109 { "System.CPU.LoadAvg", H_LoadAvg, (char *)0, DCI_DT_FLOAT, "Average CPU load for last minute" },
110 { "System.CPU.LoadAvg5", H_LoadAvg, (char *)1, DCI_DT_FLOAT, "Average CPU load for last 5 minutes" },
111 { "System.CPU.LoadAvg15", H_LoadAvg, (char *)2, DCI_DT_FLOAT, "Average CPU load for last 15 minutes" },
112 { "System.CPU.Usage", H_CPUUsage, "T0", DCI_DT_FLOAT, "Average CPU(s) utilization for last minute" },
113 { "System.CPU.Usage5", H_CPUUsage, "T1", DCI_DT_FLOAT, "Average CPU(s) utilization for last 5 minutes" },
114 { "System.CPU.Usage15", H_CPUUsage, "T2", DCI_DT_FLOAT, "Average CPU(s) utilization for last 15 minutes" },
115 { "System.CPU.Usage(*)", H_CPUUsage, "C0", DCI_DT_FLOAT, "Average CPU {instance} utilization for last minute" },
116 { "System.CPU.Usage5(*)", H_CPUUsage, "C1", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 5 minutes" },
117 { "System.CPU.Usage15(*)", H_CPUUsage, "C2", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 15 minutes" },
118 { "System.Hostname", H_Hostname, NULL, DCI_DT_STRING, "Host name" },
119 { "System.KStat(*)", H_KStat, NULL, DCI_DT_STRING, "" },
120 { "System.ProcessCount", H_SysProcCount, NULL, DCI_DT_INT, "Total number of processes" },
121 { "System.Uname", H_Uname, NULL, DCI_DT_STRING, "System uname" },
122 { "System.Uptime", H_Uptime, NULL, DCI_DT_UINT, "System uptime" }
123 };
124 static NETXMS_SUBAGENT_ENUM m_enums[] =
125 {
126 { "Net.InterfaceList", H_NetIfList, NULL },
127 { "System.ProcessList", H_ProcessList, NULL }
128 };
129
130 static NETXMS_SUBAGENT_INFO m_info =
131 {
132 NETXMS_SUBAGENT_INFO_MAGIC,
133 _T("SUNOS"), NETXMS_VERSION_STRING,
134 UnloadHandler, NULL,
135 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
136 m_parameters,
137 sizeof(m_enums) / sizeof(NETXMS_SUBAGENT_ENUM),
138 m_enums
139 };
140
141
142 //
143 // Entry point for NetXMS agent
144 //
145
146 extern "C" BOOL NxSubAgentInit(NETXMS_SUBAGENT_INFO **ppInfo, TCHAR *pszConfigFile)
147 {
148 m_hCPUStatThread = ThreadCreateEx(CPUStatCollector, 0, NULL);
149
150 *ppInfo = &m_info;
151 return TRUE;
152 }