]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-05-29 00:27:14 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 29 May 2004 00:27:23 +0000 (00:27 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 29 May 2004 00:27:23 +0000 (00:27 +0000)
added plugin_diskstats.c

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@443 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

Makefile.am
Makefile.in
config.h.in
configure
lcd4linux.conf.sample
plugin.c
plugin_diskstats.c [new file with mode: 0644]
plugins.m4

index 9539d3942ff819579df3702a32df0984903d7171..aac5da6f224ca916ef63845b7b0f53a83506b300 100644 (file)
@@ -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        \
index 6a47fa292841fe21c97a2ce794bf832c49add9c1..2ae01c5a097e74d7adeaf89817190b305f8f2f5c 100644 (file)
@@ -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)
index 4f81f0de130d9aeff953efc987aeb466b8bc2003..d8b4fdb6b846aca010710780ada82bb9f94777a7 100644 (file)
 /* cpuinfo plugin */
 #undef PLUGIN_CPUINFO
 
+/* diskstats plugin */
+#undef PLUGIN_DISKSTATS
+
 /* dvb plugin */
 #undef PLUGIN_DVB
 
index bede6cf769ec802f67ddc3ac372eef137cfdaba3..2f9a2993336e0ed1eee597d31816d043cee72b03 100755 (executable)
--- a/configure
+++ b/configure
@@ -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
          ;;
@@ -5824,6 +5828,14 @@ cat >>confdefs.h <<\_ACEOF
 #define PLUGIN_CPUINFO 1
 _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
 
index 85281c6863078948ac9b19ce204fadf345bf18db..7b5ecb215ebb36786bf949cdfc596a3fcc733155 100644 (file)
@@ -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
index 69a6212b3070c3adda19f526fe27d7de6c9df761..1302d586b33638612f92f2f2a4b1aabab23c0363 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -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
  *
  *
  *
  * $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 (file)
index 0000000..a48f00f
--- /dev/null
@@ -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);
+}
index 547fc5703afc6bd18021c0f1d1e6db0ac8b8b04c..41f4efb3816d829e60171f2c6becf462e0a94d31 100644 (file)
@@ -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