diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | Makefile.in | 20 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 12 | ||||
-rw-r--r-- | lcd4linux.conf.sample | 6 | ||||
-rw-r--r-- | plugin.c | 14 | ||||
-rw-r--r-- | plugin_diskstats.c | 161 | ||||
-rw-r--r-- | plugins.m4 | 8 |
8 files changed, 214 insertions, 11 deletions
diff --git a/Makefile.am b/Makefile.am index 9539d39..aac5da6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -73,6 +73,7 @@ font_6x8.h \ \ plugin_apm.c \ plugin_cpuinfo.c \ +plugin_diskstats.c \ plugin_dvb.c \ plugin_exec.c \ plugin_i2c_sensors.c \ diff --git a/Makefile.in b/Makefile.in index 6a47fa2..2ae01c5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -101,7 +101,7 @@ lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h deb #liblcd4linux_la_SOURCES = -EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_BeckmannEgle.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_HD44780.c drv_Image.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_T6963.c drv_USBLCD.c drv_X11.c font_6x8.h plugin_apm.c plugin_cpuinfo.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_seti.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c +EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_BeckmannEgle.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_HD44780.c drv_Image.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_T6963.c drv_USBLCD.c drv_X11.c font_6x8.h plugin_apm.c plugin_cpuinfo.c plugin_diskstats.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_seti.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Drivers README.Plugins README.KDE plugin_sample.c @@ -148,15 +148,15 @@ DEP_FILES = .deps/cfg.P .deps/debug.P .deps/drv.P \ .deps/drv_generic_serial.P .deps/drv_generic_text.P .deps/evaluator.P \ .deps/hash.P .deps/layout.P .deps/lcd4linux.P .deps/pid.P \ .deps/plugin.P .deps/plugin_apm.P .deps/plugin_cfg.P \ -.deps/plugin_cpuinfo.P .deps/plugin_dvb.P .deps/plugin_exec.P \ -.deps/plugin_i2c_sensors.P .deps/plugin_imon.P .deps/plugin_isdn.P \ -.deps/plugin_loadavg.P .deps/plugin_math.P .deps/plugin_meminfo.P \ -.deps/plugin_mysql.P .deps/plugin_netdev.P .deps/plugin_pop3.P \ -.deps/plugin_ppp.P .deps/plugin_proc_stat.P .deps/plugin_seti.P \ -.deps/plugin_string.P .deps/plugin_time.P .deps/plugin_uname.P \ -.deps/plugin_uptime.P .deps/plugin_wireless.P .deps/plugin_xmms.P \ -.deps/qprintf.P .deps/thread.P .deps/timer.P .deps/udelay.P \ -.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ +.deps/plugin_cpuinfo.P .deps/plugin_diskstats.P .deps/plugin_dvb.P \ +.deps/plugin_exec.P .deps/plugin_i2c_sensors.P .deps/plugin_imon.P \ +.deps/plugin_isdn.P .deps/plugin_loadavg.P .deps/plugin_math.P \ +.deps/plugin_meminfo.P .deps/plugin_mysql.P .deps/plugin_netdev.P \ +.deps/plugin_pop3.P .deps/plugin_ppp.P .deps/plugin_proc_stat.P \ +.deps/plugin_seti.P .deps/plugin_string.P .deps/plugin_time.P \ +.deps/plugin_uname.P .deps/plugin_uptime.P .deps/plugin_wireless.P \ +.deps/plugin_xmms.P .deps/qprintf.P .deps/thread.P .deps/timer.P \ +.deps/udelay.P .deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ .deps/widget_text.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/config.h.in b/config.h.in index 4f81f0d..d8b4fdb 100644 --- a/config.h.in +++ b/config.h.in @@ -236,6 +236,9 @@ /* cpuinfo plugin */ #undef PLUGIN_CPUINFO +/* diskstats plugin */ +#undef PLUGIN_DISKSTATS + /* dvb plugin */ #undef PLUGIN_DVB @@ -5724,6 +5724,7 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;} all) PLUGIN_APM="yes" PLUGIN_CPUINFO="yes" + PLUGIN_DISKSTATS="yes" PLUGIN_DVB="yes" PLUGIN_EXEC="yes" PLUGIN_I2C_SENSORS="yes" @@ -5748,6 +5749,9 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;} cpuinfo) PLUGIN_CPUINFO=$val ;; + diskstats) + PLUGIN_DISKSTATS=$val + ;; dvb) PLUGIN_DVB=$val ;; @@ -5825,6 +5829,14 @@ cat >>confdefs.h <<\_ACEOF _ACEOF fi +if test "$PLUGIN_DISKSTATS" = "yes"; then + PLUGINS="$PLUGINS plugin_diskstats.o" + +cat >>confdefs.h <<\_ACEOF +#define PLUGIN_DISKSTATS 1 +_ACEOF + +fi if test "$PLUGIN_DVB" = "yes"; then for ac_header in linux/dvb/frontend.h diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 85281c6..7b5ecb2 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -221,6 +221,9 @@ Widget Disk { # disk.[rw]blk return blocks, we assume a blocksize of 512 # to get the number in kB/s we would do blk*512/1024, which is blk/2 expression (proc_stat::disk('.*', 'rblk', 500)+proc_stat::disk('.*', 'wblk', 500))/2 + # with kernel 2.6, disk_io disappeared from /proc/stat but moved to /proc/diskstat + # therefore you have to use another function called 'diskstats': + # expression (diskstats('.*', '.*_sectors', 500) prefix 'disk' postfix ' ' width 10 @@ -233,6 +236,9 @@ Widget DiskBar { class 'Bar' expression proc_stat::disk('.*', 'rblk', 500) expression2 proc_stat::disk('.*', 'wblk', 500) + # for kernel 2.6: + # expression diskstats('.*', 'read_sectors', 500) + # expression2 diskstats('.*', 'write_sectors', 500) length 14 direction 'E' update tack @@ -1,4 +1,4 @@ -/* $Id: plugin.c,v 1.30 2004/05/22 18:30:02 reinelt Exp $ +/* $Id: plugin.c,v 1.31 2004/05/29 00:27:23 reinelt Exp $ * * plugin handler for the Evaluator * @@ -22,6 +22,10 @@ * * * $Log: plugin.c,v $ + * Revision 1.31 2004/05/29 00:27:23 reinelt + * + * added plugin_diskstats.c + * * Revision 1.30 2004/05/22 18:30:02 reinelt * * added plugin 'uptime' @@ -185,6 +189,8 @@ int plugin_init_apm (void); void plugin_exit_apm (void); int plugin_init_cpuinfo (void); void plugin_exit_cpuinfo (void); +int plugin_init_diskstats (void); +void plugin_exit_diskstats (void); int plugin_init_dvb (void); void plugin_exit_dvb (void); int plugin_init_exec (void); @@ -234,6 +240,9 @@ int plugin_init (void) #ifdef PLUGIN_CPUINFO plugin_init_cpuinfo(); #endif +#ifdef PLUGIN_DISKSTATS + plugin_init_diskstats(); +#endif #ifdef PLUGIN_DVB plugin_init_dvb(); #endif @@ -297,6 +306,9 @@ void plugin_exit(void) { #ifdef PLUGIN_CPUINFO plugin_exit_cpuinfo(); #endif +#ifdef PLUGIN_DISKSTATS + plugin_exit_diskstats(); +#endif #ifdef PLUGIN_DVB plugin_exit_dvb(); #endif diff --git a/plugin_diskstats.c b/plugin_diskstats.c new file mode 100644 index 0000000..a48f00f --- /dev/null +++ b/plugin_diskstats.c @@ -0,0 +1,161 @@ +/* $Id: plugin_diskstats.c,v 1.1 2004/05/29 00:27:23 reinelt Exp $ + * + * plugin for /proc/diskstats parsing + * + * Copyright 2003 Michael Reinelt <reinelt@eunet.at> + * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> + * + * This file is part of LCD4Linux. + * + * LCD4Linux 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, or (at your option) + * any later version. + * + * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * $Log: plugin_diskstats.c,v $ + * Revision 1.1 2004/05/29 00:27:23 reinelt + * + * added plugin_diskstats.c + * + */ + +/* + * exported functions: + * + * int plugin_init_diskstats (void) + * adds functions to access /proc/stat + * + */ + + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> + +#include "debug.h" +#include "plugin.h" +#include "qprintf.h" +#include "hash.h" + + +static HASH DISKSTATS = { 0, }; +static FILE *stream = NULL; + + +static void hash_set2 (char *key1, char *key2, char *val) +{ + char key[32]; + + qprintf(key, sizeof(key), "%s.%s", key1, key2); + hash_set_delta (&DISKSTATS, key, val); +} + + +static int parse_diskstats (void) +{ + int age; + + // reread every 10 msec only + age = hash_age(&DISKSTATS, NULL, NULL); + if (age > 0 && age <= 10) return 0; + + if (stream == NULL) stream = fopen("/proc/diskstats", "r"); + if (stream == NULL) { + error ("fopen(/proc/diskstats) failed: %s", strerror(errno)); + return -1; + } + + rewind(stream); + + while (!feof(stream)) { + char buffer[1024]; + char *beg, *end; + char *major = NULL; + char *minor = NULL; + char *name = NULL; + char *key[] = { "reads", "read_merges", "read_sectors", "read_ticks", + "writes", "write_merges", "write_sectors", "write_ticks", + "in_flight", "io_ticks", "time_in_queue" + }; + + int i; + + if (fgets (buffer, sizeof(buffer), stream) == NULL) break; + + beg = buffer; + i = 0; + while (beg != NULL) { + while (*beg == ' ') beg++; + if ((end = strchr(beg, ' '))) *end = '\0'; + switch (i++) { + case 0: + major = beg; + break; + case 1: + minor = beg; + break; + case 2: + name = beg; + hash_set2 ("major", name, major); + hash_set2 ("minor", name, minor); + break; + default: + hash_set2 (key[i-3], name, beg); + } + beg = end ? end+1 : NULL; + } + } + return 0; +} + + +static void my_diskstats (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3) +{ + char *dev, *key, buffer[32]; + int delay; + double value; + + if (parse_diskstats() < 0) { + SetResult(&result, R_STRING, ""); + return; + } + + dev = R2S(arg1); + key = R2S(arg2); + delay = R2N(arg3); + + qprintf(buffer, sizeof(buffer), "%s\\.%s", dev, key); + value = hash_get_regex(&DISKSTATS, buffer, delay); + + SetResult(&result, R_NUMBER, &value); +} + + +int plugin_init_diskstats (void) +{ + AddFunction ("diskstats", 3, my_diskstats); + return 0; +} + +void plugin_exit_diskstats(void) +{ + if (stream != NULL) { + fclose (stream); + stream = NULL; + } + hash_destroy(&DISKSTATS); +} @@ -32,6 +32,7 @@ for plugin in $plugins; do all) PLUGIN_APM="yes" PLUGIN_CPUINFO="yes" + PLUGIN_DISKSTATS="yes" PLUGIN_DVB="yes" PLUGIN_EXEC="yes" PLUGIN_I2C_SENSORS="yes" @@ -56,6 +57,9 @@ for plugin in $plugins; do cpuinfo) PLUGIN_CPUINFO=$val ;; + diskstats) + PLUGIN_DISKSTATS=$val + ;; dvb) PLUGIN_DVB=$val ;; @@ -122,6 +126,10 @@ if test "$PLUGIN_CPUINFO" = "yes"; then PLUGINS="$PLUGINS plugin_cpuinfo.o" AC_DEFINE(PLUGIN_CPUINFO,1,[cpuinfo plugin]) fi +if test "$PLUGIN_DISKSTATS" = "yes"; then + PLUGINS="$PLUGINS plugin_diskstats.o" + AC_DEFINE(PLUGIN_DISKSTATS,1,[diskstats plugin]) +fi if test "$PLUGIN_DVB" = "yes"; then AC_CHECK_HEADERS(linux/dvb/frontend.h, [has_dvb_header=true], [has_dvb_header=false]) if test "$has_dvb_header" = true; then |