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

Comparing projects/libstatgrab/extras/python/statgrab.pyx (file contents):
Revision 1.2 by tdb, Fri Feb 6 15:12:14 2004 UTC vs.
Revision 1.6 by tdb, Fri Feb 13 12:03:29 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 duplex:
104 +        FULL_DUPLEX
105 +        HALF_DUPLEX
106 +        NO_DUPLEX
107 +
108 +    ctypedef struct network_iface_stat_t:
109 +        char *interface_name
110 +        int speed
111 +        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()
# Line 115 | Line 146 | class Result:
146      def __repr__(self):
147          return str(self.attrs)
148  
149 + class StatgrabException(Exception):
150 +    def __init__(self, value):
151 +        self.value = value
152 +    def __str__(self):
153 +        return repr(self.value)
154  
155 +
156   def py_get_cpu_totals():
157      cdef cpu_states_t *s
158      s = get_cpu_totals()
159 +    if s == NULL:
160 +        raise StatgrabException, 'get_cpu_totals() returned NULL'
161      return Result(
162          {'user': s.user,
163           'kernel': s.kernel,
# Line 134 | Line 173 | def py_get_cpu_totals():
173   def py_get_cpu_diff():
174      cdef cpu_states_t *s
175      s = get_cpu_diff()
176 +    if s == NULL:
177 +        raise StatgrabException, 'get_cpu_diff() returned NULL'
178      return Result(
179          {'user': s.user,
180           'kernel': s.kernel,
# Line 149 | Line 190 | def py_get_cpu_diff():
190   def py_cpu_percent_usage():
191      cdef cpu_percent_t *s
192      s = cpu_percent_usage()
193 +    if s == NULL:
194 +        raise StatgrabException, 'cpu_percent_usage() returned NULL'
195      return Result(
196          {'user': s.user,
197           'kernel': s.kernel,
# Line 163 | Line 206 | def py_cpu_percent_usage():
206   def py_get_memory_stats():
207      cdef mem_stat_t *s
208      s = get_memory_stats()
209 +    if s == NULL:
210 +        raise StatgrabException, 'get_memory_stats() returned NULL'
211      return Result(
212          {'total': s.total,
213           'used': s.used,
# Line 174 | Line 219 | def py_get_memory_stats():
219   def py_get_load_stats():
220      cdef load_stat_t *s
221      s = get_load_stats()
222 +    if s == NULL:
223 +        raise StatgrabException, 'get_load_stats() returned NULL'
224      return Result(
225          {'min1': s.min1,
226           'min5': s.min5,
# Line 184 | Line 231 | def py_get_load_stats():
231   def py_get_user_stats():
232      cdef user_stat_t *s
233      s = get_user_stats()
234 +    if s == NULL:
235 +        raise StatgrabException, 'get_user_stats() returned NULL'
236      return Result(
237          {'name_list': s.name_list,
238           'num_entries': s.num_entries,
# Line 193 | Line 242 | def py_get_user_stats():
242   def py_get_swap_stats():
243      cdef swap_stat_t *s
244      s = get_swap_stats()
245 +    if s == NULL:
246 +        raise StatgrabException, 'get_swap_stats() returned NULL'
247      return Result(
248          {'total': s.total,
249           'used': s.used,
# Line 203 | Line 254 | def py_get_swap_stats():
254   def py_get_general_stats():
255      cdef general_stat_t *s
256      s = get_general_stats()
257 +    if s == NULL:
258 +        raise StatgrabException, 'get_general_stats() returned NULL'
259      return Result(
260          {'os_name': s.os_name,
261           'os_release': s.os_release,
# Line 217 | Line 270 | def py_get_disk_stats():
270      cdef disk_stat_t *s
271      cdef int entries
272      s = get_disk_stats(&entries)
273 <    list = [entries]
273 >    if s == NULL:
274 >        raise StatgrabException, 'get_disk_stats() returned NULL'
275 >    list = []
276      for i from 0 <= i < entries:
277          list.append(Result(
278              {'device_name': s.device_name,
# Line 238 | Line 293 | def py_get_diskio_stats():
293      cdef diskio_stat_t *s
294      cdef int entries
295      s = get_diskio_stats(&entries)
296 <    list = [entries]
296 >    if s == NULL:
297 >        raise StatgrabException, 'get_diskio_stats() returned NULL'
298 >    list = []
299      for i from 0 <= i < entries:
300          list.append(Result(
301              {'disk_name': s.disk_name,
# Line 254 | Line 311 | def py_get_diskio_stats_diff():
311      cdef diskio_stat_t *s
312      cdef int entries
313      s = get_diskio_stats_diff(&entries)
314 <    list = [entries]
314 >    if s == NULL:
315 >        raise StatgrabException, 'get_diskio_stats_diff() returned NULL'
316 >    list = []
317      for i from 0 <= i < entries:
318          list.append(Result(
319              {'disk_name': s.disk_name,
# Line 269 | Line 328 | def py_get_diskio_stats_diff():
328   def py_get_process_stats():
329      cdef process_stat_t *s
330      s = get_process_stats()
331 +    if s == NULL:
332 +        raise StatgrabException, 'get_process_stats() returned NULL'
333      return Result(
334          {'total': s.total,
335           'running': s.running,
# Line 282 | Line 343 | def py_get_network_stats():
343      cdef network_stat_t *s
344      cdef int entries
345      s = get_network_stats(&entries)
346 <    list = [entries]
346 >    if s == NULL:
347 >        raise StatgrabException, 'get_network_stats() returned NULL'
348 >    list = []
349      for i from 0 <= i < entries:
350          list.append(Result(
351              {'interface_name': s.interface_name,
# Line 298 | Line 361 | def py_get_network_stats_diff():
361      cdef network_stat_t *s
362      cdef int entries
363      s = get_network_stats_diff(&entries)
364 <    list = [entries]
364 >    if s == NULL:
365 >        raise StatgrabException, 'get_network_stats_diff() returned NULL'
366 >    list = []
367      for i from 0 <= i < entries:
368          list.append(Result(
369              {'interface_name': s.interface_name,
# Line 310 | Line 375 | def py_get_network_stats_diff():
375          s = s + 1
376      return list
377  
378 + def py_get_network_iface_stats():
379 +    cdef network_iface_stat_t *s
380 +    cdef int entries
381 +    s = get_network_iface_stats(&entries)
382 +    if s == NULL:
383 +        raise StatgrabException, 'get_network_iface_stats() returned NULL'
384 +    list = []
385 +    for i from 0 <= i < entries:
386 +        list.append(Result(
387 +            {'interface_name': s.interface_name,
388 +             'speed': s.speed,
389 +             'dup': s.dup,
390 +            }
391 +        ))
392 +        s = s + 1
393 +    return list
394 +
395   def py_get_page_stats():
396      cdef page_stat_t *s
397      s = get_page_stats()
398 +    if s == NULL:
399 +        raise StatgrabException, 'get_page_stats() returned NULL'
400      return Result(
401          {'pages_pagein': s.pages_pagein,
402           'pages_pageout': s.pages_pageout,
# Line 322 | Line 406 | def py_get_page_stats():
406   def py_get_page_stats_diff():
407      cdef page_stat_t *s
408      s = get_page_stats_diff()
409 +    if s == NULL:
410 +        raise StatgrabException, 'get_page_stats_diff() returned NULL'
411      return Result(
412          {'pages_pagein': s.pages_pagein,
413           'pages_pageout': s.pages_pageout,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines