1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2003 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
7 |
|
* modify it under the terms of the GNU General Public License |
22 |
|
#include "config.h" |
23 |
|
#endif |
24 |
|
|
25 |
– |
#include <stdio.h> |
26 |
– |
#include "ukcprog.h" |
25 |
|
#include "statgrab.h" |
26 |
+ |
#include "tools.h" |
27 |
|
#ifdef SOLARIS |
28 |
|
#include <sys/stat.h> |
29 |
|
#include <sys/swap.h> |
30 |
|
#include <unistd.h> |
31 |
|
#endif |
32 |
+ |
#ifdef LINUX |
33 |
+ |
#include <stdio.h> |
34 |
+ |
#endif |
35 |
+ |
#ifdef FREEBSD |
36 |
+ |
#include <unistd.h> |
37 |
+ |
#include <sys/types.h> |
38 |
+ |
#include <kvm.h> |
39 |
+ |
#endif |
40 |
|
|
41 |
|
swap_stat_t *get_swap_stats(){ |
42 |
|
|
43 |
|
static swap_stat_t swap_stat; |
44 |
|
|
45 |
+ |
#ifdef SOLARIS |
46 |
|
struct anoninfo ai; |
47 |
|
int pagesize; |
48 |
+ |
#endif |
49 |
+ |
#ifdef LINUX |
50 |
+ |
FILE *f; |
51 |
+ |
char *line_ptr; |
52 |
+ |
#endif |
53 |
+ |
#ifdef FREEBSD |
54 |
+ |
struct kvm_swap swapinfo; |
55 |
+ |
int pagesize; |
56 |
+ |
kvm_t *kvmd; |
57 |
+ |
#endif |
58 |
+ |
#ifdef NETBSD |
59 |
+ |
struct uvmexp *uvm; |
60 |
+ |
#endif |
61 |
|
|
62 |
+ |
#ifdef SOLARIS |
63 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
64 |
|
return NULL; |
65 |
|
} |
69 |
|
swap_stat.total = (long long)ai.ani_max * (long long)pagesize; |
70 |
|
swap_stat.used = (long long)ai.ani_resv * (long long)pagesize; |
71 |
|
swap_stat.free = swap_stat.total - swap_stat.used; |
72 |
+ |
#endif |
73 |
+ |
#ifdef LINUX |
74 |
+ |
if ((f=fopen("/proc/meminfo", "r" ))==NULL) { |
75 |
+ |
return NULL; |
76 |
+ |
} |
77 |
+ |
if((line_ptr=f_read_line(f, "Swap:"))==NULL){ |
78 |
+ |
fclose(f); |
79 |
+ |
return NULL; |
80 |
+ |
} |
81 |
+ |
if((sscanf(line_ptr, "Swap: %lld %lld %lld", &swap_stat.total, &swap_stat.used, &swap_stat.free))!=3){ |
82 |
+ |
fclose(f); |
83 |
+ |
return NULL; |
84 |
+ |
} |
85 |
+ |
fclose(f); |
86 |
+ |
#endif |
87 |
+ |
#ifdef FREEBSD |
88 |
+ |
if((kvmd = get_kvm()) == NULL){ |
89 |
+ |
return NULL; |
90 |
+ |
} |
91 |
+ |
if ((kvm_getswapinfo(kvmd, &swapinfo, 1,0)) == -1){ |
92 |
+ |
return NULL; |
93 |
+ |
} |
94 |
+ |
pagesize=getpagesize(); |
95 |
|
|
96 |
+ |
swap_stat.total= (long long)swapinfo.ksw_total * (long long)pagesize; |
97 |
+ |
swap_stat.used = (long long)swapinfo.ksw_used * (long long)pagesize; |
98 |
+ |
swap_stat.free = swap_stat.total-swap_stat.used; |
99 |
+ |
#endif |
100 |
+ |
#ifdef NETBSD |
101 |
+ |
if ((uvm = get_uvmexp()) == NULL) { |
102 |
+ |
return NULL; |
103 |
+ |
} |
104 |
+ |
|
105 |
+ |
swap_stat.total = (long long)uvm->pagesize * (long long)uvm->swpages; |
106 |
+ |
swap_stat.used = (long long)uvm->pagesize * (long long)uvm->swpginuse; |
107 |
+ |
swap_stat.free = swap_stat.total - swap_stat.used; |
108 |
+ |
#endif |
109 |
|
return &swap_stat; |
110 |
|
|
111 |
|
} |