"Fossies" - the Fresh Open Source Software Archive

Member "dstat-0.7.4/plugins/dstat_squid.py" (17 Jan 2019, 1666 Bytes) of package /linux/privat/dstat-0.7.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "dstat_squid.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.7.3_vs_0.7.4.

    1 ### Authority: Jason Friedland <thesuperjason@gmail.com>
    2 
    3 # This plugin has been tested with:
    4 # - Dstat 0.6.7
    5 # - CentOS release 5.4 (Final)
    6 # - Python 2.4.3
    7 # - Squid 2.6 and 2.7
    8  
    9 global squidclient_options
   10 squidclient_options = os.getenv('DSTAT_SQUID_OPTS') # -p 8080
   11  
   12 class dstat_plugin(dstat):
   13     '''
   14     Provides various Squid statistics.
   15     '''
   16     def __init__(self):
   17         self.name = 'squid status'
   18         self.type = 's'
   19         self.width = 5
   20         self.scale = 1000
   21         self.vars = ('Number of file desc currently in use',
   22             'CPU Usage, 5 minute avg',
   23             'Total accounted',
   24             'Number of clients accessing cache',
   25             'Mean Object Size')
   26         self.nick = ('fdesc',
   27             'cpu5',
   28             'mem',
   29             'clnts',
   30             'objsz')
   31 
   32     def check(self):
   33         if not os.access('/usr/sbin/squidclient', os.X_OK):
   34             raise Exception('Needs squidclient binary')
   35         cmd_test('/usr/sbin/squidclient %s mgr:info' % squidclient_options)
   36         return True
   37  
   38     def extract(self):
   39         try:
   40             for l in cmd_splitlines('/usr/sbin/squidclient %s mgr:info' % squidclient_options, ':'):
   41                 if l[0].strip() in self.vars:
   42                     self.val[l[0].strip()] = l[1].strip()
   43                     break
   44         except IOError as e:
   45             if op.debug > 1: print('%s: lost pipe to squidclient, %s' % (self.filename, e))
   46             for name in self.vars: self.val[name] = -1
   47         except Exception as e:
   48             if op.debug > 1: print('%s: exception' (self.filename, e))
   49             for name in self.vars: self.val[name] = -1
   50 
   51 # vim:ts=4:sw=4:et