1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
|
* http://www.i-scream.org |
4 |
< |
* Copyright (C) 2000-2003 i-scream |
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 |
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 |
|
#ifdef HAVE_CONFIG_H |
37 |
|
FLOAT, |
38 |
|
DOUBLE, |
39 |
|
STRING, |
40 |
< |
INT |
40 |
> |
INT, |
41 |
> |
BOOL, |
42 |
> |
DUPLEX |
43 |
|
} stat_type; |
44 |
|
|
45 |
|
typedef enum { |
283 |
|
die("out of memory"); |
284 |
|
|
285 |
|
name = buf; |
286 |
+ |
if (strlen(name) == 2 && name[1] == ':') |
287 |
+ |
name[1] = '\0'; |
288 |
|
if (strncmp(name, "/dev/", 5) == 0) |
289 |
|
name += 5; |
290 |
|
while ((p = strchr(name, '/')) != NULL) |
350 |
|
void populate_net() { |
351 |
|
int n, i; |
352 |
|
network_stat_t *net; |
353 |
+ |
network_iface_stat_t *iface; |
354 |
|
|
355 |
|
net = use_diffs ? get_network_stats_diff(&n) : get_network_stats(&n); |
356 |
|
if (net != NULL) { |
367 |
|
"net", name, "systime", NULL); |
368 |
|
} |
369 |
|
} |
370 |
+ |
|
371 |
+ |
iface = get_network_iface_stats(&n); |
372 |
+ |
if (iface != NULL) { |
373 |
+ |
for (i = 0; i < n; i++) { |
374 |
+ |
const char *name = iface[i].interface_name; |
375 |
+ |
|
376 |
+ |
add_stat(INT, &iface[i].speed, |
377 |
+ |
"net", name, "speed", NULL); |
378 |
+ |
add_stat(BOOL, &iface[i].up, |
379 |
+ |
"net", name, "up", NULL); |
380 |
+ |
add_stat(DUPLEX, &iface[i].dup, |
381 |
+ |
"net", name, "duplex", NULL); |
382 |
+ |
} |
383 |
+ |
} |
384 |
|
} |
385 |
|
|
386 |
|
void populate_page() { |
390 |
|
if (page != NULL) { |
391 |
|
add_stat(LONG_LONG, &page->pages_pagein, "page", "in", NULL); |
392 |
|
add_stat(LONG_LONG, &page->pages_pageout, "page", "out", NULL); |
393 |
< |
add_stat(LONG_LONG, &page->systime, "page", "systime", NULL); |
393 |
> |
add_stat(TIME_T, &page->systime, "page", "systime", NULL); |
394 |
|
} |
395 |
|
} |
396 |
|
|
449 |
|
t->populate(); |
450 |
|
} |
451 |
|
|
452 |
< |
qsort(stats, num_stats, sizeof *stats, stats_compare); |
452 |
> |
if (stats != NULL) |
453 |
> |
qsort(stats, num_stats, sizeof *stats, stats_compare); |
454 |
|
} |
455 |
|
|
456 |
|
/* Print the value of a stat. */ |
478 |
|
case INT: |
479 |
|
printf("%d", *(int *)v); |
480 |
|
break; |
481 |
+ |
case BOOL: |
482 |
+ |
printf("%s", *(int *)v ? "true" : "false"); |
483 |
+ |
break; |
484 |
+ |
case DUPLEX: |
485 |
+ |
switch (*(statgrab_duplex *) v) { |
486 |
+ |
case FULL_DUPLEX: |
487 |
+ |
printf("full"); |
488 |
+ |
break; |
489 |
+ |
case HALF_DUPLEX: |
490 |
+ |
printf("half"); |
491 |
+ |
break; |
492 |
+ |
default: |
493 |
+ |
printf("unknown"); |
494 |
+ |
break; |
495 |
+ |
} |
496 |
+ |
break; |
497 |
|
} |
498 |
|
} |
499 |
|
|
536 |
|
else |
537 |
|
compare = stats_compare; |
538 |
|
|
539 |
< |
s = (const stat *)bsearch(&key, stats, num_stats, |
540 |
< |
sizeof *stats, compare); |
539 |
> |
if (stats == NULL) { |
540 |
> |
s = NULL; |
541 |
> |
} else { |
542 |
> |
s = (const stat *)bsearch(&key, stats, |
543 |
> |
num_stats, |
544 |
> |
sizeof *stats, |
545 |
> |
compare); |
546 |
> |
} |
547 |
> |
|
548 |
|
if (s == NULL) { |
549 |
|
printf("Unknown stat %s\n", name); |
550 |
|
continue; |
647 |
|
use_diffs = 1; |
648 |
|
|
649 |
|
select_interesting(argc - optind, &argv[optind]); |
650 |
+ |
|
651 |
+ |
/* We don't care if statgrab_init fails, because we can just display |
652 |
+ |
the statistics that can be read as non-root. */ |
653 |
+ |
statgrab_init(); |
654 |
+ |
if (statgrab_drop_privileges() != 0) |
655 |
+ |
die("Failed to drop setuid/setgid privileges"); |
656 |
|
|
657 |
|
switch (repeat_mode) { |
658 |
|
case REPEAT_NONE: |