--- projects/libstatgrab/src/saidar/saidar.c 2003/10/09 15:57:05 1.1 +++ projects/libstatgrab/src/saidar/saidar.c 2003/10/18 15:05:17 1.9 @@ -1,3 +1,27 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -10,7 +34,12 @@ #include #include #include + +#ifdef HAVE_NCURSES_H +#include +#else #include +#endif typedef struct{ cpu_percent_t *cpu_percents; @@ -176,9 +205,22 @@ void display_data(){ diskio_stat_t *diskio_stat_ptr; network_stat_t *network_stat_ptr; disk_stat_t *disk_stat_ptr; + /* Size before it will start overwriting "uptime" */ + char hostname[15]; + char *ptr; move(0,12); - printw("%s", stats.general_stats->hostname); + strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); + /* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ + hostname[14] = '\0'; + ptr=strchr(hostname, '.'); + /* Some hosts give back a FQDN for hostname. To avoid this, we'll + * just blank out everything after the first "." + */ + if (ptr != NULL){ + *ptr = '\0'; + } + printw("%s", hostname); move(0,36); printw("%s", hr_uptime(stats.general_stats->uptime)); epoc_time=time(NULL); @@ -218,7 +260,6 @@ void display_data(){ printw("%5d", stats.user_stats->num_entries); /* Mem */ - move(6, 12); printw("%7s", size_conv(stats.mem_stats->total)); move(7, 12); @@ -286,6 +327,7 @@ void display_data(){ network_stat_ptr++; } + /* Disk */ disk_stat_ptr = stats.disk_stats; for(counter=0;counteravail)); move(13+stats.network_entries+counter, 73); - printw("%5.2f%%", 100.00 * ((float)disk_stat_ptr->used / (float)disk_stat_ptr->size)); + printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); disk_stat_ptr++; } @@ -323,6 +365,22 @@ int get_stats(){ return 1; } +void version_num(char *progname){ + fprintf(stderr, "%s version %s\n", progname, PACKAGE_VERSION); + fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); + exit(1); +} + +void usage(char *progname){ + fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); + fprintf(stderr, " -d Sets the update time in seconds\n"); + fprintf(stderr, " -v Prints version number\n"); + fprintf(stderr, " -h Displays this help information.\n"); + fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); + exit(1); + +} + int main(int argc, char **argv){ extern char *optarg; @@ -340,7 +398,7 @@ int main(int argc, char **argv){ int delay=2; - while ((c = getopt(argc, argv, "d:")) != EOF){ + while ((c = getopt(argc, argv, "vhd:")) != EOF){ switch (c){ case 'd': delay = atoi(optarg); @@ -350,6 +408,15 @@ int main(int argc, char **argv){ } delay--; break; + case 'v': + version_num(argv[0]); + break; + case 'h': + default: + usage(argv[0]); + return 1; + break; + } }