1 |
< |
/* |
2 |
< |
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
1 |
> |
/* |
2 |
> |
* i-scream libstatgrab |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2004 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. |
6 |
> |
* This library is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU Lesser General Public |
8 |
> |
* License as published by the Free Software Foundation; either |
9 |
> |
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
* |
11 |
< |
* This program is distributed in the hope that it will be useful, |
11 |
> |
* This library 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. |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
> |
* Lesser 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. |
16 |
> |
* You should have received a copy of the GNU Lesser General Public |
17 |
> |
* License along with this library; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
> |
* 02111-1307 USA |
20 |
> |
* |
21 |
> |
* $Id$ |
22 |
|
*/ |
23 |
|
|
24 |
|
#include <sys/types.h> |
25 |
|
|
26 |
< |
typedef struct{ |
27 |
< |
long long user; |
28 |
< |
long long kernel; |
29 |
< |
long long idle; |
30 |
< |
long long iowait; |
28 |
< |
long long swap; |
29 |
< |
long long nice; |
30 |
< |
long long total; |
31 |
< |
time_t systime; |
32 |
< |
}cpu_states_t; |
26 |
> |
/* FIXME typedefs for 32/64-bit types */ |
27 |
> |
/* FIXME maybe tidy up field names? */ |
28 |
> |
/* FIXME tab/space damage */ |
29 |
> |
/* FIXME prefixes for util functions too */ |
30 |
> |
/* FIXME comments for less obvious fields */ |
31 |
|
|
32 |
< |
typedef struct{ |
33 |
< |
float user; |
34 |
< |
float kernel; |
35 |
< |
float idle; |
36 |
< |
float iowait; |
37 |
< |
float swap; |
38 |
< |
float nice; |
32 |
> |
int sg_init(void); |
33 |
> |
int sg_drop_privileges(void); |
34 |
> |
|
35 |
> |
typedef enum { |
36 |
> |
SG_ERROR_NONE = 0, |
37 |
> |
SG_ERROR_ASPRINTF, |
38 |
> |
SG_ERROR_DEVSTAT_GETDEVS, |
39 |
> |
SG_ERROR_DEVSTAT_SELECTDEVS, |
40 |
> |
SG_ERROR_ENOENT, |
41 |
> |
SG_ERROR_GETIFADDRS, |
42 |
> |
SG_ERROR_GETMNTINFO, |
43 |
> |
SG_ERROR_GETPAGESIZE, |
44 |
> |
SG_ERROR_KSTAT_DATA_LOOKUP, |
45 |
> |
SG_ERROR_KSTAT_LOOKUP, |
46 |
> |
SG_ERROR_KSTAT_OPEN, |
47 |
> |
SG_ERROR_KSTAT_READ, |
48 |
> |
SG_ERROR_KVM_GETSWAPINFO, |
49 |
> |
SG_ERROR_KVM_OPENFILES, |
50 |
> |
SG_ERROR_MALLOC, |
51 |
> |
SG_ERROR_OPEN, |
52 |
> |
SG_ERROR_OPENDIR, |
53 |
> |
SG_ERROR_PARSE, |
54 |
> |
SG_ERROR_SETEGID, |
55 |
> |
SG_ERROR_SETEUID, |
56 |
> |
SG_ERROR_SETMNTENT, |
57 |
> |
SG_ERROR_SOCKET, |
58 |
> |
SG_ERROR_SWAPCTL, |
59 |
> |
SG_ERROR_SYSCONF, |
60 |
> |
SG_ERROR_SYSCTL, |
61 |
> |
SG_ERROR_SYSCTLBYNAME, |
62 |
> |
SG_ERROR_SYSCTLNAMETOMIB, |
63 |
> |
SG_ERROR_UNAME, |
64 |
> |
SG_ERROR_UNSUPPORTED, |
65 |
> |
SG_ERROR_XSW_VER_MISMATCH |
66 |
> |
} sg_error; |
67 |
> |
|
68 |
> |
void sg_set_error(sg_error code, const char *arg); |
69 |
> |
sg_error sg_get_error(); |
70 |
> |
const char *sg_get_error_arg(); |
71 |
> |
const char *sg_str_error(sg_error code); |
72 |
> |
|
73 |
> |
typedef struct { |
74 |
> |
char *os_name; |
75 |
> |
char *os_release; |
76 |
> |
char *os_version; |
77 |
> |
char *platform; |
78 |
> |
char *hostname; |
79 |
> |
time_t uptime; |
80 |
> |
} sg_host_info; |
81 |
> |
|
82 |
> |
sg_host_info *sg_get_host_info(); |
83 |
> |
|
84 |
> |
typedef struct { |
85 |
> |
long long user; |
86 |
> |
long long kernel; |
87 |
> |
long long idle; |
88 |
> |
long long iowait; |
89 |
> |
long long swap; |
90 |
> |
long long nice; |
91 |
> |
long long total; |
92 |
> |
time_t systime; |
93 |
> |
} sg_cpu_stats; |
94 |
> |
|
95 |
> |
sg_cpu_stats *sg_get_cpu_stats(); |
96 |
> |
sg_cpu_stats *sg_get_cpu_stats_diff(); |
97 |
> |
|
98 |
> |
typedef struct { |
99 |
> |
float user; |
100 |
> |
float kernel; |
101 |
> |
float idle; |
102 |
> |
float iowait; |
103 |
> |
float swap; |
104 |
> |
float nice; |
105 |
|
time_t time_taken; |
106 |
< |
}cpu_percent_t; |
106 |
> |
} sg_cpu_percents; |
107 |
|
|
108 |
< |
typedef struct{ |
108 |
> |
sg_cpu_percents *sg_get_cpu_percents(); |
109 |
> |
|
110 |
> |
typedef struct { |
111 |
|
long long total; |
112 |
|
long long free; |
113 |
|
long long used; |
114 |
|
long long cache; |
115 |
< |
}mem_stat_t; |
115 |
> |
} sg_mem_stats; |
116 |
|
|
117 |
< |
typedef struct{ |
117 |
> |
sg_mem_stats *sg_get_mem_stats(); |
118 |
> |
|
119 |
> |
typedef struct { |
120 |
|
double min1; |
121 |
|
double min5; |
122 |
|
double min15; |
123 |
< |
}load_stat_t; |
123 |
> |
} sg_load_stats; |
124 |
|
|
125 |
< |
#ifdef SOLARIS |
58 |
< |
#define MAX_LOGIN_NAME_SIZE 8 |
59 |
< |
#endif |
60 |
< |
#ifdef LINUX |
61 |
< |
#define MAX_LOGIN_NAME_SIZE UT_NAMESIZE |
62 |
< |
#endif |
125 |
> |
sg_load_stats *sg_get_load_stats(); |
126 |
|
|
127 |
< |
typedef struct{ |
127 |
> |
typedef struct { |
128 |
|
char *name_list; |
129 |
|
int num_entries; |
130 |
< |
}user_stat_t; |
130 |
> |
} sg_user_stats; |
131 |
|
|
132 |
< |
typedef struct{ |
132 |
> |
sg_user_stats *sg_get_user_stats(); |
133 |
> |
|
134 |
> |
typedef struct { |
135 |
|
long long total; |
136 |
|
long long used; |
137 |
|
long long free; |
138 |
< |
}swap_stat_t; |
138 |
> |
} sg_swap_stats; |
139 |
|
|
140 |
< |
typedef struct{ |
76 |
< |
char *os_name; |
77 |
< |
char *os_release; |
78 |
< |
char *os_version; |
79 |
< |
char *platform; |
80 |
< |
char *hostname; |
81 |
< |
time_t uptime; |
82 |
< |
}general_stat_t; |
140 |
> |
sg_swap_stats *sg_get_swap_stats(); |
141 |
|
|
142 |
|
typedef struct { |
143 |
< |
char *device_name; |
143 |
> |
char *device_name; |
144 |
|
char *fs_type; |
145 |
< |
char *mnt_point; |
146 |
< |
long long size; |
147 |
< |
long long used; |
148 |
< |
long long avail; |
149 |
< |
long long total_inodes; |
145 |
> |
char *mnt_point; |
146 |
> |
long long size; |
147 |
> |
long long used; |
148 |
> |
long long avail; |
149 |
> |
long long total_inodes; |
150 |
|
long long used_inodes; |
151 |
< |
long long free_inodes; |
152 |
< |
}disk_stat_t; |
151 |
> |
long long free_inodes; |
152 |
> |
} sg_fs_stats; |
153 |
|
|
154 |
< |
typedef struct{ |
154 |
> |
sg_fs_stats *sg_get_fs_stats(int *entries); |
155 |
> |
|
156 |
> |
typedef struct { |
157 |
|
char *disk_name; |
158 |
|
long long read_bytes; |
159 |
|
long long write_bytes; |
160 |
|
time_t systime; |
161 |
< |
}diskio_stat_t; |
161 |
> |
} sg_disk_io_stats; |
162 |
|
|
163 |
< |
typedef struct{ |
164 |
< |
int total; |
105 |
< |
int running; |
106 |
< |
int sleeping; |
107 |
< |
int stopped; |
108 |
< |
int zombie; |
109 |
< |
}process_stat_t; |
163 |
> |
sg_disk_io_stats *sg_get_disk_io_stats(int *entries); |
164 |
> |
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries); |
165 |
|
|
166 |
< |
typedef struct{ |
166 |
> |
typedef struct { |
167 |
|
char *interface_name; |
168 |
|
long long tx; |
169 |
|
long long rx; |
170 |
+ |
long long ipackets; |
171 |
+ |
long long opackets; |
172 |
+ |
long long ierrors; |
173 |
+ |
long long oerrors; |
174 |
+ |
long long collisions; |
175 |
|
time_t systime; |
176 |
< |
}network_stat_t; |
176 |
> |
} sg_network_io_stats; |
177 |
|
|
178 |
< |
typedef struct{ |
178 |
> |
sg_network_io_stats *sg_get_network_io_stats(int *entries); |
179 |
> |
sg_network_io_stats *sg_get_network_io_stats_diff(int *entries); |
180 |
> |
|
181 |
> |
typedef enum { |
182 |
> |
SG_IFACE_DUPLEX_FULL, |
183 |
> |
SG_IFACE_DUPLEX_HALF, |
184 |
> |
SG_IFACE_DUPLEX_UNKNOWN |
185 |
> |
} sg_iface_duplex; |
186 |
> |
|
187 |
> |
typedef struct { |
188 |
> |
char *interface_name; |
189 |
> |
int speed; /* In megabits/sec */ |
190 |
> |
sg_iface_duplex dup; |
191 |
> |
int up; |
192 |
> |
} sg_network_iface_stats; |
193 |
> |
|
194 |
> |
sg_network_iface_stats *sg_get_network_iface_stats(int *entries); |
195 |
> |
|
196 |
> |
typedef struct { |
197 |
|
long long pages_pagein; |
198 |
|
long long pages_pageout; |
199 |
|
time_t systime; |
200 |
< |
}page_stat_t; |
200 |
> |
} sg_page_stats; |
201 |
|
|
202 |
< |
cpu_states_t *get_cpu_totals(); |
203 |
< |
cpu_states_t *get_cpu_diff(); |
126 |
< |
cpu_percent_t *cpu_percent_usage(); |
202 |
> |
sg_page_stats *sg_get_page_stats(); |
203 |
> |
sg_page_stats *sg_get_page_stats_diff(); |
204 |
|
|
205 |
< |
mem_stat_t *get_memory_stats(); |
205 |
> |
typedef enum { |
206 |
> |
SG_PROCESS_STATE_RUNNING, |
207 |
> |
SG_PROCESS_STATE_SLEEPING, |
208 |
> |
SG_PROCESS_STATE_STOPPED, |
209 |
> |
SG_PROCESS_STATE_ZOMBIE, |
210 |
> |
SG_PROCESS_STATE_UNKNOWN |
211 |
> |
} sg_process_state; |
212 |
|
|
213 |
< |
load_stat_t *get_load_stats(); |
213 |
> |
typedef struct { |
214 |
> |
char *process_name; |
215 |
> |
char *proctitle; |
216 |
|
|
217 |
< |
user_stat_t *get_user_stats(); |
217 |
> |
pid_t pid; |
218 |
> |
pid_t parent; /* Parent pid */ |
219 |
> |
pid_t pgid; /* process id of process group leader */ |
220 |
|
|
221 |
< |
swap_stat_t *get_swap_stats(); |
221 |
> |
uid_t uid; |
222 |
> |
uid_t euid; |
223 |
> |
gid_t gid; |
224 |
> |
gid_t egid; |
225 |
|
|
226 |
< |
general_stat_t *get_general_stats(); |
226 |
> |
unsigned long long proc_size; /* in bytes */ |
227 |
> |
unsigned long long proc_resident; /* in bytes */ |
228 |
> |
time_t time_spent; /* time running in seconds */ |
229 |
> |
double cpu_percent; |
230 |
> |
int nice; |
231 |
> |
sg_process_state state; |
232 |
> |
} sg_process_stats; |
233 |
|
|
234 |
< |
disk_stat_t *get_disk_stats(int *entries); |
139 |
< |
diskio_stat_t *get_diskio_stats(int *entries); |
140 |
< |
diskio_stat_t *get_diskio_stats_diff(int *entries); |
234 |
> |
sg_process_stats *sg_get_process_stats(int *entries); |
235 |
|
|
236 |
< |
process_stat_t *get_process_stats(); |
236 |
> |
typedef struct { |
237 |
> |
int total; |
238 |
> |
int running; |
239 |
> |
int sleeping; |
240 |
> |
int stopped; |
241 |
> |
int zombie; |
242 |
> |
} sg_process_count; |
243 |
|
|
244 |
< |
network_stat_t *get_network_stats(int *entries); |
145 |
< |
network_stat_t *get_network_stats_diff(int *entries); |
244 |
> |
sg_process_count *sg_get_process_count(); |
245 |
|
|
246 |
< |
page_stat_t *get_page_stats(); |
247 |
< |
page_stat_t *get_page_stats_diff(); |
246 |
> |
#ifdef SG_ENABLE_DEPRECATED |
247 |
> |
#include <statgrab_deprecated.h> |
248 |
> |
#endif |
249 |
> |
|