@cryptotaxi247 / netdata-1 / commits / 9c334bb2e

varnish module: add instance_name option (#5264)

* add instance_name option * add timeout * minor

Ilya Mashchenko committed Jan 31, 2019 at 16:02 UTC 9c334bb2ef4b8562fe5c28dab94579288ed467c1
3 files changed +30 -6
collectors/python.d.plugin/varnish/README.md
+7 -1
@@ -64,7 +64,13 @@ It produces:
64
65 ### configuration
66
67 -No configuration is needed.
67 +Only one parameter is supported:
68 +
69 +```yaml
70 +instance_name: 'name'
71 +```
72 +
73 +The name of the varnishd instance to get logs from. If not specified, the host name is used.
74
75 ---
76
collectors/python.d.plugin/varnish/varnish.chart.py
+19 -5
@@ -136,6 +136,8 @@ CHARTS = {
136 }
137 }
138
139 +VARNISHSTAT = 'varnishstat'
140 +
141
142 class Parser:
143 _backend_new = re.compile(r'VBE.([\d\w_.]+)\(.*?\).(beresp[\w_]+)\s+(\d+)')
@@ -172,19 +174,31 @@ class Service(ExecutableService):
174 ExecutableService.__init__(self, configuration=configuration, name=name)
175 self.order = ORDER
176 self.definitions = CHARTS
175 - varnishstat = find_binary('varnishstat')
176 - self.command = [varnishstat, '-1'] if varnishstat else None
177 + self.instance_name = configuration.get('instance_name')
178 self.parser = Parser()
179 + self.command = None
180 +
181 + def create_command(self):
182 + varnishstat = find_binary(VARNISHSTAT)
183 +
184 + if not varnishstat:
185 + self.error("can't locate '{0}' binary or binary is not executable by user netdata".format(VARNISHSTAT))
186 + return False
187 +
188 + if self.instance_name:
189 + self.command = [varnishstat, '-1', '-n', self.instance_name, '-t', '1']
190 + else:
191 + self.command = [varnishstat, '-1', '-t', '1']
192 + return True
193
194 def check(self):
180 - if not self.command:
181 - self.error("Can't locate 'varnishstat' binary or binary is not executable by user netdata")
195 + if not self.create_command():
196 return False
197
198 # STDOUT is not empty
199 reply = self._get_raw_data()
200 if not reply:
187 - self.error("No output from 'varnishstat'. Not enough privileges?")
201 + self.error("No output from 'varnishstat'. Is it running? Not enough privileges?")
202 return False
203
204 self.parser.init(reply)
collectors/python.d.plugin/varnish/varnish.conf
+4
@@ -59,4 +59,8 @@
59 # penalty: yes # the JOB's penalty
60 # autodetection_retry: 0 # the JOB's re-check interval in seconds
61 #
62 +# Additionally to the above, varnish also supports the following:
63 +#
64 +# instance_name: 'name' # the name of the varnishd instance to get logs from. If not specified, the host name is used.
65 +#
66 # ----------------------------------------------------------------------