Solaris subagent: implemented System.Memory.Physical.* parameters
[public/netxms.git] / src / agent / subagents / sunos / main.cpp
CommitLineData
6082bd00
VK
1/*
2** NetXMS subagent for SunOS/Solaris
1b3c0ef0 3** Copyright (C) 2004, 2005 Victor Kirhenshtein
6082bd00
VK
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
7b1d9d90 30LONG H_CPUCount(char *pszParam, char *pArg, char *pValue);
518e4590 31LONG H_CPUUsage(char *pszParam, char *pArg, char *pValue);
6082bd00 32LONG H_DiskInfo(char *pszParam, char *pArg, char *pValue);
5e55b48b 33LONG H_Hostname(char *pszParam, char *pArg, char *pValue);
7b1d9d90 34LONG H_KStat(char *pszParam, char *pArg, char *pValue);
3babc9bf 35LONG H_LoadAvg(char *pszParam, char *pArg, char *pValue);
7a5229b4 36LONG H_MemoryInfo(char *pszParam, char *pArg, char *pValue);
d984863a 37LONG H_NetIfList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
4d1fde4c
VK
38LONG H_NetIfAdminStatus(char *pszParam, char *pArg, char *pValue);
39LONG H_NetIfDescription(char *pszParam, char *pArg, char *pValue);
40LONG H_NetInterfaceStats(char *pszParam, char *pArg, char *pValue);
d6a35a77 41LONG H_ProcessCount(char *pszParam, char *pArg, char *pValue);
b492a277 42LONG H_ProcessInfo(char *pszParam, char *pArg, char *pValue);
bce81ca5 43LONG H_ProcessList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
b492a277 44LONG H_SysProcCount(char *pszParam, char *pArg, char *pValue);
1b3c0ef0
VK
45LONG H_Uname(char *pszParam, char *pArg, char *pValue);
46LONG H_Uptime(char *pszParam, char *pArg, char *pValue);
6082bd00
VK
47
48
cf5fa1e2
VK
49//
50// Global variables
51//
52
53BOOL g_bShutdown = FALSE;
54
55
56//
57// Static data
58//
59
60static THREAD m_hCPUStatThread = INVALID_THREAD_HANDLE;
61
62
8ec03f6f
VK
63//
64// Detect support for source packages
65//
66
cf5fa1e2 67static LONG H_SourcePkg(char *pszParam, char *pArg, char *pValue)
8ec03f6f
VK
68{
69 ret_int(pValue, 1);
70 return SYSINFO_RC_SUCCESS;
71}
72
73
6082bd00
VK
74//
75// Called by master agent at unload
76//
77
78static void UnloadHandler(void)
79{
cf5fa1e2
VK
80 g_bShutdown = TRUE;
81 ThreadJoin(m_hCPUStatThread);
6082bd00
VK
82}
83
84
85//
86// Subagent information
87//
88
89static NETXMS_SUBAGENT_PARAM m_parameters[] =
90{
1b3c0ef0
VK
91 { "Agent.SourcePackageSupport", H_SourcePkg, NULL, DCI_DT_INT, "" },
92 { "Disk.Free(*)", H_DiskInfo, (char *)DISK_FREE, DCI_DT_UINT64, "Free disk space on *" },
93 { "Disk.Total(*)", H_DiskInfo, (char *)DISK_TOTAL, DCI_DT_UINT64, "Total disk space on *" },
94 { "Disk.Used(*)", H_DiskInfo, (char *)DISK_USED, DCI_DT_UINT64, "Used disk space on *" },
4d1fde4c
VK
95 { "Net.Interface.AdminStatus(*)", H_NetIfAdminStatus, NULL, DCI_DT_INT, "Administrative status of interface {instance}" },
96 { "Net.Interface.BytesIn(*)", H_NetInterfaceStats, "rbytes", DCI_DT_UINT, "Number of input bytes on interface {instance}" },
97 { "Net.Interface.BytesOut(*)", H_NetInterfaceStats, "obytes", DCI_DT_UINT, "Number of output bytes on interface {instance}" },
98 { "Net.Interface.Description(*)", H_NetIfDescription, NULL, DCI_DT_STRING, "" },
99 { "Net.Interface.InErrors(*)", H_NetInterfaceStats, "ierrors", DCI_DT_UINT, "Number of input errors on interface {instance}" },
100 { "Net.Interface.Link(*)", H_NetInterfaceStats, "link_up", DCI_DT_INT, "Link status for interface {instance}" },
101 { "Net.Interface.OutErrors(*)", H_NetInterfaceStats, "oerrors", DCI_DT_UINT, "Number of output errors on interface {instance}" },
102 { "Net.Interface.PacketsIn(*)", H_NetInterfaceStats, "ipackets", DCI_DT_UINT, "Number of input packets on interface {instance}" },
103 { "Net.Interface.PacketsOut(*)", H_NetInterfaceStats, "opackets", DCI_DT_UINT, "Number of output packets on interface {instance}" },
104 { "Net.Interface.Speed(*)", H_NetInterfaceStats, "ifspeed", DCI_DT_UINT, "Speed of interface {instance}" },
105 { "Process.Count(*)", H_ProcessCount, NULL, DCI_DT_UINT, "Number of proceses {instance}" },
1b3c0ef0
VK
106 { "Process.KernelTime(*)", H_ProcessInfo, (char *)PROCINFO_KTIME, DCI_DT_UINT64, "" },
107 { "Process.PageFaults(*)", H_ProcessInfo, (char *)PROCINFO_PF, DCI_DT_UINT64, "" },
108 { "Process.UserTime(*)", H_ProcessInfo, (char *)PROCINFO_UTIME, DCI_DT_UINT64, "" },
7b1d9d90 109 { "System.CPU.Count", H_CPUCount, NULL, DCI_DT_UINT, "Number of CPU in the system" },
3babc9bf
VK
110 { "System.CPU.LoadAvg", H_LoadAvg, (char *)0, DCI_DT_FLOAT, "Average CPU load for last minute" },
111 { "System.CPU.LoadAvg5", H_LoadAvg, (char *)1, DCI_DT_FLOAT, "Average CPU load for last 5 minutes" },
112 { "System.CPU.LoadAvg15", H_LoadAvg, (char *)2, DCI_DT_FLOAT, "Average CPU load for last 15 minutes" },
518e4590
VK
113 { "System.CPU.Usage", H_CPUUsage, "T0", DCI_DT_FLOAT, "Average CPU(s) utilization for last minute" },
114 { "System.CPU.Usage5", H_CPUUsage, "T1", DCI_DT_FLOAT, "Average CPU(s) utilization for last 5 minutes" },
115 { "System.CPU.Usage15", H_CPUUsage, "T2", DCI_DT_FLOAT, "Average CPU(s) utilization for last 15 minutes" },
116 { "System.CPU.Usage(*)", H_CPUUsage, "C0", DCI_DT_FLOAT, "Average CPU {instance} utilization for last minute" },
117 { "System.CPU.Usage5(*)", H_CPUUsage, "C1", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 5 minutes" },
118 { "System.CPU.Usage15(*)", H_CPUUsage, "C2", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 15 minutes" },
5e55b48b 119 { "System.Hostname", H_Hostname, NULL, DCI_DT_STRING, "Host name" },
7b1d9d90 120 { "System.KStat(*)", H_KStat, NULL, DCI_DT_STRING, "" },
7a5229b4
VK
121 { "System.Memory.Physical.Free", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, "Available physical memory" },
122 { "System.Memory.Physical.Total", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_TOTAL, DCI_DT_UINT64, "Total amount of physical memory" },
29b8518f 123 { "System.Memory.Physical.Used", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_USED, DCI_DT_UINT64, "Used physical memory" },
7a5229b4
VK
124 { "System.Memory.Swap.Free", H_MemoryInfo, (char *)MEMINFO_SWAP_FREE, DCI_DT_UINT64, "Free swap space" },
125 { "System.Memory.Swap.Total", H_MemoryInfo, (char *)MEMINFO_SWAP_TOTAL, DCI_DT_UINT64, "Total amount of swap space" },
126 { "System.Memory.Swap.Used", H_MemoryInfo, (char *)MEMINFO_SWAP_USED, DCI_DT_UINT64, "Used swap space" },
1b3c0ef0
VK
127 { "System.ProcessCount", H_SysProcCount, NULL, DCI_DT_INT, "Total number of processes" },
128 { "System.Uname", H_Uname, NULL, DCI_DT_STRING, "System uname" },
129 { "System.Uptime", H_Uptime, NULL, DCI_DT_UINT, "System uptime" }
6082bd00
VK
130};
131static NETXMS_SUBAGENT_ENUM m_enums[] =
132{
bce81ca5
VK
133 { "Net.InterfaceList", H_NetIfList, NULL },
134 { "System.ProcessList", H_ProcessList, NULL }
6082bd00
VK
135};
136
137static NETXMS_SUBAGENT_INFO m_info =
138{
139 NETXMS_SUBAGENT_INFO_MAGIC,
7c65fe96
VK
140 _T("SUNOS"), NETXMS_VERSION_STRING,
141 UnloadHandler, NULL,
6082bd00
VK
142 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
143 m_parameters,
144 sizeof(m_enums) / sizeof(NETXMS_SUBAGENT_ENUM),
145 m_enums
146};
147
148
149//
150// Entry point for NetXMS agent
151//
152
153extern "C" BOOL NxSubAgentInit(NETXMS_SUBAGENT_INFO **ppInfo, TCHAR *pszConfigFile)
154{
cf5fa1e2
VK
155 m_hCPUStatThread = ThreadCreateEx(CPUStatCollector, 0, NULL);
156
6082bd00
VK
157 *ppInfo = &m_info;
158 return TRUE;
159}