From 0434eba357e5d8955fa62f83e6c6dbe6a8d5252e Mon Sep 17 00:00:00 2001 From: Merlin Hughes Date: Wed, 31 Jul 2002 14:20:29 +0000 Subject: [PATCH] Update to support logging of the load average to the round-robin database. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@1474 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/sensord/args.c | 13 ++++++--- prog/sensord/rrd.c | 60 +++++++++++++++++++++++++++++++----------- prog/sensord/sensord.8 | 24 ++++++++++++----- prog/sensord/sensord.h | 3 ++- 4 files changed, 74 insertions(+), 26 deletions(-) diff --git a/prog/sensord/args.c b/prog/sensord/args.c index b2c6bafb..3369b368 100644 --- a/prog/sensord/args.c +++ b/prog/sensord/args.c @@ -43,6 +43,7 @@ int syslogFacility = LOG_LOCAL4; int doScan = 0; int doSet = 0; int doCGI = 0; +int doLoad = 0; int debug = 0; sensors_chip_name chipNames[MAX_CHIP_NAMES]; int numChipNames = 0; @@ -102,6 +103,7 @@ static const char *daemonSyntax = " -p, --pid-file -- PID file (default /var/run/sensord.pid)\n" " -f, --syslog-facility -- syslog facility to use (default local4)\n" " -g, --rrd-cgi -- output an RRD CGI script and exit\n" + " -a, --load-average -- include load average in RRD file\n" " -d, --debug -- display some debug information\n" " -v, --version -- display version and exit\n" " -h, --help -- display help and exit\n" @@ -116,7 +118,8 @@ static const char *daemonSyntax = "\n" "If unspecified, no RRD (round robin database) is used. If specified and the\n" "file does not exist, it will be created. For RRD updates to be successful,\n" - "the RRD file configuration must EXACTLY match the sensors that are used.\n"; + "the RRD file configuration must EXACTLY match the sensors that are used. If\n" + "your configuration changes, delete the old RRD file and restart sensord.\n"; static const char *appSyntax = " -a, --alarm-scan -- only scan for alarms\n" @@ -132,7 +135,7 @@ static const char *appSyntax = "\n" "If no chips are specified, all chip info will be printed.\n"; -static const char *daemonShortOptions = "i:l:t:f:r:c:p:dvhg:"; +static const char *daemonShortOptions = "i:l:t:f:r:c:p:advhg:"; static const struct option daemonLongOptions[] = { { "interval", required_argument, NULL, 'i' }, @@ -143,6 +146,7 @@ static const struct option daemonLongOptions[] = { { "config-file", required_argument, NULL, 'c' }, { "pid-file", required_argument, NULL, 'p' }, { "rrd-cgi", required_argument, NULL, 'g' }, + { "load-average", no_argument, NULL, 'a' }, { "debug", no_argument, NULL, 'd' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, @@ -192,7 +196,10 @@ parseArgs return -1; break; case 'a': - doScan = 1; + if (isDaemon) + doLoad = 1; + else + doScan = 1; break; case 's': doSet = 1; diff --git a/prog/sensord/rrd.c b/prog/sensord/rrd.c index 95b8fce7..a8dde0dd 100644 --- a/prog/sensord/rrd.c +++ b/prog/sensord/rrd.c @@ -63,9 +63,12 @@ #define RRD_BUFF 64 char rrdBuff[MAX_RRD_SENSORS * RRD_BUFF + 1]; -char rrdLabels[MAX_RRD_SENSORS][RAW_LABEL_LENGTH + 1]; +static char rrdLabels[MAX_RRD_SENSORS][RAW_LABEL_LENGTH + 1]; -typedef int (*FeatureFN) (void *data, const char *rawLabel, char *label, const FeatureDescriptor *feature); +#define LOADAVG "loadavg" +#define LOAD_AVERAGE "Load Average * 10" + +typedef int (*FeatureFN) (void *data, const char *rawLabel, const char *label, const FeatureDescriptor *feature); static char rrdNextChar @@ -186,8 +189,8 @@ struct ds { static int rrdGetSensors_DS -(void *_data, const char *rawLabel, char *label, const FeatureDescriptor *feature) { - if (feature->rrd) { +(void *_data, const char *rawLabel, const char *label, const FeatureDescriptor *feature) { + if (!feature || feature->rrd) { struct ds *data = (struct ds *) _data; char *ptr = rrdBuff + data->num * RRD_BUFF; data->argv[data->num ++] = ptr; @@ -202,6 +205,8 @@ rrdGetSensors int ret = 0; struct ds data = { 0, argv}; ret = applyToFeatures (rrdGetSensors_DS, &data); + if (!ret && doLoad) + ret = rrdGetSensors_DS (&data, LOADAVG, LOAD_AVERAGE, NULL); return ret ? -1 : data.num; } @@ -262,22 +267,23 @@ struct gr { char *axisTitle; char *axisDefn; char *options; + int loadAvg; }; static int rrdCGI_DEF -(void *_data, const char *rawLabel, char *label, const FeatureDescriptor *feature) { +(void *_data, const char *rawLabel, const char *label, const FeatureDescriptor *feature) { struct gr *data = (struct gr *) _data; - if (feature->rrd && (feature->type == data->type)) + if (!feature || (feature->rrd && (feature->type == data->type))) printf ("\n\tDEF:%s=%s:%s:AVERAGE", rawLabel, rrdFile, rawLabel); return 0; } static int rrdCGI_LINE -(void *_data, const char *rawLabel, char *label, const FeatureDescriptor *feature) { +(void *_data, const char *rawLabel, const char *label, const FeatureDescriptor *feature) { struct gr *data = (struct gr *) _data; - if (feature->rrd && (feature->type == data->type)) + if (!feature || (feature->rrd && (feature->type == data->type))) printf ("\n\tLINE2:%s#%.6x:\"%s\"", rawLabel, random () & 0xffffff, label); return 0; } @@ -290,7 +296,8 @@ static struct gr graphs[] = { "Temperature", "Temperature (C)", "HOUR:1:HOUR:3:HOUR:3:0:%b %d %H:00", - "-s -1d -l 0" + "-s -1d -l 0", + 1 }, { DataType_rpm, "Daily Fan Speed Summary", @@ -298,7 +305,8 @@ static struct gr graphs[] = { "Fan Speed", "Speed (RPM)", "HOUR:1:HOUR:3:HOUR:3:0:%b %d %H:00", - "-s -1d -l 0" + "-s -1d -l 0", + 0 }, { DataType_voltage, "Daily Voltage Summary", @@ -306,7 +314,8 @@ static struct gr graphs[] = { "Power Supply", "Voltage (V)", "HOUR:1:HOUR:3:HOUR:3:0:%b %d %H:00", - "-s -1d --alt-autoscale" + "-s -1d --alt-autoscale", + 0 }, { DataType_temperature, "Weekly Temperature Summary", @@ -314,7 +323,8 @@ static struct gr graphs[] = { "Temperature", "Temperature (C)", "HOUR:6:DAY:1:DAY:1:86400:%a %b %d", - "-s -1w -l 0" + "-s -1w -l 0", + 1 }, { DataType_rpm, "Weekly Fan Speed Summary", @@ -322,7 +332,8 @@ static struct gr graphs[] = { "Fan Speed", "Speed (RPM)", "HOUR:6:DAY:1:DAY:1:86400:%a %b %d", - "-s -1w -l 0" + "-s -1w -l 0", + 0 }, { DataType_voltage, "Weekly Voltage Summary", @@ -330,7 +341,8 @@ static struct gr graphs[] = { "Power Supply", "Voltage (V)", "HOUR:6:DAY:1:DAY:1:86400:%a %b %d", - "-s -1w --alt-autoscale" + "-s -1w --alt-autoscale", + 0 }, { DataType_other } @@ -340,7 +352,21 @@ int rrdUpdate (void) { int ret = rrdChips (); - + if (!ret && doLoad) { + FILE *loadavg; + if (!(loadavg = fopen ("/proc/loadavg", "r"))) { + sensorLog (LOG_ERR, "Error opening `/proc/loadavg': %s", strerror (errno)); + ret = 1; + } else { + float value; + if (fscanf (loadavg, "%f", &value) != 1) { + sensorLog (LOG_ERR, "Error reading load average"); + ret = 2; + } else { + sprintf (rrdBuff + strlen (rrdBuff), ":%f", value * 10.0); + } + } + } if (!ret) { const char *argv[] = { "sensord", rrdFile, rrdBuff, NULL @@ -371,8 +397,12 @@ rrdCGI printf ("\t--lazy\n\t-v '%s'\n\t-t '%s'\n\t-x '%s'\n\t%s", graph->axisTitle, graph->title, graph->axisDefn, graph->options); if (!ret) ret = applyToFeatures (rrdCGI_DEF, graph); + if (!ret && doLoad && graph->loadAvg) + ret = rrdCGI_DEF (graph, LOADAVG, LOAD_AVERAGE, NULL); if (!ret) ret = applyToFeatures (rrdCGI_LINE, graph); + if (!ret && doLoad && graph->loadAvg) + ret = rrdCGI_LINE (graph, LOADAVG, LOAD_AVERAGE, NULL); printf (">\n

\n"); ++ graph; } diff --git a/prog/sensord/sensord.8 b/prog/sensord/sensord.8 index a8af8f71..93b45d8c 100644 --- a/prog/sensord/sensord.8 +++ b/prog/sensord/sensord.8 @@ -21,7 +21,7 @@ .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" -.TH sensord 8 "April 27, 2002" "Version 0.6.0" "Linux System Administration" +.TH sensord 8 "July 31, 2002" "Version 0.6.2" "Linux System Administration" .SH NAME sensord \- Sensor information logging daemon. .SH SYNOPSIS @@ -115,6 +115,9 @@ this will be accessed under the `/sensord/' directory on the Webserver. See the section .B ROUND ROBIN DATABASES below for more details. +.IP "-a, --load-average" +Include the load average (multiplied by 10) in the RRD database. You should +also specify this flag when you create the CGI script. .IP "-d, --debug" Prints a small amount of additional debugging information. .IP "-h, --help" @@ -277,7 +280,9 @@ names and order of sensors read by .BR sensord (8). It is recommended that you create the default database and then use .BR rrdinfo (1) -to obtain this information. +to obtain this information, and/or +.BR rrdtune (1) +to change it. After creating the round-robin database, you must then configure your Web server to display the sensor information. This assumes that @@ -296,14 +301,17 @@ An example of how to set up Web-accessible graphs of recent sensor readings follows: .IP .nf -sensord -i 0 -r /var/log/sensord.rrd +sensord --log-interval 0 \\ + --load-average \\ + --rrd-cgi /var/log/sensord.rrd .fi .PP Here, we start .BR sensord (8) and configure it to store readings in a round-robin database; note that we disable logging of sensor readings to -.BR syslog (3). +.BR syslog (3), +and enable logging of the load average. .IP .nf mkdir /var/www/sensord @@ -317,7 +325,8 @@ directory appropriately. You will have to determine the location and ownership that is appropriate for your machine. .IP .nf -sensord --rrd-file /var/log/sensord.rrd \\ +sensord --load-average \\ + --rrd-file /var/log/sensord.rrd \\ --rrd-cgi /var/www/sensord \\ > /usr/lib/cgi-bin/sensord.cgi chmod a+rx /usr/lib/cgi-bin/sensord.cgi @@ -325,8 +334,9 @@ chmod a+rx /usr/lib/cgi-bin/sensord.cgi .PP Here, we create a CGI script that will display sensor readings from the database. -You must specify the location of the round-robin database and the -location of the directory where the images should be stored. The +You must specify the location of the round-robin database, the +location of the directory where the images should be stored, +and whether you want the load average displayed. The .BR --rrd-cgi command-line parameter causes .BR sensord (8) diff --git a/prog/sensord/sensord.h b/prog/sensord/sensord.h index 29374d2c..a5b4ded7 100644 --- a/prog/sensord/sensord.h +++ b/prog/sensord/sensord.h @@ -20,7 +20,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define version "0.6.0" +#define version "0.6.2" #include "lib/sensors.h" @@ -40,6 +40,7 @@ extern int syslogFacility; extern int doScan; extern int doSet; extern int doCGI; +extern int doLoad; extern int debug; extern sensors_chip_name chipNames[]; extern int numChipNames;