[svn] r6224 - in trunk/tools/dstat: . plugins

packagers at lists.rpmforge.net packagers at lists.rpmforge.net
Sun Mar 16 07:49:13 CET 2008


Author: dag
Date: 2008-03-16 06:49:12 +0000 (Sun, 16 Mar 2008)
New Revision: 6224

Modified:
   trunk/tools/dstat/ChangeLog
   trunk/tools/dstat/dstat
   trunk/tools/dstat/plugins/dstat_cpufreq.py
Log:
Added --pidfile option to write out a pidfile (Kelly Long)

Modified: trunk/tools/dstat/ChangeLog
===================================================================
--- trunk/tools/dstat/ChangeLog	2008-03-16 06:18:16 UTC (rev 6223)
+++ trunk/tools/dstat/ChangeLog	2008-03-16 06:49:12 UTC (rev 6224)
@@ -6,6 +6,7 @@
 - Scheduler accuracy improvements by using sched instead of signal
 - Added external dstat_snooze plugin (Kelly Long)
 - Improved dstat_time to accept format string from DSTAT_TIMEFMT (Kelly Long)
+- Added --pidfile option to write out a pidfile (Kelly Long)
 
 * 0.6.7 - Cambridge overdue - released 26/02/2008
 - Only rewrite xterm title when XTERM_SHELL is set to bash

Modified: trunk/tools/dstat/dstat
===================================================================
--- trunk/tools/dstat/dstat	2008-03-16 06:18:16 UTC (rev 6223)
+++ trunk/tools/dstat/dstat	2008-03-16 06:49:12 UTC (rev 6224)
@@ -87,6 +87,7 @@
         self.update = True
         self.header = True
         self.output = False
+        self.pidfile = False
 
         ### Implicit if no terminal is used
         if not sys.stdout.isatty():
@@ -107,7 +108,7 @@
                 ['cpu', 'disk', 'epoch', 'int', 'ipc', 'load', 'lock', 'mem', 'net',
                 'page', 'proc', 'raw', 'swap', 'sys', 'tcp', 'time', 'udp', 'unix', 
                 'all', 'debug', 'full', 'help', 'integer', 'mods', 'modules', 'nocolor',
-                'noheaders', 'noupdate', 'output=', 'version', 'vmstat'])
+                'noheaders', 'noupdate', 'output=', 'pidfile=', 'version', 'vmstat'])
         except getopt.error, exc:
             print 'dstat: %s, try dstat -h for a list of all the options' % str(exc)
             sys.exit(1)
@@ -184,6 +185,8 @@
                 self.update = False
             elif opt in ['-o', '--output']:
                 self.output = arg
+            elif opt in ['--pidfile']:
+                self.pidfile = arg
             elif opt in ['-h', '--help']:
                 self.usage()
                 self.help()
@@ -1617,14 +1620,9 @@
             line = line + ','
     outputfile.write(line + '\n')
 
-def info(level, str):
-    "Output info message"
-#   if level <= op.verbose:
-    print str
-
 def die(ret, str):
     "Print error and exit with errorcode"
-    info(0, str)
+    print >>sys.stderr, str
     exit(ret)
 
 def initterm():
@@ -1676,7 +1674,7 @@
             if curses.tigetnum('colors') < 0:
                 return False
         except:
-            info(1, 'Color support is disabled, python-curses is not installed.')
+            print >>sys.stderr, 'Color support is disabled, python-curses is not installed.'
             return False
     return color
 
@@ -1827,6 +1825,7 @@
     ### Check terminal capabilities
     op.color = gettermcolor(op.color)
 
+    ### Prepare CSV output file
     if op.output:
         if os.path.exists(op.output):
             outputfile = open(op.output, 'a', 0)
@@ -1839,6 +1838,16 @@
         outputfile.write('"Host:","%s",,,,"User:","%s"\n' % (hostname, user))
         outputfile.write('"Cmdline:","dstat %s",,,,"Date:","%s"\n\n' % (' '.join(op.args), time.strftime('%d %b %Y %H:%M:%S %Z', time.localtime())))
 
+    ### Create pidfile
+    if op.pidfile:
+        try:
+            pidfile = open(op.pidfile, 'w', 0)
+            pidfile.write(str(os.getpid()))
+            pidfile.close()
+        except Exception, e:
+            print >>sys.stderr, 'Failed to create pidfile %s' % op.pidfile, e
+            op.pidfile = False
+
     ### Empty ansi database if no colors are requested
     if not op.color:
         op.update = False
@@ -1884,7 +1893,7 @@
 #                        print o.__module__
 #                        print o.name
                     else:
-                        info(1, 'Module is of unknown type.')
+                        print >>sys.stderr, 'Module %s is of unknown type.' % mod
 
                     ### Remove defect stat objects and calculate line length
                     if not o.check():
@@ -1894,9 +1903,9 @@
 #               print o.__module__
             except Exception, e:
                 if mod == mods[-1]:
-                    info(1, 'Module %s failed to load. (%s)' % (mod, e))
+                    print >>sys.stderr, 'Module %s failed to load. (%s)' % (mod, e)
                 elif op.debug:
-                    info(1, 'Module %s failed to load, trying another. (%s)' % (mod, e))
+                    print >>sys.stderr, 'Module %s failed to load, trying another. (%s)' % (mod, e)
                 if op.debug:
                     raise
 #                tb = sys.exc_info()[2]
@@ -1993,7 +2002,7 @@
         ### Display header
         if showheader:
             if loop == 0 and totlist != vislist:
-                info(1, 'Terminal width too small, trimming output.')
+                print >>sys.stderr, 'Terminal width too small, trimming output.'
             showheader = False
             showtitle(1, totlist, vislist, ansi['darkblue'] + char['space'], ansi['darkblue'] + char['gt'])
             showtitle(2, totlist, vislist, ansi['gray'] + char['pipe'], ansi['darkblue'] + char['gt'])
@@ -2046,6 +2055,10 @@
         main()
     except KeyboardInterrupt, e:
         print ansi['default']
+
+    if op.pidfile and os.path.exists(op.pidfile):
+        os.remove(op.pidfile)
+
     exit(0)
 else:
     op = Options('')

Modified: trunk/tools/dstat/plugins/dstat_cpufreq.py
===================================================================
--- trunk/tools/dstat/plugins/dstat_cpufreq.py	2008-03-16 06:18:16 UTC (rev 6223)
+++ trunk/tools/dstat/plugins/dstat_cpufreq.py	2008-03-16 06:49:12 UTC (rev 6224)
@@ -26,7 +26,7 @@
         if self.vars:
             for cpu in self.vars:
                 if not os.access('/sys/devices/system/cpu/'+cpu+'/cpufreq/scaling_cur_freq', os.R_OK):
-                    raise Exception, 'Cannot access acpi cpu frequency information'
+                    raise Exception, 'Cannot access acpi '+cpu+' frequency information'
             return True
         raise Exception, 'No statistics found'
 




More information about the commits mailing list