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 |
|
|
135 |
|
def __repr__(self): |
136 |
|
return str(self.attrs) |
137 |
|
|
138 |
+ |
class StatgrabException(Exception): |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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( |
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( |
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( |
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, |
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( |
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( |
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, |
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, |