1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **/
19
20 #include "common.h"
21 #include "sysinfo.h"
22 #include "log.h"
23
KERNEL_MAXFILES(AGENT_REQUEST * request,AGENT_RESULT * result)24 int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
25 {
26 #ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
27 int mib[2];
28 size_t len;
29 int maxfiles;
30
31 mib[0] = CTL_KERN;
32 mib[1] = KERN_MAXFILES;
33
34 len = sizeof(maxfiles);
35
36 if (0 != sysctl(mib, 2, &maxfiles, &len, NULL, 0))
37 {
38 SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
39 return SYSINFO_RET_FAIL;
40 }
41
42 SET_UI64_RESULT(result, maxfiles);
43
44 return SYSINFO_RET_OK;
45 #else
46 SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"kern.maxfiles\" system"
47 " parameter."));
48 return SYSINFO_RET_FAIL;
49 #endif
50 }
51
KERNEL_MAXPROC(AGENT_REQUEST * request,AGENT_RESULT * result)52 int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
53 {
54 #ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
55 int mib[2];
56 size_t len;
57 int maxproc;
58
59 mib[0] = CTL_KERN;
60 mib[1] = KERN_MAXPROC;
61
62 len = sizeof(maxproc);
63
64 if (0 != sysctl(mib, 2, &maxproc, &len, NULL, 0))
65 {
66 SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
67 return SYSINFO_RET_FAIL;
68 }
69
70 SET_UI64_RESULT(result, maxproc);
71
72 return SYSINFO_RET_OK;
73 #else
74 SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"kern.maxproc\" system"
75 " parameter."));
76 return SYSINFO_RET_FAIL;
77 #endif
78 }
79