1 |
pajs |
1.1 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.6 |
* http://www.i-scream.org |
4 |
|
|
* Copyright (C) 2000-2003 i-scream |
5 |
pajs |
1.1 |
* |
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 |
tdb |
1.3 |
#include <sys/utsname.h> |
26 |
pajs |
1.1 |
#include "statgrab.h" |
27 |
ats |
1.9 |
#include <stdlib.h> |
28 |
pajs |
1.1 |
#ifdef SOLARIS |
29 |
|
|
#include <kstat.h> |
30 |
|
|
#include <time.h> |
31 |
|
|
#endif |
32 |
ats |
1.11 |
#if defined(LINUX) || defined(CYGWIN) |
33 |
pajs |
1.4 |
#include <stdio.h> |
34 |
|
|
#endif |
35 |
ats |
1.9 |
#ifdef ALLBSD |
36 |
pajs |
1.5 |
#ifdef FREEBSD |
37 |
|
|
#include <sys/types.h> |
38 |
|
|
#include <sys/sysctl.h> |
39 |
ats |
1.9 |
#else |
40 |
|
|
#include <sys/param.h> |
41 |
|
|
#include <sys/sysctl.h> |
42 |
|
|
#endif |
43 |
pajs |
1.5 |
#include <time.h> |
44 |
|
|
#include <sys/time.h> |
45 |
|
|
#endif |
46 |
pajs |
1.1 |
|
47 |
|
|
general_stat_t *get_general_stats(){ |
48 |
|
|
|
49 |
|
|
static general_stat_t general_stat; |
50 |
pajs |
1.4 |
static struct utsname os; |
51 |
pajs |
1.1 |
|
52 |
pajs |
1.4 |
#ifdef SOLARIS |
53 |
pajs |
1.1 |
time_t boottime,curtime; |
54 |
|
|
kstat_ctl_t *kc; |
55 |
|
|
kstat_t *ksp; |
56 |
|
|
kstat_named_t *kn; |
57 |
pajs |
1.4 |
#endif |
58 |
ats |
1.11 |
#if defined(LINUX) || defined(CYGWIN) |
59 |
pajs |
1.4 |
FILE *f; |
60 |
|
|
#endif |
61 |
ats |
1.9 |
#ifdef ALLBSD |
62 |
|
|
int mib[2]; |
63 |
pajs |
1.5 |
struct timeval boottime; |
64 |
|
|
time_t curtime; |
65 |
|
|
size_t size; |
66 |
|
|
#endif |
67 |
pajs |
1.1 |
|
68 |
|
|
if((uname(&os)) < 0){ |
69 |
|
|
return NULL; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
general_stat.os_name = os.sysname; |
73 |
|
|
general_stat.os_release = os.release; |
74 |
|
|
general_stat.os_version = os.version; |
75 |
|
|
general_stat.platform = os.machine; |
76 |
|
|
general_stat.hostname = os.nodename; |
77 |
|
|
|
78 |
|
|
/* get uptime */ |
79 |
pajs |
1.4 |
#ifdef SOLARIS |
80 |
pajs |
1.1 |
if ((kc = kstat_open()) == NULL) { |
81 |
|
|
return NULL; |
82 |
|
|
} |
83 |
|
|
if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){ |
84 |
|
|
return NULL; |
85 |
|
|
} |
86 |
|
|
if (kstat_read(kc, ksp, 0) == -1) { |
87 |
|
|
return NULL; |
88 |
|
|
} |
89 |
|
|
if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){ |
90 |
|
|
return NULL; |
91 |
|
|
} |
92 |
|
|
boottime=(kn->value.ui32); |
93 |
pajs |
1.2 |
|
94 |
|
|
kstat_close(kc); |
95 |
pajs |
1.1 |
|
96 |
|
|
time(&curtime); |
97 |
|
|
general_stat.uptime = curtime - boottime; |
98 |
pajs |
1.4 |
#endif |
99 |
ats |
1.11 |
#if defined(LINUX) || defined(CYGWIN) |
100 |
pajs |
1.4 |
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
101 |
|
|
return NULL; |
102 |
|
|
} |
103 |
|
|
if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){ |
104 |
|
|
return NULL; |
105 |
|
|
} |
106 |
|
|
fclose(f); |
107 |
pajs |
1.5 |
#endif |
108 |
ats |
1.9 |
#ifdef ALLBSD |
109 |
|
|
mib[0] = CTL_KERN; |
110 |
|
|
mib[1] = KERN_BOOTTIME; |
111 |
ats |
1.8 |
size = sizeof boottime; |
112 |
ats |
1.9 |
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){ |
113 |
pajs |
1.5 |
return NULL; |
114 |
|
|
} |
115 |
|
|
time(&curtime); |
116 |
|
|
general_stat.uptime=curtime-boottime.tv_sec; |
117 |
pajs |
1.4 |
#endif |
118 |
pajs |
1.1 |
|
119 |
|
|
return &general_stat; |
120 |
|
|
|
121 |
|
|
} |