XEN subagent: added domain state parameters
[public/netxms.git] / src / agent / subagents / xen / xen.cpp
CommitLineData
1647762a
VK
1/*
2** NetXMS XEN hypervisor subagent
3** Copyright (C) 2017 Raden Solutions
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** File: xen.cpp
20**
21**/
22
23#include "xen.h"
24
25/**
26 * Handlers
27 */
38270c40 28LONG H_XenDomainCPUUsage(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
1647762a 29LONG H_XenDomainList(const TCHAR *param, const TCHAR *arg, StringList *value, AbstractCommSession *session);
024506fc 30LONG H_XenDomainNetIfTable(const TCHAR *param, const TCHAR *arg, Table *value, AbstractCommSession *session);
41668ccd 31LONG H_XenDomainNetStats(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
9d249009 32LONG H_XenDomainState(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
1647762a 33LONG H_XenDomainTable(const TCHAR *param, const TCHAR *arg, Table *value, AbstractCommSession *session);
38270c40 34LONG H_XenHostCPUUsage(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
eb29b7f5
VK
35LONG H_XenHostOnlineCPUs(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
36LONG H_XenHostPhyInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
1647762a
VK
37LONG H_XenHostVersion(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
38
39/**
40 * Convert XEN log level into NetXMS debug level
41 */
42inline int ConvertLogLevel(xentoollog_level level)
43{
44 if (level >= XTL_ERROR)
45 return 1;
46 if (level >= XTL_WARN)
47 return 3;
48 if (level >= XTL_NOTICE)
49 return 4;
50 return 5;
51}
52
53/**
54 * Write log message
55 */
56static void LogMessage(struct xentoollog_logger *logger,
57 xentoollog_level level,
58 int errnoval /* or -1 */,
59 const char *context /* eg "xc", "xl", may be 0 */,
60 const char *format /* without level, context, \n */,
61 va_list al)
62{
63 char msg[4096];
64 vsnprintf(msg, 4096, format, al);
65 nxlog_debug(ConvertLogLevel(level), _T("XEN: [%hs] (%hs): %hs"), xtl_level_to_string(level), context, msg);
66}
67
68/**
69 * Write progress message
70 */
71static void LogProgress(struct xentoollog_logger *logger,
72 const char *context /* see above */,
73 const char *doing_what /* no \r,\n */,
74 int percent, unsigned long done, unsigned long total)
75{
76}
77
78/**
79 * Destroy logger
80 */
81static void LogDestroy(struct xentoollog_logger *logger)
82{
83}
84
85/**
86 * Logger definition
87 */
88xentoollog_logger g_xenLogger = { LogMessage, LogProgress, LogDestroy };
89
90/**
91 * Called by master agent at unload
92 */
93static void SubagentShutdown()
94{
360492cb 95 XenStopCPUCollector();
1647762a
VK
96}
97
98/**
99 * Subagent initialization
100 */
101static BOOL SubagentInit(Config *config)
102{
360492cb 103 XenStartCPUCollector();
1647762a
VK
104 return TRUE;
105}
106
107/**
108 * Parameters
109 */
110static NETXMS_SUBAGENT_PARAM s_parameters[] =
111{
38270c40
VK
112 { _T("XEN.Domain.CPU.CurrentUsage(*)"), H_XenDomainCPUUsage, _T("0"), DCI_DT_FLOAT, _T("XEN domain {instance}: current CPU utilization") },
113 { _T("XEN.Domain.CPU.Usage(*)"), H_XenDomainCPUUsage, _T("1"), DCI_DT_FLOAT, _T("XEN domain {instance}: average CPU utilization for last minute") },
114 { _T("XEN.Domain.CPU.Usage15(*)"), H_XenDomainCPUUsage, _T("F"), DCI_DT_FLOAT, _T("XEN domain {instance}: average CPU utilization for last 15 minutes") },
115 { _T("XEN.Domain.CPU.Usage5(*)"), H_XenDomainCPUUsage, _T("5"), DCI_DT_FLOAT, _T("XEN domain {instance}: average CPU utilization for last 5 minutes") },
9d249009
VK
116 { _T("XEN.Domain.IsExist(*)"), H_XenDomainState, _T("E"), DCI_DT_INT, _T("XEN domain {instance}: existence flag") },
117 { _T("XEN.Domain.IsOperational(*)"), H_XenDomainState, _T("O"), DCI_DT_INT, _T("XEN domain {instance}: operational flag") },
118 { _T("XEN.Domain.IsPaused(*)"), H_XenDomainState, _T("P"), DCI_DT_INT, _T("XEN domain {instance}: paused flag") },
41668ccd
VK
119 { _T("XEN.Domain.Net.RxBytes(*)"), H_XenDomainNetStats, _T("RB"), DCI_DT_UINT64, _T("XEN domain {instance}: network usage (bytes received)") },
120 { _T("XEN.Domain.Net.RxPackets(*)"), H_XenDomainNetStats, _T("RP"), DCI_DT_UINT64, _T("XEN domain {instance}: network usage (packets received)") },
121 { _T("XEN.Domain.Net.TxBytes(*)"), H_XenDomainNetStats, _T("TB"), DCI_DT_UINT64, _T("XEN domain {instance}: network usage (bytes transmitted)") },
122 { _T("XEN.Domain.Net.TxPackets(*)"), H_XenDomainNetStats, _T("TP"), DCI_DT_UINT64, _T("XEN domain {instance}: network usage (packets transmitted)") },
9d249009 123 { _T("XEN.Domain.State(*)"), H_XenDomainState, _T("?"), DCI_DT_INT, _T("XEN domain {instance}: state") },
eb29b7f5 124 { _T("XEN.Host.CPU.Cores"), H_XenHostPhyInfo, _T("c"), DCI_DT_INT, _T("XEN host: number of CPU cores") },
38270c40 125 { _T("XEN.Host.CPU.CurrentUsage"), H_XenHostCPUUsage, _T("0"), DCI_DT_FLOAT, _T("XEN host: current CPU utilization") },
eb29b7f5
VK
126 { _T("XEN.Host.CPU.Frequency"), H_XenHostPhyInfo, _T("F"), DCI_DT_INT, _T("XEN host: number of CPU cores") },
127 { _T("XEN.Host.CPU.LogicalCount"), H_XenHostPhyInfo, _T("C"), DCI_DT_INT, _T("XEN host: number of logical CPUs") },
128 { _T("XEN.Host.CPU.Online"), H_XenHostOnlineCPUs, NULL, DCI_DT_INT, _T("XEN host: number of online CPUs") },
129 { _T("XEN.Host.CPU.PhysicalCount"), H_XenHostPhyInfo, _T("P"), DCI_DT_INT, _T("XEN host: number of physical CPUs") },
38270c40
VK
130 { _T("XEN.Host.CPU.Usage"), H_XenHostCPUUsage, _T("1"), DCI_DT_FLOAT, _T("XEN host: average CPU utilization for last minute") },
131 { _T("XEN.Host.CPU.Usage15"), H_XenHostCPUUsage, _T("F"), DCI_DT_FLOAT, _T("XEN host: average CPU utilization for last 15 minutes") },
132 { _T("XEN.Host.CPU.Usage5"), H_XenHostCPUUsage, _T("5"), DCI_DT_FLOAT, _T("XEN host: average CPU utilization for last 5 minutes") },
eb29b7f5
VK
133 { _T("XEN.Host.Memory.Free"), H_XenHostPhyInfo, _T("M"), DCI_DT_UINT64, _T("XEN host: free memory") },
134 { _T("XEN.Host.Memory.FreePerc"), H_XenHostPhyInfo, _T("m"), DCI_DT_FLOAT, _T("XEN host: free memory (%)") },
135 { _T("XEN.Host.Memory.Outstanding"), H_XenHostPhyInfo, _T("O"), DCI_DT_UINT64, _T("XEN host: outstanding memory") },
136 { _T("XEN.Host.Memory.OutstandingPerc"), H_XenHostPhyInfo, _T("o"), DCI_DT_FLOAT, _T("XEN host: outstanding memory (%)") },
137 { _T("XEN.Host.Memory.Scrub"), H_XenHostPhyInfo, _T("S"), DCI_DT_UINT64, _T("XEN host: scrub memory") },
138 { _T("XEN.Host.Memory.ScrubPerc"), H_XenHostPhyInfo, _T("s"), DCI_DT_FLOAT, _T("XEN host: scrub memory (%)") },
139 { _T("XEN.Host.Memory.Total"), H_XenHostPhyInfo, _T("T"), DCI_DT_UINT64, _T("XEN host: total memory") },
140 { _T("XEN.Host.Memory.Used"), H_XenHostPhyInfo, _T("U"), DCI_DT_UINT64, _T("XEN host: used memory") },
141 { _T("XEN.Host.Memory.UsedPerc"), H_XenHostPhyInfo, _T("u"), DCI_DT_FLOAT, _T("XEN host: used memory (%)") },
1647762a
VK
142 { _T("XEN.Host.Version"), H_XenHostVersion, NULL, DCI_DT_STRING, _T("XEN host: version") }
143};
144
145/**
146 * Lists
147 */
148static NETXMS_SUBAGENT_LIST s_lists[] =
149{
38270c40 150 { _T("XEN.Domains"), H_XenDomainList, NULL }
1647762a
VK
151};
152
153/**
154 * Tables
155 */
156static NETXMS_SUBAGENT_TABLE s_tables[] =
157{
024506fc
VK
158 { _T("XEN.Domains"), H_XenDomainTable, NULL, _T("ID"), _T("XEN: domains (virtual machines)") },
159 { _T("XEN.Net.DomainInterfaces"), H_XenDomainNetIfTable, NULL, _T("NAME"), _T("XEN: domain network interfaces") }
1647762a
VK
160};
161
162/**
163 * Subagent information
164 */
165static NETXMS_SUBAGENT_INFO m_info =
166{
167 NETXMS_SUBAGENT_INFO_MAGIC,
38270c40 168 _T("XEN"), NETXMS_VERSION_STRING,
1647762a
VK
169 SubagentInit, SubagentShutdown, NULL,
170 sizeof(s_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
171 s_parameters,
172 sizeof(s_lists) / sizeof(NETXMS_SUBAGENT_LIST),
173 s_lists,
174 sizeof(s_tables) / sizeof(NETXMS_SUBAGENT_TABLE),
175 s_tables, // tables
176 0, NULL, // actions
177 0, NULL // push parameters
178};
179
180/**
181 * Entry point for NetXMS agent
182 */
183DECLARE_SUBAGENT_ENTRY_POINT(XEN)
184{
185 *ppInfo = &m_info;
186 return TRUE;
187}
188
189#ifdef _WIN32
190
191/**
192 * DLL entry point
193 */
194BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
195{
196 if (dwReason == DLL_PROCESS_ATTACH)
197 DisableThreadLibraryCalls(hInstance);
198 return TRUE;
199}
200
201#endif