1 |
< |
# TODO: return values more the python way - like os.stat |
2 |
< |
# deal with failures better (return nothing, or raise error?) |
1 |
> |
# |
2 |
> |
# i-scream pystatgrab |
3 |
> |
# http://www.i-scream.org/pystatgrab/ |
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. |
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 |
> |
# $Id$ |
21 |
> |
# |
22 |
|
|
23 |
|
ctypedef long time_t |
24 |
+ |
ctypedef int pid_t |
25 |
+ |
ctypedef int uid_t |
26 |
+ |
ctypedef int gid_t |
27 |
|
|
28 |
|
cdef extern from "statgrab.h": |
29 |
< |
ctypedef struct cpu_states_t: |
29 |
> |
cdef extern int sg_init() |
30 |
> |
cdef extern int sg_drop_privileges() |
31 |
> |
|
32 |
> |
ctypedef enum sg_error: |
33 |
> |
SG_ERROR_NONE = 0 |
34 |
> |
SG_ERROR_ASPRINTF |
35 |
> |
SG_ERROR_DEVSTAT_GETDEVS |
36 |
> |
SG_ERROR_DEVSTAT_SELECTDEVS |
37 |
> |
SG_ERROR_ENOENT |
38 |
> |
SG_ERROR_GETIFADDRS |
39 |
> |
SG_ERROR_GETMNTINFO |
40 |
> |
SG_ERROR_GETPAGESIZE |
41 |
> |
SG_ERROR_KSTAT_DATA_LOOKUP |
42 |
> |
SG_ERROR_KSTAT_LOOKUP |
43 |
> |
SG_ERROR_KSTAT_OPEN |
44 |
> |
SG_ERROR_KSTAT_READ |
45 |
> |
SG_ERROR_KVM_GETSWAPINFO |
46 |
> |
SG_ERROR_KVM_OPENFILES |
47 |
> |
SG_ERROR_MALLOC |
48 |
> |
SG_ERROR_OPEN |
49 |
> |
SG_ERROR_OPENDIR |
50 |
> |
SG_ERROR_PARSE |
51 |
> |
SG_ERROR_SETEGID |
52 |
> |
SG_ERROR_SETEUID |
53 |
> |
SG_ERROR_SETMNTENT |
54 |
> |
SG_ERROR_SOCKET |
55 |
> |
SG_ERROR_SWAPCTL |
56 |
> |
SG_ERROR_SYSCONF |
57 |
> |
SG_ERROR_SYSCTL |
58 |
> |
SG_ERROR_SYSCTLBYNAME |
59 |
> |
SG_ERROR_SYSCTLNAMETOMIB |
60 |
> |
SG_ERROR_UNAME |
61 |
> |
SG_ERROR_UNSUPPORTED |
62 |
> |
SG_ERROR_XSW_VER_MISMATCH |
63 |
> |
|
64 |
> |
cdef extern void sg_set_error(sg_error code, char *arg) |
65 |
> |
cdef extern void sg_set_error_with_errno(sg_error code, char *arg) |
66 |
> |
cdef extern sg_error sg_get_error() |
67 |
> |
cdef extern char *sg_get_error_arg() |
68 |
> |
cdef extern int sg_get_error_errno() |
69 |
> |
cdef extern char *sg_str_error(sg_error code) |
70 |
> |
|
71 |
> |
ctypedef struct sg_host_info: |
72 |
> |
char *os_name |
73 |
> |
char *os_release |
74 |
> |
char *os_version |
75 |
> |
char *platform |
76 |
> |
char *hostname |
77 |
> |
time_t uptime |
78 |
> |
|
79 |
> |
cdef extern sg_host_info *sg_get_host_info() |
80 |
> |
|
81 |
> |
ctypedef struct sg_cpu_stats: |
82 |
|
long long user |
83 |
|
long long kernel |
84 |
|
long long idle |
88 |
|
long long total |
89 |
|
time_t systime |
90 |
|
|
91 |
< |
ctypedef struct cpu_percent_t: |
91 |
> |
cdef extern sg_cpu_stats *sg_get_cpu_stats() |
92 |
> |
cdef extern sg_cpu_stats *sg_get_cpu_stats_diff() |
93 |
> |
|
94 |
> |
ctypedef struct sg_cpu_percents: |
95 |
|
float user |
96 |
|
float kernel |
97 |
|
float idle |
100 |
|
float nice |
101 |
|
time_t time_taken |
102 |
|
|
103 |
< |
ctypedef struct mem_stat_t: |
103 |
> |
cdef extern sg_cpu_percents *sg_get_cpu_percents() |
104 |
> |
|
105 |
> |
ctypedef struct sg_mem_stats: |
106 |
|
long long total |
107 |
|
long long free |
108 |
|
long long used |
109 |
|
long long cache |
110 |
|
|
111 |
< |
ctypedef struct load_stat_t: |
111 |
> |
cdef extern sg_mem_stats *sg_get_mem_stats() |
112 |
> |
|
113 |
> |
ctypedef struct sg_load_stats: |
114 |
|
double min1 |
115 |
|
double min5 |
116 |
|
double min15 |
117 |
|
|
118 |
< |
ctypedef struct user_stat_t: |
118 |
> |
cdef extern sg_load_stats *sg_get_load_stats() |
119 |
> |
|
120 |
> |
ctypedef struct sg_user_stats: |
121 |
|
char *name_list |
122 |
|
int num_entries |
123 |
|
|
124 |
< |
ctypedef struct swap_stat_t: |
124 |
> |
cdef extern sg_user_stats *sg_get_user_stats() |
125 |
> |
|
126 |
> |
ctypedef struct sg_swap_stats: |
127 |
|
long long total |
128 |
|
long long used |
129 |
|
long long free |
130 |
|
|
131 |
< |
ctypedef struct general_stat_t: |
47 |
< |
char *os_name |
48 |
< |
char *os_release |
49 |
< |
char *os_version |
50 |
< |
char *platform |
51 |
< |
char *hostname |
52 |
< |
time_t uptime |
131 |
> |
cdef extern sg_swap_stats *sg_get_swap_stats() |
132 |
|
|
133 |
< |
ctypedef struct disk_stat_t: |
133 |
> |
ctypedef struct sg_fs_stats: |
134 |
|
char *device_name |
135 |
|
char *fs_type |
136 |
|
char *mnt_point |
141 |
|
long long used_inodes |
142 |
|
long long free_inodes |
143 |
|
|
144 |
< |
ctypedef struct diskio_stat_t: |
144 |
> |
cdef extern sg_fs_stats *sg_get_fs_stats(int *entries) |
145 |
> |
|
146 |
> |
ctypedef struct sg_disk_io_stats: |
147 |
|
char *disk_name |
148 |
|
long long read_bytes |
149 |
|
long long write_bytes |
150 |
|
time_t systime |
151 |
|
|
152 |
< |
ctypedef struct process_stat_t: |
153 |
< |
int total |
73 |
< |
int running |
74 |
< |
int sleeping |
75 |
< |
int stopped |
76 |
< |
int zombie |
152 |
> |
cdef extern sg_disk_io_stats *sg_get_disk_io_stats(int *entries) |
153 |
> |
cdef extern sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries) |
154 |
|
|
155 |
< |
ctypedef struct network_stat_t: |
155 |
> |
ctypedef struct sg_network_io_stats: |
156 |
|
char *interface_name |
157 |
|
long long tx |
158 |
|
long long rx |
159 |
+ |
long long ipackets |
160 |
+ |
long long opackets |
161 |
+ |
long long ierrors |
162 |
+ |
long long oerrors |
163 |
+ |
long long collisions |
164 |
|
time_t systime |
165 |
|
|
166 |
< |
ctypedef struct page_stat_t: |
166 |
> |
cdef extern sg_network_io_stats *sg_get_network_io_stats(int *entries) |
167 |
> |
cdef extern sg_network_io_stats *sg_get_network_io_stats_diff(int *entries) |
168 |
> |
|
169 |
> |
ctypedef enum sg_iface_duplex: |
170 |
> |
SG_IFACE_DUPLEX_FULL |
171 |
> |
SG_IFACE_DUPLEX_HALF |
172 |
> |
SG_IFACE_DUPLEX_UNKNOWN |
173 |
> |
|
174 |
> |
ctypedef struct sg_network_iface_stats: |
175 |
> |
char *interface_name |
176 |
> |
int speed |
177 |
> |
sg_iface_duplex dup |
178 |
> |
int up |
179 |
> |
|
180 |
> |
cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries) |
181 |
> |
|
182 |
> |
ctypedef struct sg_page_stats: |
183 |
|
long long pages_pagein |
184 |
|
long long pages_pageout |
185 |
|
time_t systime |
186 |
|
|
187 |
< |
cdef extern cpu_states_t *get_cpu_totals() |
188 |
< |
cdef extern cpu_states_t *get_cpu_diff() |
91 |
< |
cdef extern cpu_percent_t *cpu_percent_usage() |
92 |
< |
cdef extern mem_stat_t *get_memory_stats() |
93 |
< |
cdef extern load_stat_t *get_load_stats() |
94 |
< |
cdef extern user_stat_t *get_user_stats() |
95 |
< |
cdef extern swap_stat_t *get_swap_stats() |
96 |
< |
cdef extern general_stat_t *get_general_stats() |
97 |
< |
cdef extern disk_stat_t *get_disk_stats(int *entries) |
98 |
< |
cdef extern diskio_stat_t *get_diskio_stats(int *entries) |
99 |
< |
cdef extern diskio_stat_t *get_diskio_stats_diff(int *entries) |
100 |
< |
cdef extern process_stat_t *get_process_stats() |
101 |
< |
cdef extern network_stat_t *get_network_stats(int *entries) |
102 |
< |
cdef extern network_stat_t *get_network_stats_diff(int *entries) |
103 |
< |
cdef extern page_stat_t *get_page_stats() |
104 |
< |
cdef extern page_stat_t *get_page_stats_diff() |
105 |
< |
cdef extern int statgrab_init() |
106 |
< |
cdef extern int statgrab_drop_privileges() |
187 |
> |
cdef extern sg_page_stats *sg_get_page_stats() |
188 |
> |
cdef extern sg_page_stats *sg_get_page_stats_diff() |
189 |
|
|
190 |
+ |
ctypedef enum sg_process_state: |
191 |
+ |
SG_PROCESS_STATE_RUNNING |
192 |
+ |
SG_PROCESS_STATE_SLEEPING |
193 |
+ |
SG_PROCESS_STATE_STOPPED |
194 |
+ |
SG_PROCESS_STATE_ZOMBIE |
195 |
+ |
SG_PROCESS_STATE_UNKNOWN |
196 |
|
|
197 |
< |
def py_get_cpu_totals(): |
198 |
< |
cdef cpu_states_t *s |
199 |
< |
s = get_cpu_totals() |
200 |
< |
return {'user': s.user, |
201 |
< |
'kernel': s.kernel, |
202 |
< |
'idle': s.idle, |
203 |
< |
'iowait': s.iowait, |
204 |
< |
'swap': s.swap, |
205 |
< |
'nice': s.nice, |
206 |
< |
'total': s.total, |
207 |
< |
'systime': s.systime, |
208 |
< |
} |
197 |
> |
ctypedef struct sg_process_stats: |
198 |
> |
char *process_name |
199 |
> |
char *proctitle |
200 |
> |
pid_t pid |
201 |
> |
pid_t parent |
202 |
> |
pid_t pgid |
203 |
> |
uid_t uid |
204 |
> |
uid_t euid |
205 |
> |
gid_t gid |
206 |
> |
gid_t egid |
207 |
> |
unsigned long long proc_size |
208 |
> |
unsigned long long proc_resident |
209 |
> |
time_t time_spent |
210 |
> |
double cpu_percent |
211 |
> |
int nice |
212 |
> |
sg_process_state state |
213 |
|
|
214 |
< |
def py_get_cpu_diff(): |
123 |
< |
cdef cpu_states_t *s |
124 |
< |
s = get_cpu_diff() |
125 |
< |
return {'user': s.user, |
126 |
< |
'kernel': s.kernel, |
127 |
< |
'idle': s.idle, |
128 |
< |
'iowait': s.iowait, |
129 |
< |
'swap': s.swap, |
130 |
< |
'nice': s.nice, |
131 |
< |
'total': s.total, |
132 |
< |
'systime': s.systime, |
133 |
< |
} |
214 |
> |
cdef extern sg_process_stats *sg_get_process_stats(int *entries) |
215 |
|
|
216 |
< |
def py_cpu_percent_usage(): |
217 |
< |
cdef cpu_percent_t *s |
218 |
< |
s = cpu_percent_usage() |
219 |
< |
return {'user': s.user, |
220 |
< |
'kernel': s.kernel, |
221 |
< |
'idle': s.idle, |
141 |
< |
'iowait': s.iowait, |
142 |
< |
'swap': s.swap, |
143 |
< |
'nice': s.nice, |
144 |
< |
'time_taken': s.time_taken, |
145 |
< |
} |
216 |
> |
ctypedef struct sg_process_count: |
217 |
> |
int total |
218 |
> |
int running |
219 |
> |
int sleeping |
220 |
> |
int stopped |
221 |
> |
int zombie |
222 |
|
|
223 |
< |
def py_get_memory_stats(): |
148 |
< |
cdef mem_stat_t *s |
149 |
< |
s = get_memory_stats() |
150 |
< |
return {'total': s.total, |
151 |
< |
'used': s.used, |
152 |
< |
'free': s.free, |
153 |
< |
'cache': s.cache, |
154 |
< |
} |
223 |
> |
cdef extern sg_process_count *sg_get_process_count() |
224 |
|
|
156 |
– |
def py_get_load_stats(): |
157 |
– |
cdef load_stat_t *s |
158 |
– |
s = get_load_stats() |
159 |
– |
return {'min1': s.min1, |
160 |
– |
'min5': s.min5, |
161 |
– |
'min15': s.min15, |
162 |
– |
} |
225 |
|
|
226 |
< |
def py_get_user_stats(): |
227 |
< |
cdef user_stat_t *s |
228 |
< |
s = get_user_stats() |
229 |
< |
return {'name_list': s.name_list, |
230 |
< |
'num_entries': s.num_entries, |
231 |
< |
} |
226 |
> |
py_SG_ERROR_NONE = SG_ERROR_NONE |
227 |
> |
py_SG_ERROR_ASPRINTF = SG_ERROR_ASPRINTF |
228 |
> |
py_SG_ERROR_DEVSTAT_GETDEVS = SG_ERROR_DEVSTAT_GETDEVS |
229 |
> |
py_SG_ERROR_DEVSTAT_SELECTDEVS = SG_ERROR_DEVSTAT_SELECTDEVS |
230 |
> |
py_SG_ERROR_ENOENT = SG_ERROR_ENOENT |
231 |
> |
py_SG_ERROR_GETIFADDRS = SG_ERROR_GETIFADDRS |
232 |
> |
py_SG_ERROR_GETMNTINFO = SG_ERROR_GETMNTINFO |
233 |
> |
py_SG_ERROR_GETPAGESIZE = SG_ERROR_GETPAGESIZE |
234 |
> |
py_SG_ERROR_KSTAT_DATA_LOOKUP = SG_ERROR_KSTAT_DATA_LOOKUP |
235 |
> |
py_SG_ERROR_KSTAT_LOOKUP = SG_ERROR_KSTAT_LOOKUP |
236 |
> |
py_SG_ERROR_KSTAT_OPEN = SG_ERROR_KSTAT_OPEN |
237 |
> |
py_SG_ERROR_KSTAT_READ = SG_ERROR_KSTAT_READ |
238 |
> |
py_SG_ERROR_KVM_GETSWAPINFO = SG_ERROR_KVM_GETSWAPINFO |
239 |
> |
py_SG_ERROR_KVM_OPENFILES = SG_ERROR_KVM_OPENFILES |
240 |
> |
py_SG_ERROR_MALLOC = SG_ERROR_MALLOC |
241 |
> |
py_SG_ERROR_OPEN = SG_ERROR_OPEN |
242 |
> |
py_SG_ERROR_OPENDIR = SG_ERROR_OPENDIR |
243 |
> |
py_SG_ERROR_PARSE = SG_ERROR_PARSE |
244 |
> |
py_SG_ERROR_SETEGID = SG_ERROR_SETEGID |
245 |
> |
py_SG_ERROR_SETEUID = SG_ERROR_SETEUID |
246 |
> |
py_SG_ERROR_SETMNTENT = SG_ERROR_SETMNTENT |
247 |
> |
py_SG_ERROR_SOCKET = SG_ERROR_SOCKET |
248 |
> |
py_SG_ERROR_SWAPCTL = SG_ERROR_SWAPCTL |
249 |
> |
py_SG_ERROR_SYSCONF = SG_ERROR_SYSCONF |
250 |
> |
py_SG_ERROR_SYSCTL = SG_ERROR_SYSCTL |
251 |
> |
py_SG_ERROR_SYSCTLBYNAME = SG_ERROR_SYSCTLBYNAME |
252 |
> |
py_SG_ERROR_SYSCTLNAMETOMIB = SG_ERROR_SYSCTLNAMETOMIB |
253 |
> |
py_SG_ERROR_UNAME = SG_ERROR_UNAME |
254 |
> |
py_SG_ERROR_UNSUPPORTED = SG_ERROR_UNSUPPORTED |
255 |
> |
py_SG_ERROR_XSW_VER_MISMATCH = SG_ERROR_XSW_VER_MISMATCH |
256 |
|
|
257 |
< |
def py_get_swap_stats(): |
258 |
< |
cdef swap_stat_t *s |
259 |
< |
s = get_swap_stats() |
174 |
< |
return {'total': s.total, |
175 |
< |
'used': s.used, |
176 |
< |
'free': s.free, |
177 |
< |
} |
257 |
> |
py_SG_IFACE_DUPLEX_FULL = SG_IFACE_DUPLEX_FULL |
258 |
> |
py_SG_IFACE_DUPLEX_HALF = SG_IFACE_DUPLEX_HALF |
259 |
> |
py_SG_IFACE_DUPLEX_UNKNOWN = SG_IFACE_DUPLEX_UNKNOWN |
260 |
|
|
261 |
< |
def py_get_general_stats(): |
262 |
< |
cdef general_stat_t *s |
263 |
< |
s = get_general_stats() |
264 |
< |
return {'os_name': s.os_name, |
265 |
< |
'os_release': s.os_release, |
184 |
< |
'os_version': s.os_version, |
185 |
< |
'platform': s.platform, |
186 |
< |
'hostname': s.hostname, |
187 |
< |
'uptime': s.uptime, |
188 |
< |
} |
261 |
> |
py_SG_PROCESS_STATE_RUNNING = SG_PROCESS_STATE_RUNNING |
262 |
> |
py_SG_PROCESS_STATE_SLEEPING = SG_PROCESS_STATE_SLEEPING |
263 |
> |
py_SG_PROCESS_STATE_STOPPED = SG_PROCESS_STATE_STOPPED |
264 |
> |
py_SG_PROCESS_STATE_ZOMBIE = SG_PROCESS_STATE_ZOMBIE |
265 |
> |
py_SG_PROCESS_STATE_UNKNOWN = SG_PROCESS_STATE_UNKNOWN |
266 |
|
|
267 |
< |
def py_get_disk_stats(): |
268 |
< |
cdef disk_stat_t *s |
267 |
> |
|
268 |
> |
class Result: |
269 |
> |
def __init__(self, attrs): |
270 |
> |
self.attrs = attrs |
271 |
> |
for attr in attrs: |
272 |
> |
setattr(self, attr, attrs[attr]) |
273 |
> |
def __getitem__(self, item): |
274 |
> |
return getattr(self, item) |
275 |
> |
def __repr__(self): |
276 |
> |
return str(self.attrs) |
277 |
> |
|
278 |
> |
class StatgrabException(Exception): |
279 |
> |
def __init__(self, value): |
280 |
> |
self.value = value |
281 |
> |
def __str__(self): |
282 |
> |
return repr(self.value) |
283 |
> |
|
284 |
> |
|
285 |
> |
def py_sg_init(): |
286 |
> |
if sg_init() == 0: |
287 |
> |
return True |
288 |
> |
else: |
289 |
> |
return False |
290 |
> |
|
291 |
> |
def py_sg_drop_privileges(): |
292 |
> |
if sg_drop_privileges() == 0: |
293 |
> |
return True |
294 |
> |
else: |
295 |
> |
return False |
296 |
> |
|
297 |
> |
def py_sg_set_error(code, arg): |
298 |
> |
sg_set_error(code, arg) |
299 |
> |
|
300 |
> |
def py_sg_set_error_with_errno(code, arg): |
301 |
> |
sg_set_error_with_errno(code, arg) |
302 |
> |
|
303 |
> |
def py_sg_get_error(): |
304 |
> |
cdef sg_error s |
305 |
> |
s = sg_get_error() |
306 |
> |
return s |
307 |
> |
|
308 |
> |
def py_sg_get_error_arg(): |
309 |
> |
s = sg_get_error_arg() |
310 |
> |
return s |
311 |
> |
|
312 |
> |
def py_sg_get_error_errno(): |
313 |
> |
s = sg_get_error_errno() |
314 |
> |
return s |
315 |
> |
|
316 |
> |
def py_sg_str_error(code): |
317 |
> |
s = sg_str_error(code) |
318 |
> |
return s |
319 |
> |
|
320 |
> |
def py_sg_get_host_info(): |
321 |
> |
cdef sg_host_info *s |
322 |
> |
s = sg_get_host_info() |
323 |
> |
if s == NULL: |
324 |
> |
raise StatgrabException, 'sg_get_host_info() returned NULL' |
325 |
> |
return Result( |
326 |
> |
{'os_name': s.os_name, |
327 |
> |
'os_release': s.os_release, |
328 |
> |
'os_version': s.os_version, |
329 |
> |
'platform': s.platform, |
330 |
> |
'hostname': s.hostname, |
331 |
> |
'uptime': s.uptime, |
332 |
> |
} |
333 |
> |
) |
334 |
> |
|
335 |
> |
def py_sg_get_cpu_stats(): |
336 |
> |
cdef sg_cpu_stats *s |
337 |
> |
s = sg_get_cpu_stats() |
338 |
> |
if s == NULL: |
339 |
> |
raise StatgrabException, 'sg_get_cpu_stats() returned NULL' |
340 |
> |
return Result( |
341 |
> |
{'user': s.user, |
342 |
> |
'kernel': s.kernel, |
343 |
> |
'idle': s.idle, |
344 |
> |
'iowait': s.iowait, |
345 |
> |
'swap': s.swap, |
346 |
> |
'nice': s.nice, |
347 |
> |
'total': s.total, |
348 |
> |
'systime': s.systime, |
349 |
> |
} |
350 |
> |
) |
351 |
> |
|
352 |
> |
def py_sg_get_cpu_stats_diff(): |
353 |
> |
cdef sg_cpu_stats *s |
354 |
> |
s = sg_get_cpu_stats_diff() |
355 |
> |
if s == NULL: |
356 |
> |
raise StatgrabException, 'sg_get_cpu_stats_diff() returned NULL' |
357 |
> |
return Result( |
358 |
> |
{'user': s.user, |
359 |
> |
'kernel': s.kernel, |
360 |
> |
'idle': s.idle, |
361 |
> |
'iowait': s.iowait, |
362 |
> |
'swap': s.swap, |
363 |
> |
'nice': s.nice, |
364 |
> |
'total': s.total, |
365 |
> |
'systime': s.systime, |
366 |
> |
} |
367 |
> |
) |
368 |
> |
|
369 |
> |
def py_sg_get_cpu_percents(): |
370 |
> |
cdef sg_cpu_percents *s |
371 |
> |
s = sg_get_cpu_percents() |
372 |
> |
if s == NULL: |
373 |
> |
raise StatgrabException, 'sg_get_cpu_percents() returned NULL' |
374 |
> |
return Result( |
375 |
> |
{'user': s.user, |
376 |
> |
'kernel': s.kernel, |
377 |
> |
'idle': s.idle, |
378 |
> |
'iowait': s.iowait, |
379 |
> |
'swap': s.swap, |
380 |
> |
'nice': s.nice, |
381 |
> |
'time_taken': s.time_taken, |
382 |
> |
} |
383 |
> |
) |
384 |
> |
|
385 |
> |
def py_sg_get_mem_stats(): |
386 |
> |
cdef sg_mem_stats *s |
387 |
> |
s = sg_get_mem_stats() |
388 |
> |
if s == NULL: |
389 |
> |
raise StatgrabException, 'sg_get_mem_stats() returned NULL' |
390 |
> |
return Result( |
391 |
> |
{'total': s.total, |
392 |
> |
'used': s.used, |
393 |
> |
'free': s.free, |
394 |
> |
'cache': s.cache, |
395 |
> |
} |
396 |
> |
) |
397 |
> |
|
398 |
> |
def py_sg_get_load_stats(): |
399 |
> |
cdef sg_load_stats *s |
400 |
> |
s = sg_get_load_stats() |
401 |
> |
if s == NULL: |
402 |
> |
raise StatgrabException, 'sg_get_load_stats() returned NULL' |
403 |
> |
return Result( |
404 |
> |
{'min1': s.min1, |
405 |
> |
'min5': s.min5, |
406 |
> |
'min15': s.min15, |
407 |
> |
} |
408 |
> |
) |
409 |
> |
|
410 |
> |
def py_sg_get_user_stats(): |
411 |
> |
cdef sg_user_stats *s |
412 |
> |
s = sg_get_user_stats() |
413 |
> |
if s == NULL: |
414 |
> |
raise StatgrabException, 'sg_get_user_stats() returned NULL' |
415 |
> |
return Result( |
416 |
> |
{'name_list': s.name_list, |
417 |
> |
'num_entries': s.num_entries, |
418 |
> |
} |
419 |
> |
) |
420 |
> |
|
421 |
> |
def py_sg_get_swap_stats(): |
422 |
> |
cdef sg_swap_stats *s |
423 |
> |
s = sg_get_swap_stats() |
424 |
> |
if s == NULL: |
425 |
> |
raise StatgrabException, 'sg_get_swap_stats() returned NULL' |
426 |
> |
return Result( |
427 |
> |
{'total': s.total, |
428 |
> |
'used': s.used, |
429 |
> |
'free': s.free, |
430 |
> |
} |
431 |
> |
) |
432 |
> |
|
433 |
> |
def py_sg_get_fs_stats(): |
434 |
> |
cdef sg_fs_stats *s |
435 |
|
cdef int entries |
436 |
< |
s = get_disk_stats(&entries) |
437 |
< |
list = [entries] |
436 |
> |
s = sg_get_fs_stats(&entries) |
437 |
> |
if s == NULL: |
438 |
> |
raise StatgrabException, 'sg_get_fs_stats() returned NULL' |
439 |
> |
list = [] |
440 |
|
for i from 0 <= i < entries: |
441 |
< |
list.append({'device_name': s.device_name, |
442 |
< |
'fs_type': s.fs_type, |
443 |
< |
'mnt_point': s.mnt_point, |
444 |
< |
'size': s.size, |
445 |
< |
'used': s.used, |
446 |
< |
'avail': s.avail, |
447 |
< |
'total_inodes': s.total_inodes, |
448 |
< |
'used_inodes': s.used_inodes, |
449 |
< |
'free_inodes': s.free_inodes, |
450 |
< |
}, |
451 |
< |
) |
441 |
> |
list.append(Result( |
442 |
> |
{'device_name': s.device_name, |
443 |
> |
'fs_type': s.fs_type, |
444 |
> |
'mnt_point': s.mnt_point, |
445 |
> |
'size': s.size, |
446 |
> |
'used': s.used, |
447 |
> |
'avail': s.avail, |
448 |
> |
'total_inodes': s.total_inodes, |
449 |
> |
'used_inodes': s.used_inodes, |
450 |
> |
'free_inodes': s.free_inodes, |
451 |
> |
} |
452 |
> |
)) |
453 |
|
s = s + 1 |
454 |
|
return list |
455 |
|
|
456 |
< |
def py_get_diskio_stats(): |
457 |
< |
cdef diskio_stat_t *s |
456 |
> |
def py_sg_get_disk_io_stats(): |
457 |
> |
cdef sg_disk_io_stats *s |
458 |
|
cdef int entries |
459 |
< |
s = get_diskio_stats(&entries) |
460 |
< |
list = [entries] |
459 |
> |
s = sg_get_disk_io_stats(&entries) |
460 |
> |
if s == NULL: |
461 |
> |
raise StatgrabException, 'sg_get_disk_io_stats() returned NULL' |
462 |
> |
list = [] |
463 |
|
for i from 0 <= i < entries: |
464 |
< |
list.append({'disk_name': s.disk_name, |
465 |
< |
'read_bytes': s.read_bytes, |
466 |
< |
'write_bytes': s.write_bytes, |
467 |
< |
'systime': s.systime, |
468 |
< |
}, |
469 |
< |
) |
464 |
> |
list.append(Result( |
465 |
> |
{'disk_name': s.disk_name, |
466 |
> |
'read_bytes': s.read_bytes, |
467 |
> |
'write_bytes': s.write_bytes, |
468 |
> |
'systime': s.systime, |
469 |
> |
} |
470 |
> |
)) |
471 |
|
s = s + 1 |
472 |
|
return list |
473 |
|
|
474 |
< |
def py_get_diskio_stats_diff(): |
475 |
< |
cdef diskio_stat_t *s |
474 |
> |
def py_sg_get_disk_io_stats_diff(): |
475 |
> |
cdef sg_disk_io_stats *s |
476 |
|
cdef int entries |
477 |
< |
s = get_diskio_stats_diff(&entries) |
478 |
< |
list = [entries] |
477 |
> |
s = sg_get_disk_io_stats_diff(&entries) |
478 |
> |
if s == NULL: |
479 |
> |
raise StatgrabException, 'sg_get_disk_io_stats_diff() returned NULL' |
480 |
> |
list = [] |
481 |
|
for i from 0 <= i < entries: |
482 |
< |
list.append({'disk_name': s.disk_name, |
483 |
< |
'read_bytes': s.read_bytes, |
484 |
< |
'write_bytes': s.write_bytes, |
485 |
< |
'systime': s.systime, |
486 |
< |
}, |
487 |
< |
) |
482 |
> |
list.append(Result( |
483 |
> |
{'disk_name': s.disk_name, |
484 |
> |
'read_bytes': s.read_bytes, |
485 |
> |
'write_bytes': s.write_bytes, |
486 |
> |
'systime': s.systime, |
487 |
> |
} |
488 |
> |
)) |
489 |
|
s = s + 1 |
490 |
|
return list |
491 |
|
|
492 |
< |
def py_get_process_stats(): |
493 |
< |
cdef process_stat_t *s |
494 |
< |
s = get_process_stats() |
495 |
< |
return {'total': s.total, |
496 |
< |
'running': s.running, |
497 |
< |
'sleeping': s.sleeping, |
498 |
< |
'stopped': s.stopped, |
499 |
< |
'zombie': s.zombie, |
500 |
< |
} |
492 |
> |
def py_sg_get_network_io_stats(): |
493 |
> |
cdef sg_network_io_stats *s |
494 |
> |
cdef int entries |
495 |
> |
s = sg_get_network_io_stats(&entries) |
496 |
> |
if s == NULL: |
497 |
> |
raise StatgrabException, 'sg_get_network_io_stats() returned NULL' |
498 |
> |
list = [] |
499 |
> |
for i from 0 <= i < entries: |
500 |
> |
list.append(Result( |
501 |
> |
{'interface_name': s.interface_name, |
502 |
> |
'tx': s.tx, |
503 |
> |
'rx': s.rx, |
504 |
> |
'ipackets': s.ipackets, |
505 |
> |
'opackets': s.opackets, |
506 |
> |
'ierrors': s.ierrors, |
507 |
> |
'oerrors': s.oerrors, |
508 |
> |
'collisions': s.collisions, |
509 |
> |
'systime': s.systime, |
510 |
> |
} |
511 |
> |
)) |
512 |
> |
s = s + 1 |
513 |
> |
return list |
514 |
|
|
515 |
< |
def py_get_network_stats(): |
516 |
< |
cdef network_stat_t *s |
515 |
> |
def py_sg_get_network_io_stats_diff(): |
516 |
> |
cdef sg_network_io_stats *s |
517 |
|
cdef int entries |
518 |
< |
s = get_network_stats(&entries) |
519 |
< |
list = [entries] |
518 |
> |
s = sg_get_network_io_stats_diff(&entries) |
519 |
> |
if s == NULL: |
520 |
> |
raise StatgrabException, 'sg_get_network_io_stats_diff() returned NULL' |
521 |
> |
list = [] |
522 |
|
for i from 0 <= i < entries: |
523 |
< |
list.append({'interface_name': s.interface_name, |
524 |
< |
'tx': s.tx, |
525 |
< |
'rx': s.rx, |
526 |
< |
'systime': s.systime, |
527 |
< |
}, |
528 |
< |
) |
523 |
> |
list.append(Result( |
524 |
> |
{'interface_name': s.interface_name, |
525 |
> |
'tx': s.tx, |
526 |
> |
'rx': s.rx, |
527 |
> |
'ipackets': s.ipackets, |
528 |
> |
'opackets': s.opackets, |
529 |
> |
'ierrors': s.ierrors, |
530 |
> |
'oerrors': s.oerrors, |
531 |
> |
'collisions': s.collisions, |
532 |
> |
'systime': s.systime, |
533 |
> |
} |
534 |
> |
)) |
535 |
|
s = s + 1 |
536 |
|
return list |
537 |
|
|
538 |
< |
def py_get_network_stats_diff(): |
539 |
< |
cdef network_stat_t *s |
538 |
> |
def py_sg_get_network_iface_stats(): |
539 |
> |
cdef sg_network_iface_stats *s |
540 |
|
cdef int entries |
541 |
< |
s = get_network_stats_diff(&entries) |
542 |
< |
list = [entries] |
541 |
> |
s = sg_get_network_iface_stats(&entries) |
542 |
> |
if s == NULL: |
543 |
> |
raise StatgrabException, 'sg_get_network_iface_stats() returned NULL' |
544 |
> |
list = [] |
545 |
|
for i from 0 <= i < entries: |
546 |
< |
list.append({'interface_name': s.interface_name, |
547 |
< |
'tx': s.tx, |
548 |
< |
'rx': s.rx, |
549 |
< |
'systime': s.systime, |
550 |
< |
}, |
551 |
< |
) |
546 |
> |
list.append(Result( |
547 |
> |
{'interface_name': s.interface_name, |
548 |
> |
'speed': s.speed, |
549 |
> |
'dup': s.dup, |
550 |
> |
'up' : s.up, |
551 |
> |
} |
552 |
> |
)) |
553 |
|
s = s + 1 |
554 |
|
return list |
555 |
|
|
556 |
< |
def py_get_page_stats(): |
557 |
< |
cdef page_stat_t *s |
558 |
< |
s = get_page_stats() |
559 |
< |
return {'pages_pagein': s.pages_pagein, |
560 |
< |
'pages_pageout': s.pages_pageout, |
561 |
< |
} |
556 |
> |
def py_sg_get_page_stats(): |
557 |
> |
cdef sg_page_stats *s |
558 |
> |
s = sg_get_page_stats() |
559 |
> |
if s == NULL: |
560 |
> |
raise StatgrabException, 'sg_get_page_stats() returned NULL' |
561 |
> |
return Result( |
562 |
> |
{'pages_pagein': s.pages_pagein, |
563 |
> |
'pages_pageout': s.pages_pageout, |
564 |
> |
} |
565 |
> |
) |
566 |
|
|
567 |
< |
def py_get_page_stats_diff(): |
568 |
< |
cdef page_stat_t *s |
569 |
< |
s = get_page_stats_diff() |
570 |
< |
return {'pages_pagein': s.pages_pagein, |
571 |
< |
'pages_pageout': s.pages_pageout, |
572 |
< |
} |
567 |
> |
def py_sg_get_page_stats_diff(): |
568 |
> |
cdef sg_page_stats *s |
569 |
> |
s = sg_get_page_stats_diff() |
570 |
> |
if s == NULL: |
571 |
> |
raise StatgrabException, 'sg_get_page_stats_diff() returned NULL' |
572 |
> |
return Result( |
573 |
> |
{'pages_pagein': s.pages_pagein, |
574 |
> |
'pages_pageout': s.pages_pageout, |
575 |
> |
} |
576 |
> |
) |
577 |
|
|
578 |
< |
def py_statgrab_init(): |
579 |
< |
return statgrab_init() |
578 |
> |
def py_sg_get_process_stats(): |
579 |
> |
cdef sg_process_stats *s |
580 |
> |
cdef int entries |
581 |
> |
s = sg_get_process_stats(&entries) |
582 |
> |
if s == NULL: |
583 |
> |
raise StatgrabException, 'sg_get_process_stats() returned NULL' |
584 |
> |
list = [] |
585 |
> |
for i from 0 <= i < entries: |
586 |
> |
if s.process_name == NULL: |
587 |
> |
s.process_name = '' |
588 |
> |
if s.proctitle == NULL: |
589 |
> |
s.proctitle = '' |
590 |
> |
list.append(Result( |
591 |
> |
{'process_name': s.process_name, |
592 |
> |
'proctitle' : s.proctitle, |
593 |
> |
'pid' : s.pid, |
594 |
> |
'parent' : s.parent, |
595 |
> |
'pgid' : s.pgid, |
596 |
> |
'uid' : s.uid, |
597 |
> |
'euid' : s.euid, |
598 |
> |
'gid' : s.gid, |
599 |
> |
'egid' : s.egid, |
600 |
> |
'proc_size' : s.proc_size, |
601 |
> |
'proc_resident' : s.proc_resident, |
602 |
> |
'time_spent' : s.time_spent, |
603 |
> |
'cpu_percent' : s.cpu_percent, |
604 |
> |
'nice' : s.nice, |
605 |
> |
'state' : s.state, |
606 |
> |
} |
607 |
> |
)) |
608 |
> |
s = s + 1 |
609 |
> |
return list |
610 |
|
|
611 |
< |
def py_statgrab_drop_privileges(): |
612 |
< |
return statgrab_drop_privileges() |
611 |
> |
def py_sg_get_process_count(): |
612 |
> |
cdef sg_process_count *s |
613 |
> |
s = sg_get_process_count() |
614 |
> |
if s == NULL: |
615 |
> |
raise StatgrabException, 'sg_get_process_count() returned NULL' |
616 |
> |
return Result( |
617 |
> |
{'total': s.total, |
618 |
> |
'running': s.running, |
619 |
> |
'sleeping': s.sleeping, |
620 |
> |
'stopped': s.stopped, |
621 |
> |
'zombie': s.zombie, |
622 |
> |
} |
623 |
> |
) |