--- projects/pystatgrab/_statgrab.pyx 2004/02/10 20:25:54 1.4 +++ projects/pystatgrab/_statgrab.pyx 2004/04/06 14:53:01 1.11 @@ -1,5 +1,5 @@ # -# i-scream central monitoring system +# i-scream pystatgrab # http://www.i-scream.org # Copyright (C) 2000-2004 i-scream # @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# $Id: _statgrab.pyx,v 1.4 2004/02/10 20:25:54 tdb Exp $ +# $Id: _statgrab.pyx,v 1.11 2004/04/06 14:53:01 tdb Exp $ # ctypedef long time_t @@ -98,8 +98,24 @@ cdef extern from "statgrab.h": char *interface_name long long tx long long rx + long long ipackets + long long opackets + long long ierrors + long long oerrors + long long collisions time_t systime + ctypedef enum statgrab_duplex: + FULL_DUPLEX + HALF_DUPLEX + UNKNOWN_DUPLEX + + ctypedef struct network_iface_stat_t: + char *interface_name + int speed + statgrab_duplex dup + int up + ctypedef struct page_stat_t: long long pages_pagein long long pages_pageout @@ -119,12 +135,18 @@ cdef extern from "statgrab.h": cdef extern process_stat_t *get_process_stats() cdef extern network_stat_t *get_network_stats(int *entries) cdef extern network_stat_t *get_network_stats_diff(int *entries) + cdef extern network_iface_stat_t *get_network_iface_stats(int *entries) cdef extern page_stat_t *get_page_stats() cdef extern page_stat_t *get_page_stats_diff() cdef extern int statgrab_init() cdef extern int statgrab_drop_privileges() +py_FULL_DUPLEX = FULL_DUPLEX +py_HALF_DUPLEX = HALF_DUPLEX +py_UNKNOWN_DUPLEX = UNKNOWN_DUPLEX + + class Result: def __init__(self, attrs): self.attrs = attrs @@ -261,7 +283,7 @@ def py_get_disk_stats(): s = get_disk_stats(&entries) if s == NULL: raise StatgrabException, 'get_disk_stats() returned NULL' - list = [entries] + list = [] for i from 0 <= i < entries: list.append(Result( {'device_name': s.device_name, @@ -284,7 +306,7 @@ def py_get_diskio_stats(): s = get_diskio_stats(&entries) if s == NULL: raise StatgrabException, 'get_diskio_stats() returned NULL' - list = [entries] + list = [] for i from 0 <= i < entries: list.append(Result( {'disk_name': s.disk_name, @@ -302,7 +324,7 @@ def py_get_diskio_stats_diff(): s = get_diskio_stats_diff(&entries) if s == NULL: raise StatgrabException, 'get_diskio_stats_diff() returned NULL' - list = [entries] + list = [] for i from 0 <= i < entries: list.append(Result( {'disk_name': s.disk_name, @@ -334,12 +356,17 @@ def py_get_network_stats(): s = get_network_stats(&entries) if s == NULL: raise StatgrabException, 'get_network_stats() returned NULL' - list = [entries] + list = [] for i from 0 <= i < entries: list.append(Result( {'interface_name': s.interface_name, 'tx': s.tx, 'rx': s.rx, + 'ipackets': s.ipackets, + 'opackets': s.opackets, + 'ierrors': s.ierrors, + 'oerrors': s.oerrors, + 'collisions': s.collisions, 'systime': s.systime, } )) @@ -352,18 +379,41 @@ def py_get_network_stats_diff(): s = get_network_stats_diff(&entries) if s == NULL: raise StatgrabException, 'get_network_stats_diff() returned NULL' - list = [entries] + list = [] for i from 0 <= i < entries: list.append(Result( {'interface_name': s.interface_name, 'tx': s.tx, 'rx': s.rx, + 'ipackets': s.ipackets, + 'opackets': s.opackets, + 'ierrors': s.ierrors, + 'oerrors': s.oerrors, + 'collisions': s.collisions, 'systime': s.systime, } )) s = s + 1 return list +def py_get_network_iface_stats(): + cdef network_iface_stat_t *s + cdef int entries + s = get_network_iface_stats(&entries) + if s == NULL: + raise StatgrabException, 'get_network_iface_stats() returned NULL' + list = [] + for i from 0 <= i < entries: + list.append(Result( + {'interface_name': s.interface_name, + 'speed': s.speed, + 'dup': s.dup, + 'up' : s.up, + } + )) + s = s + 1 + return list + def py_get_page_stats(): cdef page_stat_t *s s = get_page_stats() @@ -387,7 +437,13 @@ def py_get_page_stats_diff(): ) def py_statgrab_init(): - return statgrab_init() + if statgrab_init() == 0: + return True + else: + return False def py_statgrab_drop_privileges(): - return statgrab_drop_privileges() + if statgrab_drop_privileges() == 0: + return True + else: + return False