1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org |
4 |
+ |
* Copyright (C) 2000-2002 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 |
+ |
|
21 |
+ |
#ifdef HAVE_CONFIG_H |
22 |
+ |
#include "config.h" |
23 |
+ |
#endif |
24 |
+ |
|
25 |
|
#include <stdio.h> |
26 |
|
#include <string.h> |
27 |
|
#include <sys/ioctl.h> |
34 |
|
#include <sys/times.h> |
35 |
|
#include <limits.h> |
36 |
|
#include <time.h> |
37 |
+ |
|
38 |
+ |
#ifdef HAVE_NCURSES_H |
39 |
+ |
#include <ncurses.h> |
40 |
+ |
#else |
41 |
|
#include <curses.h> |
42 |
+ |
#endif |
43 |
|
|
44 |
|
typedef struct{ |
45 |
|
cpu_percent_t *cpu_percents; |
205 |
|
diskio_stat_t *diskio_stat_ptr; |
206 |
|
network_stat_t *network_stat_ptr; |
207 |
|
disk_stat_t *disk_stat_ptr; |
208 |
+ |
/* Size before it will start overwriting "uptime" */ |
209 |
+ |
char hostname[15]; |
210 |
+ |
char *ptr; |
211 |
|
|
212 |
|
move(0,12); |
213 |
< |
printw("%s", stats.general_stats->hostname); |
213 |
> |
strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); |
214 |
> |
/* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ |
215 |
> |
hostname[14] = '\0'; |
216 |
> |
ptr=strchr(hostname, '.'); |
217 |
> |
/* Some hosts give back a FQDN for hostname. To avoid this, we'll |
218 |
> |
* just blank out everything after the first "." |
219 |
> |
*/ |
220 |
> |
if (ptr != NULL){ |
221 |
> |
*ptr = '\0'; |
222 |
> |
} |
223 |
> |
printw("%s", hostname); |
224 |
|
move(0,36); |
225 |
|
printw("%s", hr_uptime(stats.general_stats->uptime)); |
226 |
|
epoc_time=time(NULL); |
260 |
|
printw("%5d", stats.user_stats->num_entries); |
261 |
|
|
262 |
|
/* Mem */ |
221 |
– |
|
263 |
|
move(6, 12); |
264 |
|
printw("%7s", size_conv(stats.mem_stats->total)); |
265 |
|
move(7, 12); |
327 |
|
network_stat_ptr++; |
328 |
|
} |
329 |
|
|
330 |
+ |
/* Disk */ |
331 |
|
disk_stat_ptr = stats.disk_stats; |
332 |
|
for(counter=0;counter<stats.disk_entries;counter++){ |
333 |
|
move(13+stats.network_entries+counter, 42); |
335 |
|
move(13+stats.network_entries+counter, 62); |
336 |
|
printw("%7s", size_conv(disk_stat_ptr->avail)); |
337 |
|
move(13+stats.network_entries+counter, 73); |
338 |
< |
printw("%5.2f%%", 100.00 * ((float)disk_stat_ptr->used / (float)disk_stat_ptr->size)); |
338 |
> |
printw("%5.2f%%", 100.00 * ((float) (disk_stat_ptr->size - disk_stat_ptr->avail) / (float) disk_stat_ptr->size)); |
339 |
|
disk_stat_ptr++; |
340 |
|
} |
341 |
|
|
365 |
|
return 1; |
366 |
|
} |
367 |
|
|
368 |
+ |
void version_num(char *progname){ |
369 |
+ |
fprintf(stderr, "%s version %s\n", progname, PACKAGE_VERSION); |
370 |
+ |
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
371 |
+ |
exit(1); |
372 |
+ |
} |
373 |
+ |
|
374 |
+ |
void usage(char *progname){ |
375 |
+ |
fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); |
376 |
+ |
fprintf(stderr, " -d Sets the update time in seconds\n"); |
377 |
+ |
fprintf(stderr, " -v Prints version number\n"); |
378 |
+ |
fprintf(stderr, " -h Displays this help information.\n"); |
379 |
+ |
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
380 |
+ |
exit(1); |
381 |
+ |
|
382 |
+ |
} |
383 |
+ |
|
384 |
|
int main(int argc, char **argv){ |
385 |
|
|
386 |
|
extern char *optarg; |
398 |
|
|
399 |
|
int delay=2; |
400 |
|
|
401 |
< |
while ((c = getopt(argc, argv, "d:")) != EOF){ |
401 |
> |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
402 |
|
switch (c){ |
403 |
|
case 'd': |
404 |
|
delay = atoi(optarg); |
408 |
|
} |
409 |
|
delay--; |
410 |
|
break; |
411 |
+ |
case 'v': |
412 |
+ |
version_num(argv[0]); |
413 |
+ |
break; |
414 |
+ |
case 'h': |
415 |
+ |
default: |
416 |
+ |
usage(argv[0]); |
417 |
+ |
return 1; |
418 |
+ |
break; |
419 |
+ |
|
420 |
|
} |
421 |
|
} |
422 |
|
|