1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
** Zabbix
** Copyright (C) 2001-2014 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include "common.h"
#include "sysinfo.h"
#include "stats.h"
#define ZBX_MAX_WAIT_VMSTAT 2 /* maximum seconds to wait for vmstat data on the first call */
int SYSTEM_STAT(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *section, *type;
int wait = ZBX_MAX_WAIT_VMSTAT;
if (!VMSTAT_COLLECTOR_STARTED(collector))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Collector is not started."));
return SYSINFO_RET_FAIL;
}
/* if vmstat data is not available yet wait for collector to gather it */
if (0 == collector->vmstat.data_available)
{
collector->vmstat.enabled = 1;
while (wait--)
{
zbx_sleep(1);
if (1 == collector->vmstat.data_available)
break;
}
if (0 == collector->vmstat.data_available)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "No data available in collector."));
return SYSINFO_RET_FAIL;
}
}
if (2 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
}
section = get_rparam(request, 0);
type = get_rparam(request, 1);
if (NULL == section)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
}
if (0 == strcmp(section, "ent"))
{
if (1 != request->nparam && 0 != collector->vmstat.shared_enabled)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
return SYSINFO_RET_FAIL;
}
else if (0 == collector->vmstat.shared_enabled)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "No data available in collector."));
return SYSINFO_RET_FAIL;
}
else
SET_DBL_RESULT(result, collector->vmstat.ent);
}
else if (NULL == type)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
if (0 == strcmp(section, "kthr"))
{
if (0 == strcmp(type, "r"))
SET_DBL_RESULT(result, collector->vmstat.kthr_r);
else if (0 == strcmp(type, "b"))
SET_DBL_RESULT(result, collector->vmstat.kthr_b);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else if (0 == strcmp(section, "page"))
{
if (0 == strcmp(type, "fi"))
SET_DBL_RESULT(result, collector->vmstat.fi);
else if (0 == strcmp(type, "fo"))
SET_DBL_RESULT(result, collector->vmstat.fo);
else if (0 == strcmp(type, "pi"))
SET_DBL_RESULT(result, collector->vmstat.pi);
else if (0 == strcmp(type, "po"))
SET_DBL_RESULT(result, collector->vmstat.po);
else if (0 == strcmp(type, "fr"))
SET_DBL_RESULT(result, collector->vmstat.fr);
else if (0 == strcmp(type, "sr"))
SET_DBL_RESULT(result, collector->vmstat.sr);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else if (0 == strcmp(section, "faults"))
{
if (0 == strcmp(type, "in"))
SET_DBL_RESULT(result, collector->vmstat.in);
else if (0 == strcmp(type, "sy"))
SET_DBL_RESULT(result, collector->vmstat.sy);
else if (0 == strcmp(type, "cs"))
SET_DBL_RESULT(result, collector->vmstat.cs);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else if (0 == strcmp(section, "cpu"))
{
if (0 == strcmp(type, "us"))
SET_DBL_RESULT(result, collector->vmstat.cpu_us);
else if (0 == strcmp(type, "sy"))
SET_DBL_RESULT(result, collector->vmstat.cpu_sy);
else if (0 == strcmp(type, "id"))
SET_DBL_RESULT(result, collector->vmstat.cpu_id);
else if (0 == strcmp(type, "wa"))
SET_DBL_RESULT(result, collector->vmstat.cpu_wa);
else if (0 == strcmp(type, "pc") && collector->vmstat.shared_enabled)
SET_DBL_RESULT(result, collector->vmstat.cpu_pc);
else if (0 == strcmp(type, "ec") && collector->vmstat.shared_enabled)
SET_DBL_RESULT(result, collector->vmstat.cpu_ec);
else if (0 == strcmp(type, "lbusy") && collector->vmstat.shared_enabled)
SET_DBL_RESULT(result, collector->vmstat.cpu_lbusy);
else if (0 == strcmp(type, "app") && collector->vmstat.shared_enabled && collector->vmstat.pool_util_authority)
SET_DBL_RESULT(result, collector->vmstat.cpu_app);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else if (0 == strcmp(section, "disk"))
{
if (0 == strcmp(type, "bps"))
SET_UI64_RESULT(result, collector->vmstat.disk_bps);
else if (0 == strcmp(type, "tps"))
SET_DBL_RESULT(result, collector->vmstat.disk_tps);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else if (0 == strcmp(section, "memory"))
{
if (0 == strcmp(type, "avm") && collector->vmstat.aix52stats)
SET_UI64_RESULT(result, collector->vmstat.mem_avm);
else if (0 == strcmp(type, "fre"))
SET_UI64_RESULT(result, collector->vmstat.mem_fre);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
}
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
return SYSINFO_RET_FAIL;
}
return SYSINFO_RET_OK;
}
|