1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
69 |
|
char *size_conv(long long number){ |
70 |
|
char type[] = {'B', 'K', 'M', 'G', 'T'}; |
71 |
|
int x=0; |
72 |
+ |
int sign=1; |
73 |
|
static char string[10]; |
74 |
|
|
75 |
+ |
if(number < 0){ |
76 |
+ |
sign=-1; |
77 |
+ |
number=-number; |
78 |
+ |
} |
79 |
+ |
|
80 |
|
for(;x<5;x++){ |
81 |
|
if( (number/1024) < (100)) { |
82 |
|
break; |
84 |
|
number = (number/1024); |
85 |
|
} |
86 |
|
|
87 |
< |
snprintf(string, 10, "%lld%c", number, type[x]); |
87 |
> |
number = number*sign; |
88 |
> |
|
89 |
> |
snprintf(string, 10, "%lld%c", number, type[x]); |
90 |
|
return string; |
91 |
|
|
92 |
|
} |
160 |
|
printw("Mem Free :"); |
161 |
|
|
162 |
|
/* Swap */ |
163 |
< |
move(6, 21); |
164 |
< |
printw("Swap Total:"); |
165 |
< |
move(7, 21); |
166 |
< |
printw("Swap Used :"); |
167 |
< |
move(8, 21); |
168 |
< |
printw("Swap Free :"); |
163 |
> |
move(6, 21); |
164 |
> |
printw("Swap Total:"); |
165 |
> |
move(7, 21); |
166 |
> |
printw("Swap Used :"); |
167 |
> |
move(8, 21); |
168 |
> |
printw("Swap Free :"); |
169 |
|
|
170 |
|
/* VM */ |
171 |
|
move(6, 42); |
335 |
|
r=0; |
336 |
|
w=0; |
337 |
|
for(counter=0;counter<stats.disk_io_entries;counter++){ |
338 |
+ |
char name[12]; |
339 |
+ |
strncpy(name, disk_io_stat_ptr->disk_name, sizeof(name)); |
340 |
+ |
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ |
341 |
|
move(line, 0); |
342 |
< |
printw("%s", disk_io_stat_ptr->disk_name); |
342 |
> |
printw("%s", name); |
343 |
|
move(line, 12); |
344 |
|
rt = (disk_io_stat_ptr->systime)? (disk_io_stat_ptr->read_bytes/disk_io_stat_ptr->systime): disk_io_stat_ptr->read_bytes; |
345 |
|
printw("%7s", size_conv(rt)); |
365 |
|
/* Network */ |
366 |
|
network_stat_ptr = stats.network_io_stats; |
367 |
|
for(counter=0;counter<stats.network_io_entries;counter++){ |
368 |
< |
move(line, 42); |
369 |
< |
printw("%s", network_stat_ptr->interface_name); |
368 |
> |
char name[20]; |
369 |
> |
strncpy(name, network_stat_ptr->interface_name, sizeof(name)); |
370 |
> |
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ |
371 |
> |
move(line, 42); |
372 |
> |
printw("%s", name); |
373 |
|
move(line, 62); |
374 |
|
rt = (network_stat_ptr->systime)? (network_stat_ptr->rx / network_stat_ptr->systime): network_stat_ptr->rx; |
375 |
|
printw("%7s", size_conv(rt)); |
386 |
|
/* Disk */ |
387 |
|
disk_stat_ptr = stats.fs_stats; |
388 |
|
for(counter=0;counter<stats.fs_entries;counter++){ |
389 |
+ |
char name[20]; |
390 |
+ |
strncpy(name, disk_stat_ptr->mnt_point, sizeof(name)); |
391 |
+ |
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ |
392 |
|
move(line, 42); |
393 |
< |
printw("%s", disk_stat_ptr->mnt_point); |
393 |
> |
printw("%s", name); |
394 |
|
move(line, 62); |
395 |
|
printw("%7s", size_conv(disk_stat_ptr->avail)); |
396 |
|
move(line, 73); |
397 |
< |
printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); |
397 |
> |
printw("%6.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); |
398 |
|
disk_stat_ptr++; |
399 |
|
line++; |
400 |
|
} |
403 |
|
refresh(); |
404 |
|
} |
405 |
|
|
406 |
< |
void sig_winch_handler(int sig){ |
406 |
> |
void sig_winch_handler(int dummy){ |
407 |
|
clear(); |
408 |
|
display_headings(); |
409 |
|
display_data(); |
410 |
< |
signal(SIGWINCH, sig_winch_handler); |
410 |
> |
signal(SIGWINCH, sig_winch_handler); |
411 |
|
} |
412 |
|
|
413 |
|
int get_stats(){ |
433 |
|
} |
434 |
|
|
435 |
|
void usage(char *progname){ |
436 |
< |
fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); |
437 |
< |
fprintf(stderr, " -d Sets the update time in seconds\n"); |
436 |
> |
fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); |
437 |
> |
fprintf(stderr, " -d Sets the update time in seconds\n"); |
438 |
|
fprintf(stderr, " -v Prints version number\n"); |
439 |
< |
fprintf(stderr, " -h Displays this help information.\n"); |
440 |
< |
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
441 |
< |
exit(1); |
439 |
> |
fprintf(stderr, " -h Displays this help information.\n"); |
440 |
> |
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
441 |
> |
exit(1); |
442 |
|
} |
443 |
|
|
444 |
|
int main(int argc, char **argv){ |
445 |
|
|
446 |
< |
extern char *optarg; |
447 |
< |
int c; |
446 |
> |
extern char *optarg; |
447 |
> |
int c; |
448 |
|
|
449 |
|
time_t last_update = 0; |
450 |
|
|
460 |
|
return 1; |
461 |
|
} |
462 |
|
|
463 |
< |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
464 |
< |
switch (c){ |
465 |
< |
case 'd': |
466 |
< |
delay = atoi(optarg); |
463 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
464 |
> |
switch (c){ |
465 |
> |
case 'd': |
466 |
> |
delay = atoi(optarg); |
467 |
|
if (delay < 1){ |
468 |
|
fprintf(stderr, "Time must be 1 second or greater\n"); |
469 |
|
exit(1); |
470 |
|
} |
471 |
< |
break; |
471 |
> |
break; |
472 |
|
case 'v': |
473 |
|
version_num(argv[0]); |
474 |
|
break; |
477 |
|
usage(argv[0]); |
478 |
|
return 1; |
479 |
|
break; |
480 |
< |
} |
481 |
< |
} |
480 |
> |
} |
481 |
> |
} |
482 |
|
|
483 |
|
signal(SIGWINCH, sig_winch_handler); |
484 |
< |
initscr(); |
485 |
< |
nonl(); |
486 |
< |
cbreak(); |
487 |
< |
noecho(); |
484 |
> |
initscr(); |
485 |
> |
nonl(); |
486 |
> |
cbreak(); |
487 |
> |
noecho(); |
488 |
|
timeout(delay * 1000); |
489 |
< |
window=newwin(0, 0, 0, 0); |
489 |
> |
window=newwin(0, 0, 0, 0); |
490 |
|
clear(); |
491 |
|
|
492 |
|
if(!get_stats()){ |