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.12 by tdb, Sun May 30 15:21:19 2004 UTC vs.
Revision 1.13 by tdb, Sun May 30 15:32:28 2004 UTC

# Line 23 | Line 23
23   ctypedef long time_t
24  
25   cdef extern from "statgrab.h":
26 +    cdef extern int sg_init()
27 +    cdef extern int sg_drop_privileges()
28 +
29 +    ctypedef struct sg_host_info:
30 +        char *os_name
31 +        char *os_release
32 +        char *os_version
33 +        char *platform
34 +        char *hostname
35 +        time_t uptime
36 +
37 +    cdef extern sg_host_info *sg_get_host_info()
38 +
39      ctypedef struct sg_cpu_stats:
40          long long user
41          long long kernel
# Line 33 | Line 46 | cdef extern from "statgrab.h":
46          long long total
47          time_t systime
48  
49 +    cdef extern sg_cpu_stats *sg_get_cpu_stats()
50 +    cdef extern sg_cpu_stats *sg_get_cpu_stats_diff()
51 +
52      ctypedef struct sg_cpu_percents:
53          float user
54          float kernel
# Line 42 | Line 58 | cdef extern from "statgrab.h":
58          float nice
59          time_t time_taken
60  
61 +    cdef extern sg_cpu_percents *sg_get_cpu_percents()
62 +
63      ctypedef struct sg_mem_stats:
64          long long total
65          long long free
66          long long used
67          long long cache
68  
69 +    cdef extern sg_mem_stats *sg_get_mem_stats()
70 +
71      ctypedef struct sg_load_stats:
72          double min1
73          double min5
74          double min15
75  
76 +    cdef extern sg_load_stats *sg_get_load_stats()
77 +
78      ctypedef struct sg_user_stats:
79          char *name_list
80          int num_entries
81  
82 +    cdef extern sg_user_stats *sg_get_user_stats()
83 +
84      ctypedef struct sg_swap_stats:
85          long long total
86          long long used
87          long long free
88  
89 <    ctypedef struct sg_host_info:
66 <        char *os_name
67 <        char *os_release
68 <        char *os_version
69 <        char *platform
70 <        char *hostname
71 <        time_t uptime
89 >    cdef extern sg_swap_stats *sg_get_swap_stats()
90  
91      ctypedef struct sg_fs_stats:
92          char *device_name
# Line 81 | Line 99 | cdef extern from "statgrab.h":
99          long long used_inodes
100          long long free_inodes
101  
102 +    cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
103 +
104      ctypedef struct sg_disk_io_stats:
105          char *disk_name
106          long long read_bytes
107          long long write_bytes
108          time_t systime
109  
110 <    ctypedef struct sg_process_count:
111 <        int total
92 <        int running
93 <        int sleeping
94 <        int stopped
95 <        int zombie
110 >    cdef extern sg_disk_io_stats *sg_get_disk_io_stats(int *entries)
111 >    cdef extern sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries)
112  
113      ctypedef struct sg_network_io_stats:
114          char *interface_name
# Line 105 | Line 121 | cdef extern from "statgrab.h":
121          long long collisions
122          time_t systime
123  
124 +    cdef extern sg_network_io_stats *sg_get_network_io_stats(int *entries)
125 +    cdef extern sg_network_io_stats *sg_get_network_io_stats_diff(int *entries)
126 +
127      ctypedef enum sg_iface_duplex:
128          SG_IFACE_DUPLEX_FULL
129          SG_IFACE_DUPLEX_HALF
# Line 116 | Line 135 | cdef extern from "statgrab.h":
135          sg_iface_duplex dup
136          int up
137  
138 +    cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries)
139 +
140      ctypedef struct sg_page_stats:
141          long long pages_pagein
142          long long pages_pageout
143          time_t systime
144  
124    cdef extern sg_cpu_stats *sg_get_cpu_stats()
125    cdef extern sg_cpu_stats *sg_get_cpu_stats_diff()
126    cdef extern sg_cpu_percents *sg_get_cpu_percents()
127    cdef extern sg_mem_stats *sg_get_mem_stats()
128    cdef extern sg_load_stats *sg_get_load_stats()
129    cdef extern sg_user_stats *sg_get_user_stats()
130    cdef extern sg_swap_stats *sg_get_swap_stats()
131    cdef extern sg_host_info *sg_get_host_info()
132    cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
133    cdef extern sg_disk_io_stats *sg_get_disk_io_stats(int *entries)
134    cdef extern sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries)
135    cdef extern sg_process_count *sg_get_process_count()
136    cdef extern sg_network_io_stats *sg_get_network_io_stats(int *entries)
137    cdef extern sg_network_io_stats *sg_get_network_io_stats_diff(int *entries)
138    cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries)
145      cdef extern sg_page_stats *sg_get_page_stats()
146      cdef extern sg_page_stats *sg_get_page_stats_diff()
141    cdef extern int sg_init()
142    cdef extern int sg_drop_privileges()
147  
148 +    ctypedef struct sg_process_count:
149 +        int total
150 +        int running
151 +        int sleeping
152 +        int stopped
153 +        int zombie
154  
155 +    cdef extern sg_process_count *sg_get_process_count()
156 +
157 +
158   py_SG_IFACE_DUPLEX_FULL = SG_IFACE_DUPLEX_FULL
159   py_SG_IFACE_DUPLEX_HALF = SG_IFACE_DUPLEX_HALF
160   py_SG_IFACE_DUPLEX_UNKNOWN = SG_IFACE_DUPLEX_UNKNOWN
# Line 164 | Line 177 | class StatgrabException(Exception):
177          return repr(self.value)
178  
179  
180 + def py_sg_init():
181 +    if sg_init() == 0:
182 +        return True
183 +    else:
184 +        return False
185 +
186 + def py_sg_drop_privileges():
187 +    if sg_drop_privileges() == 0:
188 +        return True
189 +    else:
190 +        return False
191 +
192 + def py_sg_get_host_info():
193 +    cdef sg_host_info *s
194 +    s = sg_get_host_info()
195 +    if s == NULL:
196 +        raise StatgrabException, 'sg_get_host_info() returned NULL'
197 +    return Result(
198 +        {'os_name': s.os_name,
199 +         'os_release': s.os_release,
200 +         'os_version': s.os_version,
201 +         'platform': s.platform,
202 +         'hostname': s.hostname,
203 +         'uptime': s.uptime,
204 +        }
205 +    )
206 +
207   def py_sg_get_cpu_stats():
208      cdef sg_cpu_stats *s
209      s = sg_get_cpu_stats()
# Line 262 | Line 302 | def py_sg_get_swap_stats():
302          }
303      )
304  
265 def py_sg_get_host_info():
266    cdef sg_host_info *s
267    s = sg_get_host_info()
268    if s == NULL:
269        raise StatgrabException, 'sg_get_host_info() 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
305   def py_sg_get_fs_stats():
306      cdef sg_fs_stats *s
307      cdef int entries
# Line 336 | Line 361 | def py_sg_get_disk_io_stats_diff():
361          s = s + 1
362      return list
363  
339 def py_sg_get_process_count():
340    cdef sg_process_count *s
341    s = sg_get_process_count()
342    if s == NULL:
343        raise StatgrabException, 'sg_get_process_count() 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
364   def py_sg_get_network_io_stats():
365      cdef sg_network_io_stats *s
366      cdef int entries
# Line 436 | Line 447 | def py_sg_get_page_stats_diff():
447          }
448      )
449  
450 < def py_sg_init():
451 <    if sg_init() == 0:
452 <        return True
453 <    else:
454 <        return False
455 <
456 < def py_sg_drop_privileges():
457 <    if sg_drop_privileges() == 0:
458 <        return True
459 <    else:
460 <        return False
450 > def py_sg_get_process_count():
451 >    cdef sg_process_count *s
452 >    s = sg_get_process_count()
453 >    if s == NULL:
454 >        raise StatgrabException, 'sg_get_process_count() returned NULL'
455 >    return Result(
456 >        {'total': s.total,
457 >         'running': s.running,
458 >         'sleeping': s.sleeping,
459 >         'stopped': s.stopped,
460 >         'zombie': s.zombie,
461 >        }
462 >    )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines