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.3 by tdb, Mon Feb 9 23:07:25 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 115 | Line 135 | class Result:
135      def __repr__(self):
136          return str(self.attrs)
137  
138 + class StatgrabException:
139 +    def __init__(self, value):
140 +        self.value = value
141 +    def __str__(self):
142 +        return repr(self.value)
143  
144 +
145   def py_get_cpu_totals():
146      cdef cpu_states_t *s
147      s = get_cpu_totals()
148 +    if s == NULL:
149 +        raise StatgrabException, 'get_cpu_totals() returned NULL'
150      return Result(
151          {'user': s.user,
152           'kernel': s.kernel,
# Line 134 | Line 162 | def py_get_cpu_totals():
162   def py_get_cpu_diff():
163      cdef cpu_states_t *s
164      s = get_cpu_diff()
165 +    if s == NULL:
166 +        raise StatgrabException, 'get_cpu_diff() returned NULL'
167      return Result(
168          {'user': s.user,
169           'kernel': s.kernel,
# Line 149 | Line 179 | def py_get_cpu_diff():
179   def py_cpu_percent_usage():
180      cdef cpu_percent_t *s
181      s = cpu_percent_usage()
182 +    if s == NULL:
183 +        raise StatgrabException, 'cpu_percent_usage() returned NULL'
184      return Result(
185          {'user': s.user,
186           'kernel': s.kernel,
# Line 163 | Line 195 | def py_cpu_percent_usage():
195   def py_get_memory_stats():
196      cdef mem_stat_t *s
197      s = get_memory_stats()
198 +    if s == NULL:
199 +        raise StatgrabException, 'get_memory_stats() returned NULL'
200      return Result(
201          {'total': s.total,
202           'used': s.used,
# Line 174 | Line 208 | def py_get_memory_stats():
208   def py_get_load_stats():
209      cdef load_stat_t *s
210      s = get_load_stats()
211 +    if s == NULL:
212 +        raise StatgrabException, 'get_load_stats() returned NULL'
213      return Result(
214          {'min1': s.min1,
215           'min5': s.min5,
# Line 184 | Line 220 | def py_get_load_stats():
220   def py_get_user_stats():
221      cdef user_stat_t *s
222      s = get_user_stats()
223 +    if s == NULL:
224 +        raise StatgrabException, 'get_user_stats() returned NULL'
225      return Result(
226          {'name_list': s.name_list,
227           'num_entries': s.num_entries,
# Line 193 | Line 231 | def py_get_user_stats():
231   def py_get_swap_stats():
232      cdef swap_stat_t *s
233      s = get_swap_stats()
234 +    if s == NULL:
235 +        raise StatgrabException, 'get_swap_stats() returned NULL'
236      return Result(
237          {'total': s.total,
238           'used': s.used,
# Line 203 | Line 243 | def py_get_swap_stats():
243   def py_get_general_stats():
244      cdef general_stat_t *s
245      s = get_general_stats()
246 +    if s == NULL:
247 +        raise StatgrabException, 'get_general_stats() returned NULL'
248      return Result(
249          {'os_name': s.os_name,
250           'os_release': s.os_release,
# Line 217 | Line 259 | def py_get_disk_stats():
259      cdef disk_stat_t *s
260      cdef int entries
261      s = get_disk_stats(&entries)
262 +    if s == NULL:
263 +        raise StatgrabException, 'get_disk_stats() returned NULL'
264      list = [entries]
265      for i from 0 <= i < entries:
266          list.append(Result(
# Line 238 | Line 282 | def py_get_diskio_stats():
282      cdef diskio_stat_t *s
283      cdef int entries
284      s = get_diskio_stats(&entries)
285 +    if s == NULL:
286 +        raise StatgrabException, 'get_diskio_stats() returned NULL'
287      list = [entries]
288      for i from 0 <= i < entries:
289          list.append(Result(
# Line 254 | Line 300 | def py_get_diskio_stats_diff():
300      cdef diskio_stat_t *s
301      cdef int entries
302      s = get_diskio_stats_diff(&entries)
303 +    if s == NULL:
304 +        raise StatgrabException, 'get_diskio_stats_diff() returned NULL'
305      list = [entries]
306      for i from 0 <= i < entries:
307          list.append(Result(
# Line 269 | Line 317 | def py_get_diskio_stats_diff():
317   def py_get_process_stats():
318      cdef process_stat_t *s
319      s = get_process_stats()
320 +    if s == NULL:
321 +        raise StatgrabException, 'get_process_stats() returned NULL'
322      return Result(
323          {'total': s.total,
324           'running': s.running,
# Line 282 | Line 332 | def py_get_network_stats():
332      cdef network_stat_t *s
333      cdef int entries
334      s = get_network_stats(&entries)
335 +    if s == NULL:
336 +        raise StatgrabException, 'get_network_stats() returned NULL'
337      list = [entries]
338      for i from 0 <= i < entries:
339          list.append(Result(
# Line 298 | Line 350 | def py_get_network_stats_diff():
350      cdef network_stat_t *s
351      cdef int entries
352      s = get_network_stats_diff(&entries)
353 +    if s == NULL:
354 +        raise StatgrabException, 'get_network_stats_diff() returned NULL'
355      list = [entries]
356      for i from 0 <= i < entries:
357          list.append(Result(
# Line 313 | Line 367 | def py_get_network_stats_diff():
367   def py_get_page_stats():
368      cdef page_stat_t *s
369      s = get_page_stats()
370 +    if s == NULL:
371 +        raise StatgrabException, 'get_page_stats() returned NULL'
372      return Result(
373          {'pages_pagein': s.pages_pagein,
374           'pages_pageout': s.pages_pageout,
# Line 322 | Line 378 | def py_get_page_stats():
378   def py_get_page_stats_diff():
379      cdef page_stat_t *s
380      s = get_page_stats_diff()
381 +    if s == NULL:
382 +        raise StatgrabException, 'get_page_stats_diff() returned NULL'
383      return Result(
384          {'pages_pagein': s.pages_pagein,
385           'pages_pageout': s.pages_pageout,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines