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.2 by tdb, Fri Feb 6 15:12:14 2004 UTC vs.
Revision 1.7 by tdb, Fri Feb 13 17:53:15 2004 UTC

# Line 1 | Line 1
1 < # TODO: deal with failures better (return nothing, or raise error?)
1 > #
2 > # i-scream central monitoring system
3 > # http://www.i-scream.org
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  
# Line 80 | Line 100 | cdef extern from "statgrab.h":
100          long long rx
101          time_t systime
102  
103 +    ctypedef enum statgrab_duplex:
104 +        FULL_DUPLEX
105 +        HALF_DUPLEX
106 +        UNKNOWN_DUPLEX
107 +
108 +    ctypedef struct network_iface_stat_t:
109 +        char *interface_name
110 +        int speed
111 +        statgrab_duplex dup
112 +
113      ctypedef struct page_stat_t:
114          long long pages_pagein
115          long long pages_pageout
# Line 99 | Line 129 | cdef extern from "statgrab.h":
129      cdef extern process_stat_t *get_process_stats()
130      cdef extern network_stat_t *get_network_stats(int *entries)
131      cdef extern network_stat_t *get_network_stats_diff(int *entries)
132 +    cdef extern network_iface_stat_t *get_network_iface_stats(int *entries)
133      cdef extern page_stat_t *get_page_stats()
134      cdef extern page_stat_t *get_page_stats_diff()
135      cdef extern int statgrab_init()
136      cdef extern int statgrab_drop_privileges()
137  
138  
139 + py_FULL_DUPLEX = FULL_DUPLEX
140 + py_HALF_DUPLEX = HALF_DUPLEX
141 + py_UNKNOWN_DUPLEX = UNKNOWN_DUPLEX
142 +
143 +
144   class Result:
145      def __init__(self, attrs):
146          self.attrs = attrs
# Line 115 | Line 151 | class Result:
151      def __repr__(self):
152          return str(self.attrs)
153  
154 + class StatgrabException(Exception):
155 +    def __init__(self, value):
156 +        self.value = value
157 +    def __str__(self):
158 +        return repr(self.value)
159  
160 +
161   def py_get_cpu_totals():
162      cdef cpu_states_t *s
163      s = get_cpu_totals()
164 +    if s == NULL:
165 +        raise StatgrabException, 'get_cpu_totals() returned NULL'
166      return Result(
167          {'user': s.user,
168           'kernel': s.kernel,
# Line 134 | Line 178 | def py_get_cpu_totals():
178   def py_get_cpu_diff():
179      cdef cpu_states_t *s
180      s = get_cpu_diff()
181 +    if s == NULL:
182 +        raise StatgrabException, 'get_cpu_diff() returned NULL'
183      return Result(
184          {'user': s.user,
185           'kernel': s.kernel,
# Line 149 | Line 195 | def py_get_cpu_diff():
195   def py_cpu_percent_usage():
196      cdef cpu_percent_t *s
197      s = cpu_percent_usage()
198 +    if s == NULL:
199 +        raise StatgrabException, 'cpu_percent_usage() returned NULL'
200      return Result(
201          {'user': s.user,
202           'kernel': s.kernel,
# Line 163 | Line 211 | def py_cpu_percent_usage():
211   def py_get_memory_stats():
212      cdef mem_stat_t *s
213      s = get_memory_stats()
214 +    if s == NULL:
215 +        raise StatgrabException, 'get_memory_stats() returned NULL'
216      return Result(
217          {'total': s.total,
218           'used': s.used,
# Line 174 | Line 224 | def py_get_memory_stats():
224   def py_get_load_stats():
225      cdef load_stat_t *s
226      s = get_load_stats()
227 +    if s == NULL:
228 +        raise StatgrabException, 'get_load_stats() returned NULL'
229      return Result(
230          {'min1': s.min1,
231           'min5': s.min5,
# Line 184 | Line 236 | def py_get_load_stats():
236   def py_get_user_stats():
237      cdef user_stat_t *s
238      s = get_user_stats()
239 +    if s == NULL:
240 +        raise StatgrabException, 'get_user_stats() returned NULL'
241      return Result(
242          {'name_list': s.name_list,
243           'num_entries': s.num_entries,
# Line 193 | Line 247 | def py_get_user_stats():
247   def py_get_swap_stats():
248      cdef swap_stat_t *s
249      s = get_swap_stats()
250 +    if s == NULL:
251 +        raise StatgrabException, 'get_swap_stats() returned NULL'
252      return Result(
253          {'total': s.total,
254           'used': s.used,
# Line 203 | Line 259 | def py_get_swap_stats():
259   def py_get_general_stats():
260      cdef general_stat_t *s
261      s = get_general_stats()
262 +    if s == NULL:
263 +        raise StatgrabException, 'get_general_stats() returned NULL'
264      return Result(
265          {'os_name': s.os_name,
266           'os_release': s.os_release,
# Line 217 | Line 275 | def py_get_disk_stats():
275      cdef disk_stat_t *s
276      cdef int entries
277      s = get_disk_stats(&entries)
278 <    list = [entries]
278 >    if s == NULL:
279 >        raise StatgrabException, 'get_disk_stats() returned NULL'
280 >    list = []
281      for i from 0 <= i < entries:
282          list.append(Result(
283              {'device_name': s.device_name,
# Line 238 | Line 298 | def py_get_diskio_stats():
298      cdef diskio_stat_t *s
299      cdef int entries
300      s = get_diskio_stats(&entries)
301 <    list = [entries]
301 >    if s == NULL:
302 >        raise StatgrabException, 'get_diskio_stats() returned NULL'
303 >    list = []
304      for i from 0 <= i < entries:
305          list.append(Result(
306              {'disk_name': s.disk_name,
# Line 254 | Line 316 | def py_get_diskio_stats_diff():
316      cdef diskio_stat_t *s
317      cdef int entries
318      s = get_diskio_stats_diff(&entries)
319 <    list = [entries]
319 >    if s == NULL:
320 >        raise StatgrabException, 'get_diskio_stats_diff() returned NULL'
321 >    list = []
322      for i from 0 <= i < entries:
323          list.append(Result(
324              {'disk_name': s.disk_name,
# Line 269 | Line 333 | def py_get_diskio_stats_diff():
333   def py_get_process_stats():
334      cdef process_stat_t *s
335      s = get_process_stats()
336 +    if s == NULL:
337 +        raise StatgrabException, 'get_process_stats() returned NULL'
338      return Result(
339          {'total': s.total,
340           'running': s.running,
# Line 282 | Line 348 | def py_get_network_stats():
348      cdef network_stat_t *s
349      cdef int entries
350      s = get_network_stats(&entries)
351 <    list = [entries]
351 >    if s == NULL:
352 >        raise StatgrabException, 'get_network_stats() returned NULL'
353 >    list = []
354      for i from 0 <= i < entries:
355          list.append(Result(
356              {'interface_name': s.interface_name,
# Line 298 | Line 366 | def py_get_network_stats_diff():
366      cdef network_stat_t *s
367      cdef int entries
368      s = get_network_stats_diff(&entries)
369 <    list = [entries]
369 >    if s == NULL:
370 >        raise StatgrabException, 'get_network_stats_diff() returned NULL'
371 >    list = []
372      for i from 0 <= i < entries:
373          list.append(Result(
374              {'interface_name': s.interface_name,
# Line 310 | Line 380 | def py_get_network_stats_diff():
380          s = s + 1
381      return list
382  
383 + def py_get_network_iface_stats():
384 +    cdef network_iface_stat_t *s
385 +    cdef int entries
386 +    s = get_network_iface_stats(&entries)
387 +    if s == NULL:
388 +        raise StatgrabException, 'get_network_iface_stats() returned NULL'
389 +    list = []
390 +    for i from 0 <= i < entries:
391 +        list.append(Result(
392 +            {'interface_name': s.interface_name,
393 +             'speed': s.speed,
394 +             'dup': s.dup,
395 +            }
396 +        ))
397 +        s = s + 1
398 +    return list
399 +
400   def py_get_page_stats():
401      cdef page_stat_t *s
402      s = get_page_stats()
403 +    if s == NULL:
404 +        raise StatgrabException, 'get_page_stats() returned NULL'
405      return Result(
406          {'pages_pagein': s.pages_pagein,
407           'pages_pageout': s.pages_pageout,
# Line 322 | Line 411 | def py_get_page_stats():
411   def py_get_page_stats_diff():
412      cdef page_stat_t *s
413      s = get_page_stats_diff()
414 +    if s == NULL:
415 +        raise StatgrabException, 'get_page_stats_diff() returned NULL'
416      return Result(
417          {'pages_pagein': s.pages_pagein,
418           'pages_pageout': s.pages_pageout,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines