aboutsummaryrefslogtreecommitdiffstats
path: root/testing/zabbix/zabbix-getloadavg.patch
blob: 44706abeb81ced2b7e24cc905cd482ae1de8d0f6 (plain)
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
diff --git a/src/libs/zbxsysinfo/linux/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c
index a76e756..9f9031d 100644
--- a/src/libs/zbxsysinfo/linux/cpu.c
+++ b/src/libs/zbxsysinfo/linux/cpu.c
@@ -22,6 +22,28 @@
 #include "sysinfo.h"
 #include "stats.h"
 
+#ifndef HAVE_GETLOADAVG
+/*! \brief Alternative method of getting load avg on Linux only */
+int getloadavg(double *list, int nelem)
+{
+        FILE *LOADAVG;
+        double avg[3] = { 0.0, 0.0, 0.0 };
+        int i, res = -1;
+
+        if ((LOADAVG = fopen("/proc/loadavg", "r"))) {
+                fscanf(LOADAVG, "%lf %lf %lf", &avg[0], &avg[1], &avg[2]);
+                res = 0;
+                fclose(LOADAVG);
+        }
+
+        for (i = 0; (i < nelem) && (i < 3); i++) {
+                list[i] = avg[i];
+        }
+
+        return res;
+}
+#endif
+
 int	SYSTEM_CPU_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
 {
 	char	mode[32];