File: dstat_squid.py

package info (click to toggle)
dstat 0.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,600 kB
  • sloc: python: 5,964; makefile: 70; sh: 3
file content (51 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
### Authority: Jason Friedland <thesuperjason@gmail.com>

# This plugin has been tested with:
# - Dstat 0.6.7
# - CentOS release 5.4 (Final)
# - Python 2.4.3
# - Squid 2.6 and 2.7
 
global squidclient_options
squidclient_options = os.getenv('DSTAT_SQUID_OPTS') # -p 8080
 
class dstat_plugin(dstat):
    '''
    Provides various Squid statistics.
    '''
    def __init__(self):
        self.name = 'squid status'
        self.type = 's'
        self.width = 5
        self.scale = 1000
        self.vars = ('Number of file desc currently in use',
            'CPU Usage, 5 minute avg',
            'Total accounted',
            'Number of clients accessing cache',
            'Mean Object Size')
        self.nick = ('fdesc',
            'cpu5',
            'mem',
            'clnts',
            'objsz')

    def check(self):
        if not os.access('/usr/bin/squidclient', os.X_OK):
            raise Exception('Needs squidclient binary')
        cmd_test('/usr/bin/squidclient %s mgr:info' % squidclient_options)
        return True
 
    def extract(self):
        try:
            for l in cmd_splitlines('/usr/bin/squidclient %s mgr:info' % squidclient_options, ':'):
                if l[0].strip() in self.vars:
                    self.val[l[0].strip()] = l[1].strip()
                    break
        except IOError as e:
            if op.debug > 1: print('%s: lost pipe to squidclient, %s' % (self.filename, e))
            for name in self.vars: self.val[name] = -1
        except Exception as e:
            if op.debug > 1: print('%s: exception' (self.filename, e))
            for name in self.vars: self.val[name] = -1

# vim:ts=4:sw=4:et