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> |
25 |
|
#include <sys/utsname.h> |
26 |
|
#include "statgrab.h" |
27 |
|
#ifdef SOLARIS |
28 |
|
#include <kstat.h> |
29 |
|
#include <time.h> |
30 |
|
#endif |
31 |
+ |
#ifdef LINUX |
32 |
+ |
#include <stdio.h> |
33 |
+ |
#endif |
34 |
+ |
#ifdef FREEBSD |
35 |
+ |
#include <sys/types.h> |
36 |
+ |
#include <sys/sysctl.h> |
37 |
+ |
#include <time.h> |
38 |
+ |
#include <sys/time.h> |
39 |
+ |
#endif |
40 |
|
|
41 |
|
general_stat_t *get_general_stats(){ |
42 |
|
|
43 |
|
static general_stat_t general_stat; |
44 |
+ |
static struct utsname os; |
45 |
|
|
46 |
< |
struct utsname os; |
46 |
> |
#ifdef SOLARIS |
47 |
|
time_t boottime,curtime; |
48 |
|
kstat_ctl_t *kc; |
49 |
|
kstat_t *ksp; |
50 |
|
kstat_named_t *kn; |
51 |
+ |
#endif |
52 |
+ |
#ifdef LINUX |
53 |
+ |
FILE *f; |
54 |
+ |
#endif |
55 |
+ |
#ifdef FREEBSD |
56 |
+ |
struct timeval boottime; |
57 |
+ |
time_t curtime; |
58 |
+ |
size_t size; |
59 |
+ |
#endif |
60 |
|
|
61 |
|
if((uname(&os)) < 0){ |
62 |
|
return NULL; |
69 |
|
general_stat.hostname = os.nodename; |
70 |
|
|
71 |
|
/* get uptime */ |
72 |
+ |
#ifdef SOLARIS |
73 |
|
if ((kc = kstat_open()) == NULL) { |
74 |
|
return NULL; |
75 |
|
} |
88 |
|
|
89 |
|
time(&curtime); |
90 |
|
general_stat.uptime = curtime - boottime; |
91 |
+ |
#endif |
92 |
+ |
#ifdef LINUX |
93 |
+ |
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
94 |
+ |
return NULL; |
95 |
+ |
} |
96 |
+ |
if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){ |
97 |
+ |
return NULL; |
98 |
+ |
} |
99 |
+ |
fclose(f); |
100 |
+ |
#endif |
101 |
+ |
#ifdef FREEBSD |
102 |
+ |
size = sizeof boottime; |
103 |
+ |
if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0){ |
104 |
+ |
return NULL; |
105 |
+ |
} |
106 |
+ |
time(&curtime); |
107 |
+ |
general_stat.uptime=curtime-boottime.tv_sec; |
108 |
+ |
#endif |
109 |
|
|
110 |
|
return &general_stat; |
111 |
|
|