-
Notifications
You must be signed in to change notification settings - Fork 81
/
ngx_sysinfo.c
81 lines (59 loc) · 1.42 KB
/
ngx_sysinfo.c
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
/*
* Copyright (C) 2010-2012 Alibaba Group Holding Limited
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_sysinfo.h>
#if (NGX_HAVE_SYSINFO)
#include <sys/sysinfo.h>
#endif
ngx_int_t
ngx_getloadavg(ngx_int_t avg[], ngx_int_t nelem, ngx_log_t *log)
{
#if (NGX_HAVE_GETLOADAVG)
double loadavg[3];
ngx_int_t i;
if (getloadavg(loadavg, nelem) == -1) {
return NGX_ERROR;
}
for (i = 0; i < nelem; i ++) {
avg[i] = loadavg[i] * 1000;
}
return NGX_OK;
#elif (NGX_HAVE_SYSINFO)
struct sysinfo s;
ngx_int_t i;
if (sysinfo(&s)) {
return NGX_ERROR;
}
for (i = 0; i < nelem; i ++) {
avg[i] = s.loads[i] * 1000 / 65536;
}
return NGX_OK;
#else
ngx_log_error(NGX_LOG_EMERG, log, 0,
"getloadavg is unsurpported under current os");
return NGX_ERROR;
#endif
}
ngx_int_t
ngx_getmeminfo(ngx_meminfo_t *meminfo, ngx_log_t *log)
{
#if (NGX_HAVE_SYSINFO)
struct sysinfo s;
if (sysinfo(&s)) {
return NGX_ERROR;
}
meminfo->totalram = s.totalram;
meminfo->freeram = s.freeram;
meminfo->sharedram = s.sharedram;
meminfo->bufferram = s.bufferram;
meminfo->totalswap = s.totalswap;
meminfo->freeswap = s.freeswap;
return NGX_OK;
#else
ngx_log_error(NGX_LOG_EMERG, log, 0,
"getmeminfo is unsurpported under current os");
return NGX_ERROR;
#endif
}