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.4 by tdb, Tue Feb 10 20:25:54 2004 UTC vs.
Revision 1.20 by tdb, Fri Jul 13 22:26:19 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines