Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 132 lines (110 sloc) 4.332 kB
8c0a4be @saltycrane Major changes. Added real-time web plots using Orbited, Stomp, js.io,…
authored
1 from subprocess import Popen, PIPE, STDOUT
974fce3 @saltycrane PEP 8 cleanup
authored
2
8c0a4be @saltycrane Major changes. Added real-time web plots using Orbited, Stomp, js.io,…
authored
3
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
4 class SourceBase(object):
974fce3 @saltycrane PEP 8 cleanup
authored
5 """Subclasses should define instance attributes self.ssh_params,
6 self.cmd, self.encoding and optionally the instance method
7 self.filter() self.ssh_params is a dict containing the parameters
8 to pass to the ssh command. At a minimum, it should define
9 self.ssh_params['hostname']. It may also define other ssh options
10 such as 'host', 'user' or 'identityfile'. Option names are the
11 same as those used in the ssh config file, except in
12 lowercase. For more information see the man page for
13 ssh_config. The 'host' option is used as a nickname. If 'host' is
14 not specified, the value for 'hostname' is assigned to 'host'.
7e9b2c5 @saltycrane Changed sources classes to use more explicit SSH parameters. Fixed "c…
authored
15
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
16 Example self.ssh_params:
7e9b2c5 @saltycrane Changed sources classes to use more explicit SSH parameters. Fixed "c…
authored
17
18 {'host': 'us-ng1',
19 'hostname': '111.111.111.15',
20 'identityfile': '/home/saltycrane/sshkeys/myprivatekey',
21 'user': 'myusername',
22 }
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
23 """
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
24 def start_stream(self):
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
25 self._assemble_ssh_command()
26 self.p = Popen(self.ssh_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
27
28 def _assemble_ssh_command(self):
29 if 'host' not in self.ssh_params:
30 self.ssh_params['host'] = self.ssh_params['hostname']
31 ssh_options = ' -o'.join(['='.join([k, v])
32 for k, v in self.ssh_params.iteritems()
33 if k != 'hostname' and k != 'host'])
34 if ssh_options:
35 ssh_options = '-o' + ssh_options
36 self.ssh_cmd = ' '.join(['ssh',
37 ssh_options,
38 self.ssh_params['hostname'],
974fce3 @saltycrane PEP 8 cleanup
authored
39 '"%s"' % self.cmd,
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
40 ])
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
41
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
42 def get_line(self):
43 while True:
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
44 line = self.p.stdout.readline()
45 if line == '' and self.p.poll() != None:
7e9b2c5 @saltycrane Changed sources classes to use more explicit SSH parameters. Fixed "c…
authored
46 raise Exception('Child process exited for host %s: %s' % (
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
47 self.ssh_params['host'], self.cmd))
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
48 line = unicode(line, encoding=self.encoding, errors='replace')
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
49 line = self.filter(line)
50 if line:
51 break
52 return line
53
54 def filter(self, line):
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
55 """To skip a line return an empty string ('')
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
56 Otherwise, return the line.
57 """
58 return line
59
974fce3 @saltycrane PEP 8 cleanup
authored
60
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
61 class SourceLog(SourceBase):
8c0a4be @saltycrane Major changes. Added real-time web plots using Orbited, Stomp, js.io,…
authored
62 """A source log file on a remote host.
63 """
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
64 def __init__(self, ssh_params, filepath, encoding='utf-8'):
65 self.ssh_params = ssh_params
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
66 self.encoding = encoding
67 self.cmd = 'tail --follow=name %s' % filepath
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
68
974fce3 @saltycrane PEP 8 cleanup
authored
69
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
70 class MysqladminExtendedRelativeSource(SourceBase):
71 """Get data from mysqladmin extended command (relative)
72 """
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
73 def __init__(self, ssh_params, encoding='utf-8'):
74 self.ssh_params = ssh_params
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
75 self.encoding = encoding
76 self.cmd = 'mysqladmin extended -i10 -r'
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
77
78 def filter(self, line):
79 if ('Questions' in line or
974fce3 @saltycrane PEP 8 cleanup
authored
80 'Slow_queries' in line):
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
81 return line
82 else:
1ae08ad @saltycrane Added plots for wordpress logged in, PHP error counts, and s3fs (sysl…
authored
83 return ''
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
84
974fce3 @saltycrane PEP 8 cleanup
authored
85
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
86 class MysqladminExtendedAbsoluteSource(SourceBase):
87 """Get data from mysqladmin extended command (absolute)
88 """
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
89 def __init__(self, ssh_params, encoding='utf-8'):
90 self.ssh_params = ssh_params
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
91 self.encoding = encoding
92 self.cmd = 'mysqladmin extended'
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
93
94 def filter(self, line):
95 if ('Slave_running' in line or
96 'Threads_connected' in line or
974fce3 @saltycrane PEP 8 cleanup
authored
97 'Threads_running' in line):
39a0754 @saltycrane Added "mysqladmin extended" sources, parsers, and analyzers
authored
98 return line
99 else:
c2fe3f3 @saltycrane Added "vmstat" source, parser, and analyzer
authored
100 return ''
101
974fce3 @saltycrane PEP 8 cleanup
authored
102
c2fe3f3 @saltycrane Added "vmstat" source, parser, and analyzer
authored
103 class VmstatSource(SourceBase):
104 """Get data from vmstat
105 """
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
106 def __init__(self, ssh_params, encoding='utf-8'):
107 self.ssh_params = ssh_params
185854a @saltycrane Refactored sources.py module. Store input text as unicode strings ins…
authored
108 self.encoding = encoding
109 self.cmd = 'vmstat 5'
c2fe3f3 @saltycrane Added "vmstat" source, parser, and analyzer
authored
110
111 def filter(self, line):
112 if (line.startswith('procs') or
974fce3 @saltycrane PEP 8 cleanup
authored
113 line.startswith(' r')):
c2fe3f3 @saltycrane Added "vmstat" source, parser, and analyzer
authored
114 return ''
115 else:
116 return line
ad71638 @saltycrane Added analyzer for "average upstream response time" that takes advant…
authored
117
974fce3 @saltycrane PEP 8 cleanup
authored
118
ad71638 @saltycrane Added analyzer for "average upstream response time" that takes advant…
authored
119 class DfSource(SourceBase):
120 """Get data from "df"
121 """
ee9365e @saltycrane Fixed a bug in constructing the ssh command with no extra options. Re…
authored
122 def __init__(self, ssh_params, filepath, encoding='utf-8'):
123 self.ssh_params = ssh_params
ad71638 @saltycrane Added analyzer for "average upstream response time" that takes advant…
authored
124 self.encoding = encoding
125 self.cmd = 'while [ 1 ]; do df %s; sleep 60; done' % filepath
126
127 def filter(self, line):
128 if line.startswith('Filesystem'):
129 return ''
130 else:
131 return line
Something went wrong with that request. Please try again.