pax_global_header00006660000000000000000000000064142216423470014517gustar00rootroot0000000000000052 comment=6e830b74b96ed350884a3c95518d189058ba6582 mrtgutils-0.8.4/000077500000000000000000000000001422164234700135625ustar00rootroot00000000000000mrtgutils-0.8.4/Makefile.am000066400000000000000000000013701422164234700156170ustar00rootroot00000000000000ACLOCAL_AMFLAGS = -I m4 noinst_LTLIBRARIES = libmrtgutil.la libmrtgutil_la_SOURCES = uptime.c util.c bin_PROGRAMS = \ mrtg-apache \ mrtg-ip-acct \ mrtg-load \ mrtg-uptime man_MANS = \ mrtg-apache.1 \ mrtg-ip-acct.1 \ mrtg-load.1 \ mrtg-uptime.1 mrtg_apache_SOURCES = mrtg-apache.c mrtg_apache_LDADD = libmrtgutil.la mrtg_ip_acct_SOURCES = mrtg-ip-acct.c mrtg_ip_acct_LDADD = libmrtgutil.la mrtg_load_SOURCES = mrtg-load.c mrtg_load_LDADD = libmrtgutil.la mrtg_uptime_SOURCES = mrtg-uptime.c mrtg_uptime_LDADD = libmrtgutil.la if WITH_SENSORS bin_PROGRAMS += mrtg-sensors man_MANS += mrtg-sensors.1 mrtg_sensors_SOURCES = mrtg-sensors.c mrtg_sensors_LDADD = libmrtgutil.la -lsensors endif %.1: %.pod pod2man $(MRTGUTILS_POD2MAN_ARGS) $^ > $@ mrtgutils-0.8.4/configure.ac000066400000000000000000000025761422164234700160620ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([mrtgutils], [0.8.4], [https://salsa.debian.org/debian/mrtgutils]) AC_CONFIG_SRCDIR([util.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign]) LT_PREREQ([2.4.6]) LT_INIT # Checks for programs. AC_PROG_CC AC_PROG_INSTALL AC_CHECK_PROGS(POD2MAN, [pod2man]) MRTGUTILS_POD2MAN_ARGS="--center='MRTG helper utilities' --release='mrtgutils "${PACKAGE_VERSION}"'" AC_SUBST([MRTGUTILS_POD2MAN_ARGS]) # Checks for libraries. AC_ARG_WITH([sensors], [AS_HELP_STRING([--with-sensors],[Enable sensors support])]) AS_IF([test "x$with_sensors" != "xno"], [AC_CHECK_LIB([sensors], [sensors_init], [mrtgutils_build_sensors="true"], [AC_MSG_FAILURE([libsensors test failed (use --without-sensors to disable)])])], []) AM_CONDITIONAL([WITH_SENSORS], [test "x${mrtgutils_build_sensors}" = "xtrue"]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h unistd.h utmp.h]) # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_CHECK_FUNCS([gethostbyname gethostname memset socket strrchr strstr strtoul]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT mrtgutils-0.8.4/m4/000077500000000000000000000000001422164234700141025ustar00rootroot00000000000000mrtgutils-0.8.4/m4/.placeholder000066400000000000000000000000001422164234700163530ustar00rootroot00000000000000mrtgutils-0.8.4/mrtg-apache.c000066400000000000000000000045101422164234700161160ustar00rootroot00000000000000#include "uptime.h" #include "util.h" #include #include #include #include #include #include #include #include #define REQUEST "GET /%s?auto\n" #define PERROR(c) do { perror(c); exit(1); } while (0); #define DIE(fmt, arg...) do { fprintf(stderr, fmt, ##arg); exit(1); } while (0); #define SHOWUSAGE DIE("Usage: mrtg-apache [-p port] [-m multiplier] [-s status-directory] -q\n") static int quiet = 0; void print_accesses(char *hostname, int port, char *statusdir, int multiplier) { int s, bytesread; char buf[2048], input[256], *p; struct sockaddr_in addr; struct hostent *h = gethostbyname(hostname); unsigned long accesses = 0; memset(&addr, 0, sizeof(addr)); if (!h) { if (quiet) { printf("0\n"); return; } else { DIE("Cannot resolve %s\n", hostname); } } addr.sin_family = AF_INET; addr.sin_port = htons(port); memcpy(&addr.sin_addr, h->h_addr, sizeof(addr.sin_addr)); snprintf(buf, sizeof(buf), REQUEST, statusdir); if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) PERROR("socket"); if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) PERROR("connect"); if (write(s, buf, strlen(buf)+1) < 0) PERROR("write"); p = buf; *p = 0; while ((bytesread = read(s, input, sizeof(input))) > 0) { if (sizeof(buf) - (p - buf) > bytesread) { memcpy(p, input, bytesread); p += bytesread; } else { /* buffer is not big enough; assume that we've read enough and just * quit */ break; } } if ((p = strstr(buf, "Total Accesses: "))) { accesses = strtoul(p + 16, NULL, 0); } printf("%lu\n", accesses * multiplier); close(s); return; } int main(int argc, char **argv) { char *hostname; int port = 80; int multiplier = 1; char *statusdir = "server-status"; int c; while ((c = getopt(argc, argv, "qp:m:s:")) > 0) { switch (c) { case 'q': quiet = 1; break; case 'p': port = atoi(optarg); break; case 'm': multiplier = atoi(optarg); break; case 's': statusdir = optarg; break; default: SHOWUSAGE; } } if (optind >= argc) SHOWUSAGE; hostname = argv[optind]; printf("0\n"); print_accesses(hostname, port, statusdir, multiplier); print_uptime(); print_hostname(); return 0; } mrtgutils-0.8.4/mrtg-apache.pod000066400000000000000000000014411422164234700164560ustar00rootroot00000000000000=head1 NAME mrtg-apache - Returns the number of hits to a Apache web site =head1 SYNOPSIS mrtg-apache Ehost nameE [B<-p> port] [B<-m> multiplier] =head1 DESCRIPTION mrtg-apache uses the server-info capability (mod_info) of Apache to determine the number of hits to a web server. The output is written in a form useful as input for the mrtg utility. Ehost nameE is the name of the Apache host to contact. B<-p> is the port number to use. Default is 80. B<-m> is the multiplier to be used in the output. For example, with a multiplier of 100, if Apache returns 20 accesses, the output will be 2000. =head1 SEE ALSO mrtg(1) =head1 AUTHOR mrtg-apache was written by Randolph Chung Etausq@debian.orgE. =head1 HISTORY This document first appeared with mrtgutils-0.1 mrtgutils-0.8.4/mrtg-ip-acct.c000066400000000000000000000022111422164234700162110ustar00rootroot00000000000000#include "uptime.h" #include "util.h" #include #include #include #include void print_ipacct(char *dev, int packets) { char buf[1024]; char *p; FILE *f; unsigned long long in = 0, out = 0; f = fopen("/proc/net/dev", "r"); if (!f) { fprintf(stderr, "mrtg-ip-acct:error: Error reading /proc/net/dev\n"); exit(2); } while (fgets(buf, sizeof(buf), f)) { p = buf; while (isspace(*p)) p++; if (strncmp(dev, p, strlen(dev)) == 0) { while (*p != ':') p++; p++; if (packets) sscanf(p, "%*d %Lu %*d %*d %*d %*d %*d %*d %*d %Lu %*d %*d %*d %*d %*d %*d", &in, &out); else sscanf(p, "%Lu %*d %*d %*d %*d %*d %*d %*d %Lu %*d %*d %*d %*d %*d %*d %*d", &in, &out); } } fclose(f); printf("%Lu\n%Lu\n", in, out); } int main(int argc, char **argv) { char *device = "eth0"; int packets = 0; int nextarg = 1; if (argc > nextarg && !strncmp(argv[nextarg], "-p", 3)) { packets = 1; ++nextarg; } if (argc > nextarg) device = argv[nextarg]; print_ipacct(device, packets); print_uptime(); print_hostname(); return 0; } mrtgutils-0.8.4/mrtg-ip-acct.pod000066400000000000000000000011031422164234700165500ustar00rootroot00000000000000=head1 NAME mrtg-ip-acct - Returns the number of IP packets that have traversed a network interface =head1 SYNOPSIS mrtg-ip-acct [Einterface nameE] =head1 DESCRIPTION mrtg-ip-acct returns the number of bytes that have been received and sent on a given interface. The output is written in a form useful as input for the mrtg utility. If no interface name is given, the default is eth0. =head1 SEE ALSO mrtg(1) =head1 AUTHOR mrtg-apache was written by Randolph Chung Etausq@debian.orgE. =head1 HISTORY This document first appeared with mrtgutils-0.1 mrtgutils-0.8.4/mrtg-load.c000066400000000000000000000030601422164234700156130ustar00rootroot00000000000000#include "uptime.h" #include "util.h" #include #include #include #include static int count = 0; static void usage(int rc) { fprintf(stderr, "Usage: mrtg-system [-l 1|5|15] [-m multiplier]\n"); exit(rc); } static void setPos(double** pos1, double** pos2, double i) { count++; if (count > 2) { fprintf(stderr, "mrtg-uptime:error: only two parameters can be sample at a time. It can be 1, 5, or 15.\n"); exit(2); } if (count == 1) *pos1 = &i; if (count == 2) *pos2 = &i; } int main(int argc, char **argv) { char* slash; double z=0; double avg1, avg5, avg15; double* pos1; double* pos2; double mult [2] = {1,1}; int c; int countm = 0; loadavg(&avg1, &avg5, &avg15); pos1 = &z; pos2=&avg5; slash = strrchr(argv[0], '/'); if (slash) argv[0] = slash + 1; while ((c = getopt(argc, argv, "m:l:")) > 0) { switch (c) { case 'm': setD(&countm, argv[0], &mult[0],atof(optarg)); break; case 'l': if (strcmp(optarg, "1") == 0) setPos(&pos1, &pos2, avg1); else if (strcmp(optarg, "5") == 0) setPos(&pos1, &pos2, avg5); else if (strcmp(optarg, "15") == 0) setPos(&pos1, &pos2, avg15); else { fprintf(stderr, "%s:error: unknown load average period '%s'.\nThe possible periods are 1, 5, and 15.", argv[0], optarg); usage(2); } break; default: usage(0); } } printf("%.0f\n", *pos1*mult[0]); printf("%.0f\n", *pos2*mult[1]); print_uptime(); print_hostname(); return 0; } mrtgutils-0.8.4/mrtg-load.pod000066400000000000000000000024551422164234700161620ustar00rootroot00000000000000=head1 NAME mrtg-load - Returns the current load or uptime data =head1 SYNOPSIS mrtg-load ([B<-l> 1|5|15] [B<-m> I])*2 =head1 DESCRIPTION mrtg-load returns the system load averages for the past 1, 5, or 15 minutes. The output is written in a form useful as input for the MRTG utility. Every parameter can be accepted twice and allow to control the two values in the output. =over =item B<-l> 1|5|15 Sets the system load average to display in the output. If none is set, only the 5 minutes average with be displyed in the second position. =item B<-m> I Sets the multiplier to be used in the output. For example, with a load of 1.2 and a multiplier of 100, the output load average would be 120. Note that the option order is important. If it is defined once, affect both output values. The default multiplier is 1. =back =head1 EXAMPLE Prints the 5-minute average of the system load, multiplied by 100. =over mrtg-load -m 100 =back Prints the 1-minute and 15-minute averages of the system load. The firs one multipled by 10, the second one by 100. =over mrtg-load -l 1 -m 10 -l 15 -m 100 =back =head1 SEE ALSO mrtg(1) =head1 AUTHOR Randolph Chung Etausq@debian.orgE is the orginal writer of mrtgutils. =head1 HISTORY This document first appeared with mrtgutils-0.1 mrtgutils-0.8.4/mrtg-sensors.c000066400000000000000000000051361422164234700163760ustar00rootroot00000000000000#include "uptime.h" #include "util.h" #include #include #include #include #include #include #include int print_value(char *chipname, char *label, double mult) { int a, b, chip_nr, gotchip; const sensors_feature *feature; const sensors_subfeature *subfeature; char *name; double val; const sensors_chip_name *chip; sensors_chip_name chipparsed; /* Special dummy chip. */ if (strcmp(chipname, "dummy") == 0) { printf("0\n"); return(1); } if (sensors_parse_chip_name(chipname, &chipparsed) != 0) { fprintf(stderr, "error parsing chip name, \"%s\"\n", chipname); printf("0\n"); return(0); } /* * To make wildcards work, iterate over all chips until one that * matches the parsed name is found. */ for (gotchip= chip_nr = 0; ! gotchip && (chip = sensors_get_detected_chips(&chipparsed, &chip_nr));) gotchip = 1; if (!gotchip) { fprintf(stderr, "could not find chip, \"%s\"\n", chipname); printf("0\n"); return(0); } /* * Now get all features and iterate through to find * the one that was requested. */ a=0; while ((feature=sensors_get_features(chip, &a))) { b=0; while ((subfeature=sensors_get_all_subfeatures(chip, feature, &b))) { if ((name = sensors_get_label(chip, feature)) && (strcmp(name, label) == 0) && (sensors_get_value(chip, subfeature->number, &val)) == 0) { printf("%.0f\n", val * mult); return(1); } } } fprintf(stderr, "could not find label %s\n", label); printf("0\n"); return(0); } void usage (void) { fprintf(stderr, "Usage: mrtg-sensors ([-m multiplier])*2 chip label [chip label]\n"); exit(1); } int main (int argc, char *argv[]) { int res, c, success = 1; double mult [2] = {1,1}; int countm = 0; while ((c = getopt(argc, argv, "m:")) > 0) { switch (c) { case 'm': setD(&countm, argv[0], &mult[0],atof(optarg)); break; default: usage(); } } if (optind >= argc || (argc - optind != 2 && argc - optind != 4)) usage(); if ((res = sensors_init(NULL))) { if (res == SENSORS_ERR_KERNEL) { fprintf(stderr, "/proc/sys/dev/sensors/chips or /proc/bus/i2c unreadable:\n" "Make sure you have inserted modules sensors.o and i2c-proc.o!"); } else { fprintf(stderr,"%s\n",sensors_strerror(res)); } exit(1); } success = success & print_value(argv[optind], argv[optind+1], mult[0]); if (argc - optind == 4) success = success & print_value(argv[optind+2] , argv[optind+3], mult[1]); else printf("0\n"); print_uptime(); print_hostname(); if (success) return(0); else return(1); } mrtgutils-0.8.4/mrtg-sensors.pod000066400000000000000000000041561422164234700167370ustar00rootroot00000000000000=head1 NAME mrtg-sensors - Returns data from lm-sensors =head1 SYNOPSIS mrtg-sensors ([B<-m> multiplier])*2 chip label [chip label] =head1 DESCRIPTION mrtg-sensors uses the lm-sensors library to query various system sensors for information such as temperature, fan speed, etc. The output is written in a form useful as input for the MRTG utility. Up to two pairs of chips and labels may be specified. The first is used for the incoming data value in MRTG, while the second is used for the outgoing data value. Of course, they need not correspond to incoming or outgoing data, that is merely what MRTG expects. "chip" is the name of the chip to query, and "label" is the label of the piece of information that should be queried from the given chip. sensors(1) can be used to look up all available chips and labels on your system. Wildcards may be used in chip names, but only the first matching chip will be queried. If you use the special name "dummy" as a chip name, nothing will be queried, and a value of zero will be sent to MRTG. =over =item B<-m> I Sets the multiplier to be used in the output. For example, if the temperature is 59.2 and a multiplier of 100, the output would be 592. The option order is important, the first -m will modify the first value and the second -m, the second. Note that you may find it more useful to use sensors.conf(5) to set global multipliers for sensors. If it is defined once, affect both output values. The default multiplier is 1. =back =head1 EXAMPLES =over 4 =item mrtg-sensors dummy dummy adm9240-\* fan2 Get the speed of fan #2 from the adm9240 chip. =item mrtg-sensors -m 0.5 adm9240-\* fan1 adm9240-\* fan2 Get the speeds of both fan #1 and fan #2, halfing both. =item mrtg-sensors -m 2 dummy dummy adm9240-\* temp Get the cpu temperature, and double it. =item mrtg-sensors -m 0.5 adm9240-\* fan1 -m 10 adm9240-\* temp Get the fan #1 speed and halfing it, and the cpu temperature with one decimal (e.i multipled by 10). =back =head1 SEE ALSO sensors(1) sensors.conf(5) =head1 AUTHOR mrtg-sensors was written by Joey 'no pseudo-code' Hess Ejoeyh@debian.orgE. mrtgutils-0.8.4/mrtg-uptime.c000066400000000000000000000050741422164234700162060ustar00rootroot00000000000000#include "uptime.h" #include "util.h" #include #include #include #include int countt = 0; static void setT(char* ar, char i) { countt++; if (countt > 2) { fprintf(stderr, "mrtg-uptime:error: only two parameters at a time. It can be sys or idle.\n"); exit(2); } if (countt == 2) ar[1] = i; else ar[0] = i; } static void usage(int rc) { fprintf(stderr, "Usage: mrtg-uptime ([-t sys|idle] [-m multiplier] [-u s|m|h|d])*2 [-c #cores]\n"); exit(rc); } int main(int argc, char **argv) { char* slash; int c; double sys_uptime, idle_uptime, pos1, pos2; int cores = 1; double mult [2] = {1,1}; double unit [2] = {1,1}; char typ [2] = {'s','i'}; int countm = 0; int countu = 0; slash = strrchr(argv[0], '/'); if (slash) argv[0] = slash + 1; while ((c = getopt(argc, argv, "t:m:u:c:")) > 0) { switch (c) { case 't': if (strcmp(optarg, "sys") == 0) setT(typ,'s'); else if (strcmp(optarg, "idle") == 0) setT(typ,'i'); else { fprintf(stderr, "%s:error: unknown uptime type '%s'.\nThe possible uptime types are sys and idle\n", argv[0], optarg); usage(2); } break; case 'm': setD(&countm, argv[0], &mult[0],atof(optarg)); break; case 'u': // [-u s|m|h|d] if (optarg[0] == 's') setD(&countu, argv[0], &unit[0],(float)1); // second else if (optarg[0] == 'm') setD(&countu, argv[0], &unit[0],(float)60); // minute else if (optarg[0] == 'h') setD(&countu, argv[0], &unit[0],(float)3600); // hour else if (optarg[0] == 'd') setD(&countu, argv[0], &unit[0],(float)86400); // day else { fprintf(stderr, "%s:error: unknown unit '%s'.\nThe possible units are (s)econds, (m)inutes, (h)ours, and (d)ays'\n", argv[0], optarg); usage(2); } break; case 'c': cores = atof(optarg); break; default: usage(0); } } uptime(&sys_uptime, &idle_uptime); pos1=sys_uptime; pos2=idle_uptime/(float)cores; switch (countt) { case 1: if (typ[0] == 's') pos1=sys_uptime; else pos1=idle_uptime/(float)cores; pos2 = 0; break; case 2: if (typ[0] == 's') { pos1=sys_uptime; } else { pos1=idle_uptime/(float)cores; } if (typ[1] == 's') { pos2=sys_uptime; } else { pos2=idle_uptime/(float)cores; } break; } printf("%.0f\n", pos1*mult[0]/unit[0]); printf("%.0f\n", pos2*mult[1]/unit[1]); print_uptime(); print_hostname(); return 0; } mrtgutils-0.8.4/mrtg-uptime.pod000066400000000000000000000037431422164234700165470ustar00rootroot00000000000000=head1 NAME mrtg-uptime - Returns uptime and idle data from /proc/uptime =head1 SYNOPSIS B ([B<-t> sys|idle] [B<-m> I] [B<-u> s|m|h|d])*2 [B<-c> I<#cores>] =head1 DESCRIPTION mrtg-uptime returns the information from /proc/uptime. The output is written in a form useful as input for the MRTG utility. Every parameter can be accepted twice and allow to control the two values in the output, with the exception of B<-c> that only affects idle uptime. =over =item B<-t> sys|idle Sets the uptime parameter in the output. If just one is set, the other one will be zero. The parameter B refers to the time the system has been up. The parameter B refers to the time the machine has spent idle. =item B<-m> I Sets the multiplier to be used in the output. For example, if the value is 280936.41 and a multiplier of 100, the output would be 28093641. If it is defined once, affect both output values. The default multiplier is 1. =item B<-u> s|m|h|d Sets the unit of the parameter. It can be expressed in (s)econds, (m)inutes, (h)ours, or (d)ays. If it is defined once, affect both output values. The default is seconds. =item B<-c> I<#cores> Because the idle uptime measures the cumulative time each processor, ignoring the amount of cores, the resulting value is the sum of how much time each core has spent idle. This parameter divides the value by I<#cores> (an integer) to get the average idle time per core. Default is 1. =back =head1 EXAMPLES Prints the average idle uptime of a core in a dual-core and the system uptime, both in minutes. =over mrtg-uptime -t idle -t sys -u m -c 2 =back Prints the uptime in hours and in seconds. =over mrtg-uptime -t sys -u h -t sys -u s =back =head1 SEE ALSO mrtg(1) =head1 AUTHORS Randolph Chung Etausq@debian.orgE is the orginal writer of mrtgutils. Luciano Bello Eluciano@debian.orgE wrote mrtg-uptime and this manpage. =head1 HISTORY This document first appeared with mrtgutils-0.8.2 mrtgutils-0.8.4/uptime.c000066400000000000000000000064021422164234700152330ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include "uptime.h" static char buf[128]; static double av[3]; static char *sprint_uptime(void); int uptime(double *uptime_secs, double *idle_secs) { static int got_uptime = 0; static double up = 0, idle = 0; if (!got_uptime) { FILE *f; f = fopen("/proc/uptime", "r"); if (!f) return -1; if (fscanf(f, "%lf %lf", &up, &idle) < 2) { fprintf(stderr, "bad data in /proc/uptime\n"); return 0; } fclose(f); got_uptime = 1; } if (uptime_secs) *uptime_secs = up; if (idle_secs) *idle_secs = idle; return up; /* assume never be zero seconds in practice */ } void loadavg(double *av1, double *av5, double *av15) { static int got_load = 0; static double avg_1 = 0, avg_5 = 0, avg_15 = 0; if (!got_load) { FILE *f; f = fopen("/proc/loadavg", "r"); if (!f) return; if (fscanf(f, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) { fprintf(stderr, "bad data in /proc/loadavg\n"); exit(1); } got_load = 1; } if (av1) *av1 = avg_1; if (av5) *av5 = avg_5; if (av15) *av15 = avg_15; } char *sprint_uptime(void) { struct utmp *utmpstruct; int upminutes, uphours, updays; int pos; struct tm *realtime; time_t realseconds; int numuser; double uptime_secs, idle_secs; /* first get the current time */ time(&realseconds); realtime = localtime(&realseconds); pos = sprintf(buf, " %2d:%02d%s ", realtime->tm_hour%12 ? realtime->tm_hour%12 : 12, realtime->tm_min, realtime->tm_hour > 11 ? "pm" : "am"); /* read and calculate the amount of uptime */ uptime(&uptime_secs, &idle_secs); updays = (int) uptime_secs / (60*60*24); strcat (buf, "up "); pos += 3; if (updays) pos += sprintf(buf + pos, "%d day%s, ", updays, (updays != 1) ? "s" : ""); upminutes = (int) uptime_secs / 60; uphours = upminutes / 60; uphours = uphours % 24; upminutes = upminutes % 60; if(uphours) pos += sprintf(buf + pos, "%2d:%02d, ", uphours, upminutes); else pos += sprintf(buf + pos, "%d min, ", upminutes); /* count the number of users */ numuser = 0; setutent(); while ((utmpstruct = getutent())) { if ((utmpstruct->ut_type == USER_PROCESS) && (utmpstruct->ut_name[0] != '\0')) numuser++; } endutent(); pos += sprintf(buf + pos, "%2d user%s, ", numuser, numuser == 1 ? "" : "s"); loadavg(&av[0], &av[1], &av[2]); pos += sprintf(buf + pos, " load average: %.2f, %.2f, %.2f", av[0], av[1], av[2]); return buf; } void print_uptime(void) { printf("%s\n", sprint_uptime()); } /* This is a trivial uptime program. I hereby release this program * into the public domain. I disclaim any responsibility for this * program --- use it at your own risk. (as if there were any.. ;-) * -michaelkjohnson (johnsonm@sunsite.unc.edu) * * Modified by Larry Greenfield to give a more traditional output, * count users, etc. (greenfie@gauss.rutgers.edu) * * Modified by mkj again to fix a few tiny buglies. * * Modified by J. Cowley to add printing the uptime message to a * string (for top) and to optimize file handling. 19 Mar 1993. * */ mrtgutils-0.8.4/uptime.h000066400000000000000000000002451422164234700152370ustar00rootroot00000000000000#ifndef UPTIME_H #define UPTIME_H void loadavg (double *, double *, double *); int uptime(double *uptime_secs, double *idle_secs); void print_uptime(void); #endif mrtgutils-0.8.4/util.c000066400000000000000000000010501422164234700146770ustar00rootroot00000000000000#include "util.h" #include #include #include #include #include #include void print_hostname(void) { char hostname[255]; struct hostent *h; gethostname(hostname, sizeof(hostname)); h = gethostbyname(hostname); printf("%s\n", (h ? h->h_name : "(none)")); } void setD(int* c,const char* name, double* ar, double i) { (*c)++; if ((*c) > 2) { fprintf(stderr, "%s:error: only two parameters at a time\n", name); exit(2); } ar[1] = i; if (*c == 1) ar[0] = i; } mrtgutils-0.8.4/util.h000066400000000000000000000001601422164234700147050ustar00rootroot00000000000000#ifndef UTIL_H #define UTIL_H void print_hostname(void); void setD(int*,const char*, double*, double); #endif