1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* http://www.i-scream.org.uk |
4 |
* Copyright (C) 2000-2002 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 |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
*/ |
20 |
|
21 |
#ifdef HAVE_CONFIG_H |
22 |
#include "config.h" |
23 |
#endif |
24 |
|
25 |
#include "statgrab.h" |
26 |
#ifdef SOLARIS |
27 |
#include <sys/stat.h> |
28 |
#include <sys/swap.h> |
29 |
#include <unistd.h> |
30 |
#endif |
31 |
#ifdef LINUX |
32 |
#include <stdio.h> |
33 |
#include "tools.h" |
34 |
#endif |
35 |
|
36 |
swap_stat_t *get_swap_stats(){ |
37 |
|
38 |
static swap_stat_t swap_stat; |
39 |
|
40 |
#ifdef SOLARIS |
41 |
struct anoninfo ai; |
42 |
int pagesize; |
43 |
#endif |
44 |
#ifdef LINUX |
45 |
FILE *f; |
46 |
char *line_ptr; |
47 |
#endif |
48 |
|
49 |
#ifdef SOLARIS |
50 |
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
51 |
return NULL; |
52 |
} |
53 |
if (swapctl(SC_AINFO, &ai) == -1) { |
54 |
return NULL; |
55 |
} |
56 |
swap_stat.total = (long long)ai.ani_max * (long long)pagesize; |
57 |
swap_stat.used = (long long)ai.ani_resv * (long long)pagesize; |
58 |
swap_stat.free = swap_stat.total - swap_stat.used; |
59 |
#endif |
60 |
#ifdef LINUX |
61 |
if ((f=fopen("/proc/meminfo", "r" ))==NULL) { |
62 |
return NULL; |
63 |
} |
64 |
if((line_ptr=f_read_line(f, "Swap:"))==NULL){ |
65 |
fclose(f); |
66 |
return NULL; |
67 |
} |
68 |
if((sscanf(line_ptr, "Swap: %lld %lld %lld", &swap_stat.total, &swap_stat.used, &swap_stat.free))!=3){ |
69 |
fclose(f); |
70 |
return NULL; |
71 |
} |
72 |
fclose(f); |
73 |
#endif |
74 |
|
75 |
return &swap_stat; |
76 |
|
77 |
} |