ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/pystatgrab/_statgrab.pyx
(Generate patch)

Comparing projects/pystatgrab/_statgrab.pyx (file contents):
Revision 1.1 by tdb, Fri Feb 6 14:10:08 2004 UTC vs.
Revision 1.19 by tdb, Fri Jul 13 22:19:56 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines