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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*
** ZABBIX
** Copyright (C) 2000-2005 SIA Zabbix
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "config.h"
#include "common.h"
#include "sysinfo.h"
#include "md5.h"
static int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
#else
struct statfs s;
#endif
assert(fs);
#ifdef HAVE_SYS_STATVFS_H
if ( statvfs( fs, &s) != 0 )
#else
if ( statfs( fs, &s) != 0 )
#endif
{
return SYSINFO_RET_FAIL;
}
if(total)
(*total) = (double)(s.f_files);
#ifdef HAVE_SYS_STATVFS_H
if(free)
(*free) = (double)(s.f_favail);
if(usage)
(*usage) = (double)(s.f_files - s.f_favail);
#else
if(free)
(*free) = (double)(s.ffree);
if(usage)
(*usage) = (double)(s.f_files - s.f_ffree);
#endif
return SYSINFO_RET_OK;
}
static int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
double value = 0;
assert(result);
clean_result(result);
if(num_param(param) > 1)
return SYSINFO_RET_FAIL;
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
return SYSINFO_RET_FAIL;
if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
result->dbl = value;
return SYSINFO_RET_OK;
}
static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
double value = 0;
assert(result);
clean_result(result);
if(num_param(param) > 1)
return SYSINFO_RET_FAIL;
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
return SYSINFO_RET_FAIL;
if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
result->dbl = value;
return SYSINFO_RET_OK;
}
static int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
double value = 0;
assert(result);
clean_result(result);
if(num_param(param) > 1)
return SYSINFO_RET_FAIL;
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
result->dbl = value;
return SYSINFO_RET_OK;
}
static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
double tot_val = 0;
double free_val = 0;
assert(result);
clean_result(result);
if(num_param(param) > 1)
return SYSINFO_RET_FAIL;
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
return SYSINFO_RET_FAIL;
if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
result->dbl = (100.0 * free_val) / tot_val;
return SYSINFO_RET_OK;
}
static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
double tot_val = 0;
double usg_val = 0;
assert(result);
clean_result(result);
if(num_param(param) > 1)
return SYSINFO_RET_FAIL;
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
return SYSINFO_RET_FAIL;
if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
result->dbl = (100.0 * usg_val) / tot_val;
return SYSINFO_RET_OK;
}
int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#define FS_FNCLIST struct fs_fnclist_s
FS_FNCLIST
{
char *mode;
int (*function)();
};
FS_FNCLIST fl[] =
{
{"free" , VFS_FS_INODE_FREE},
{"total" , VFS_FS_INODE_TOTAL},
{"used", VFS_FS_INODE_USED},
{"pfree" , VFS_FS_INODE_PFREE},
{"pused" , VFS_FS_INODE_PUSED},
{0, 0}
};
char fsname[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
assert(result);
clean_result(result);
if(num_param(param) > 2)
{
return SYSINFO_RET_FAIL;
}
if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
sprintf(mode, "total");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
return (fl[i].function)(cmd, fsname, flags, result);
}
}
return SYSINFO_RET_FAIL;
}
|