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.11 by tdb, Tue Apr 6 14:53:01 2004 UTC vs.
Revision 1.17 by tdb, Sat Jul 30 18:16:14 2005 UTC

# Line 1 | Line 1
1   #
2   # i-scream pystatgrab
3 < # http://www.i-scream.org
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_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 33 | 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 42 | 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:
66 <        char *os_name
67 <        char *os_release
68 <        char *os_version
69 <        char *platform
70 <        char *hostname
71 <        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 80 | 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
92 <        int running
93 <        int sleeping
94 <        int stopped
95 <        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
# Line 105 | Line 170 | cdef extern from "statgrab.h":
170          long long collisions
171          time_t systime
172  
173 <    ctypedef enum statgrab_duplex:
174 <        FULL_DUPLEX
110 <        HALF_DUPLEX
111 <        UNKNOWN_DUPLEX
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 struct network_iface_stat_t:
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 <        statgrab_duplex dup
184 >        sg_iface_duplex duplex
185          int up
186  
187 <    ctypedef struct page_stat_t:
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()
126 <    cdef extern cpu_percent_t *cpu_percent_usage()
127 <    cdef extern mem_stat_t *get_memory_stats()
128 <    cdef extern load_stat_t *get_load_stats()
129 <    cdef extern user_stat_t *get_user_stats()
130 <    cdef extern swap_stat_t *get_swap_stats()
131 <    cdef extern general_stat_t *get_general_stats()
132 <    cdef extern disk_stat_t *get_disk_stats(int *entries)
133 <    cdef extern diskio_stat_t *get_diskio_stats(int *entries)
134 <    cdef extern diskio_stat_t *get_diskio_stats_diff(int *entries)
135 <    cdef extern process_stat_t *get_process_stats()
136 <    cdef extern network_stat_t *get_network_stats(int *entries)
137 <    cdef extern network_stat_t *get_network_stats_diff(int *entries)
138 <    cdef extern network_iface_stat_t *get_network_iface_stats(int *entries)
139 <    cdef extern page_stat_t *get_page_stats()
140 <    cdef extern page_stat_t *get_page_stats_diff()
141 <    cdef extern int statgrab_init()
142 <    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 < py_FULL_DUPLEX = FULL_DUPLEX
205 < py_HALF_DUPLEX = HALF_DUPLEX
206 < py_UNKNOWN_DUPLEX = UNKNOWN_DUPLEX
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 +    cdef extern sg_process_stats *sg_get_process_stats(int *entries)
222  
223 +    ctypedef struct sg_process_count:
224 +        int total
225 +        int running
226 +        int sleeping
227 +        int stopped
228 +        int zombie
229 +
230 +    cdef extern sg_process_count *sg_get_process_count()
231 +
232 +
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 + 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 + 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 +
275   class Result:
276      def __init__(self, attrs):
277          self.attrs = attrs
# Line 164 | Line 289 | class StatgrabException(Exception):
289          return repr(self.value)
290  
291  
292 < def py_get_cpu_totals():
293 <    cdef cpu_states_t *s
294 <    s = get_cpu_totals()
292 > def py_sg_init():
293 >    if sg_init() == 0:
294 >        return True
295 >    else:
296 >        return False
297 >
298 > def py_sg_drop_privileges():
299 >    if sg_drop_privileges() == 0:
300 >        return True
301 >    else:
302 >        return False
303 >
304 > def py_sg_set_error(code, arg):
305 >    sg_set_error(code, arg)
306 >
307 > def py_sg_set_error_with_errno(code, arg):
308 >    sg_set_error_with_errno(code, arg)
309 >
310 > def py_sg_get_error():
311 >    cdef sg_error s
312 >    s = sg_get_error()
313 >    return s
314 >
315 > def py_sg_get_error_arg():
316 >    s = sg_get_error_arg()
317 >    return s
318 >
319 > def py_sg_get_error_errno():
320 >    s = sg_get_error_errno()
321 >    return s
322 >
323 > def py_sg_str_error(code):
324 >    s = sg_str_error(code)
325 >    return s
326 >
327 > def py_sg_get_host_info():
328 >    cdef sg_host_info *s
329 >    s = sg_get_host_info()
330      if s == NULL:
331 <        raise StatgrabException, 'get_cpu_totals() returned NULL'
331 >        raise StatgrabException, 'sg_get_host_info() returned NULL'
332      return Result(
333 +        {'os_name': s.os_name,
334 +         'os_release': s.os_release,
335 +         'os_version': s.os_version,
336 +         'platform': s.platform,
337 +         'hostname': s.hostname,
338 +         'uptime': s.uptime,
339 +        }
340 +    )
341 +
342 + def py_sg_get_cpu_stats():
343 +    cdef sg_cpu_stats *s
344 +    s = sg_get_cpu_stats()
345 +    if s == NULL:
346 +        raise StatgrabException, 'sg_get_cpu_stats() returned NULL'
347 +    return Result(
348          {'user': s.user,
349           'kernel': s.kernel,
350           'idle': s.idle,
# Line 181 | Line 356 | def py_get_cpu_totals():
356          }
357      )
358  
359 < def py_get_cpu_diff():
360 <    cdef cpu_states_t *s
361 <    s = get_cpu_diff()
359 > def py_sg_get_cpu_stats_diff():
360 >    cdef sg_cpu_stats *s
361 >    s = sg_get_cpu_stats_diff()
362      if s == NULL:
363 <        raise StatgrabException, 'get_cpu_diff() returned NULL'
363 >        raise StatgrabException, 'sg_get_cpu_stats_diff() returned NULL'
364      return Result(
365          {'user': s.user,
366           'kernel': s.kernel,
# Line 198 | Line 373 | def py_get_cpu_diff():
373          }
374      )
375  
376 < def py_cpu_percent_usage():
377 <    cdef cpu_percent_t *s
378 <    s = cpu_percent_usage()
376 > def py_sg_get_cpu_percents():
377 >    cdef sg_cpu_percents *s
378 >    s = sg_get_cpu_percents()
379      if s == NULL:
380 <        raise StatgrabException, 'cpu_percent_usage() returned NULL'
380 >        raise StatgrabException, 'sg_get_cpu_percents() returned NULL'
381      return Result(
382          {'user': s.user,
383           'kernel': s.kernel,
# Line 214 | Line 389 | def py_cpu_percent_usage():
389          }
390      )
391  
392 < def py_get_memory_stats():
393 <    cdef mem_stat_t *s
394 <    s = get_memory_stats()
392 > def py_sg_get_mem_stats():
393 >    cdef sg_mem_stats *s
394 >    s = sg_get_mem_stats()
395      if s == NULL:
396 <        raise StatgrabException, 'get_memory_stats() returned NULL'
396 >        raise StatgrabException, 'sg_get_mem_stats() returned NULL'
397      return Result(
398          {'total': s.total,
399           'used': s.used,
# Line 227 | Line 402 | def py_get_memory_stats():
402          }
403      )
404  
405 < def py_get_load_stats():
406 <    cdef load_stat_t *s
407 <    s = get_load_stats()
405 > def py_sg_get_load_stats():
406 >    cdef sg_load_stats *s
407 >    s = sg_get_load_stats()
408      if s == NULL:
409 <        raise StatgrabException, 'get_load_stats() returned NULL'
409 >        raise StatgrabException, 'sg_get_load_stats() returned NULL'
410      return Result(
411          {'min1': s.min1,
412           'min5': s.min5,
# Line 239 | Line 414 | def py_get_load_stats():
414          }
415      )
416  
417 < def py_get_user_stats():
418 <    cdef user_stat_t *s
419 <    s = get_user_stats()
417 > def py_sg_get_user_stats():
418 >    cdef sg_user_stats *s
419 >    s = sg_get_user_stats()
420      if s == NULL:
421 <        raise StatgrabException, 'get_user_stats() returned NULL'
421 >        raise StatgrabException, 'sg_get_user_stats() returned NULL'
422      return Result(
423          {'name_list': s.name_list,
424           'num_entries': s.num_entries,
425          }
426      )
427  
428 < def py_get_swap_stats():
429 <    cdef swap_stat_t *s
430 <    s = get_swap_stats()
428 > def py_sg_get_swap_stats():
429 >    cdef sg_swap_stats *s
430 >    s = sg_get_swap_stats()
431      if s == NULL:
432 <        raise StatgrabException, 'get_swap_stats() returned NULL'
432 >        raise StatgrabException, 'sg_get_swap_stats() returned NULL'
433      return Result(
434          {'total': s.total,
435           'used': s.used,
# Line 262 | Line 437 | def py_get_swap_stats():
437          }
438      )
439  
440 < def py_get_general_stats():
441 <    cdef general_stat_t *s
267 <    s = get_general_stats()
268 <    if s == NULL:
269 <        raise StatgrabException, 'get_general_stats() returned NULL'
270 <    return Result(
271 <        {'os_name': s.os_name,
272 <         'os_release': s.os_release,
273 <         'os_version': s.os_version,
274 <         'platform': s.platform,
275 <         'hostname': s.hostname,
276 <         'uptime': s.uptime,
277 <        }
278 <    )
279 <
280 < def py_get_disk_stats():
281 <    cdef disk_stat_t *s
440 > def py_sg_get_fs_stats():
441 >    cdef sg_fs_stats *s
442      cdef int entries
443 <    s = get_disk_stats(&entries)
443 >    s = sg_get_fs_stats(&entries)
444      if s == NULL:
445 <        raise StatgrabException, 'get_disk_stats() returned NULL'
445 >        raise StatgrabException, 'sg_get_fs_stats() returned NULL'
446      list = []
447      for i from 0 <= i < entries:
448          list.append(Result(
# Line 295 | Line 455 | def py_get_disk_stats():
455               'total_inodes': s.total_inodes,
456               'used_inodes': s.used_inodes,
457               'free_inodes': s.free_inodes,
458 +             'avail_inodes': s.avail_inodes,
459 +             'io_size': s.io_size,
460 +             'block_size': s.block_size,
461 +             'total_blocks': s.total_blocks,
462 +             'free_blocks': s.free_blocks,
463 +             'used_blocks': s.used_blocks,
464 +             'avail_blocks': s.avail_blocks,
465              }
466          ))
467          s = s + 1
468      return list
469  
470 < def py_get_diskio_stats():
471 <    cdef diskio_stat_t *s
470 > def py_sg_get_disk_io_stats():
471 >    cdef sg_disk_io_stats *s
472      cdef int entries
473 <    s = get_diskio_stats(&entries)
473 >    s = sg_get_disk_io_stats(&entries)
474      if s == NULL:
475 <        raise StatgrabException, 'get_diskio_stats() returned NULL'
475 >        raise StatgrabException, 'sg_get_disk_io_stats() returned NULL'
476      list = []
477      for i from 0 <= i < entries:
478          list.append(Result(
# Line 318 | Line 485 | def py_get_diskio_stats():
485          s = s + 1
486      return list
487  
488 < def py_get_diskio_stats_diff():
489 <    cdef diskio_stat_t *s
488 > def py_sg_get_disk_io_stats_diff():
489 >    cdef sg_disk_io_stats *s
490      cdef int entries
491 <    s = get_diskio_stats_diff(&entries)
491 >    s = sg_get_disk_io_stats_diff(&entries)
492      if s == NULL:
493 <        raise StatgrabException, 'get_diskio_stats_diff() returned NULL'
493 >        raise StatgrabException, 'sg_get_disk_io_stats_diff() returned NULL'
494      list = []
495      for i from 0 <= i < entries:
496          list.append(Result(
# Line 336 | Line 503 | def py_get_diskio_stats_diff():
503          s = s + 1
504      return list
505  
506 < def py_get_process_stats():
507 <    cdef process_stat_t *s
341 <    s = get_process_stats()
342 <    if s == NULL:
343 <        raise StatgrabException, 'get_process_stats() returned NULL'
344 <    return Result(
345 <        {'total': s.total,
346 <         'running': s.running,
347 <         'sleeping': s.sleeping,
348 <         'stopped': s.stopped,
349 <         'zombie': s.zombie,
350 <        }
351 <    )
352 <
353 < def py_get_network_stats():
354 <    cdef network_stat_t *s
506 > def py_sg_get_network_io_stats():
507 >    cdef sg_network_io_stats *s
508      cdef int entries
509 <    s = get_network_stats(&entries)
509 >    s = sg_get_network_io_stats(&entries)
510      if s == NULL:
511 <        raise StatgrabException, 'get_network_stats() returned NULL'
511 >        raise StatgrabException, 'sg_get_network_io_stats() returned NULL'
512      list = []
513      for i from 0 <= i < entries:
514          list.append(Result(
# Line 373 | Line 526 | def py_get_network_stats():
526          s = s + 1
527      return list
528  
529 < def py_get_network_stats_diff():
530 <    cdef network_stat_t *s
529 > def py_sg_get_network_io_stats_diff():
530 >    cdef sg_network_io_stats *s
531      cdef int entries
532 <    s = get_network_stats_diff(&entries)
532 >    s = sg_get_network_io_stats_diff(&entries)
533      if s == NULL:
534 <        raise StatgrabException, 'get_network_stats_diff() returned NULL'
534 >        raise StatgrabException, 'sg_get_network_io_stats_diff() returned NULL'
535      list = []
536      for i from 0 <= i < entries:
537          list.append(Result(
# Line 396 | Line 549 | def py_get_network_stats_diff():
549          s = s + 1
550      return list
551  
552 < def py_get_network_iface_stats():
553 <    cdef network_iface_stat_t *s
552 > def py_sg_get_network_iface_stats():
553 >    cdef sg_network_iface_stats *s
554      cdef int entries
555 <    s = get_network_iface_stats(&entries)
555 >    s = sg_get_network_iface_stats(&entries)
556      if s == NULL:
557 <        raise StatgrabException, 'get_network_iface_stats() returned NULL'
557 >        raise StatgrabException, 'sg_get_network_iface_stats() returned NULL'
558      list = []
559      for i from 0 <= i < entries:
560          list.append(Result(
561              {'interface_name': s.interface_name,
562               'speed': s.speed,
563 <             'dup': s.dup,
563 >             'duplex': s.duplex,
564               'up' : s.up,
565              }
566          ))
567          s = s + 1
568      return list
569  
570 < def py_get_page_stats():
571 <    cdef page_stat_t *s
572 <    s = get_page_stats()
570 > def py_sg_get_page_stats():
571 >    cdef sg_page_stats *s
572 >    s = sg_get_page_stats()
573      if s == NULL:
574 <        raise StatgrabException, 'get_page_stats() returned NULL'
574 >        raise StatgrabException, 'sg_get_page_stats() returned NULL'
575      return Result(
576          {'pages_pagein': s.pages_pagein,
577           'pages_pageout': s.pages_pageout,
578          }
579      )
580  
581 < def py_get_page_stats_diff():
582 <    cdef page_stat_t *s
583 <    s = get_page_stats_diff()
581 > def py_sg_get_page_stats_diff():
582 >    cdef sg_page_stats *s
583 >    s = sg_get_page_stats_diff()
584      if s == NULL:
585 <        raise StatgrabException, 'get_page_stats_diff() returned NULL'
585 >        raise StatgrabException, 'sg_get_page_stats_diff() returned NULL'
586      return Result(
587          {'pages_pagein': s.pages_pagein,
588           'pages_pageout': s.pages_pageout,
589          }
590      )
591  
592 < def py_statgrab_init():
593 <    if statgrab_init() == 0:
594 <        return True
595 <    else:
596 <        return False
592 > def py_sg_get_process_stats():
593 >    cdef sg_process_stats *s
594 >    cdef int entries
595 >    s = sg_get_process_stats(&entries)
596 >    if s == NULL:
597 >        raise StatgrabException, 'sg_get_process_stats() returned NULL'
598 >    list = []
599 >    for i from 0 <= i < entries:
600 >        if s.process_name == NULL:
601 >            s.process_name = ''
602 >        if s.proctitle == NULL:
603 >            s.proctitle = ''
604 >        list.append(Result(
605 >            {'process_name': s.process_name,
606 >             'proctitle' : s.proctitle,
607 >             'pid' : s.pid,
608 >             'parent' : s.parent,
609 >             'pgid' : s.pgid,
610 >             'uid' : s.uid,
611 >             'euid' : s.euid,
612 >             'gid' : s.gid,
613 >             'egid' : s.egid,
614 >             'proc_size' : s.proc_size,
615 >             'proc_resident' : s.proc_resident,
616 >             'time_spent' : s.time_spent,
617 >             'cpu_percent' : s.cpu_percent,
618 >             'nice' : s.nice,
619 >             'state' : s.state,
620 >            }
621 >        ))
622 >        s = s + 1
623 >    return list
624  
625 < def py_statgrab_drop_privileges():
626 <    if statgrab_drop_privileges() == 0:
627 <        return True
628 <    else:
629 <        return False
625 > def py_sg_get_process_count():
626 >    cdef sg_process_count *s
627 >    s = sg_get_process_count()
628 >    if s == NULL:
629 >        raise StatgrabException, 'sg_get_process_count() returned NULL'
630 >    return Result(
631 >        {'total': s.total,
632 >         'running': s.running,
633 >         'sleeping': s.sleeping,
634 >         'stopped': s.stopped,
635 >         'zombie': s.zombie,
636 >        }
637 >    )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines