1 # -*- coding: utf-8 -*-
2 # Description: squid netdata python.d plugin
3 # Author: Pawel Krupa (paulfantom)
5 from base import NetSocketService
7 # default module values (can be overridden per job in `config`)
12 # default job configuration (overridden by python.d.plugin)
13 # config = {'local': {
14 # 'update_every': update_every,
16 # 'priority': priority,
17 # 'url': 'http://localhost/stub_status'
20 # charts order (can be overridden if you want less charts, or different order)
21 ORDER = ['clients_net', 'clients_requests', 'servers_net', 'servers_requests']
25 'options': [None, "Squid Client Bandwidth", "kilobits / sec", "clients", "squid.clients.net" "area"],
27 ["client_http_kbytes_in", "in", "incremental", 8, 1],
28 ["client_http_kbytes_out", "out", "incremental", -8, 1],
29 ["client_http_hit_kbytes_out", "hits", "incremental", -8, 1]
32 'options': [None, "Squid Client Requests", "requests / sec", "clients", "squid.clients.requests", 'line'],
34 ["client_http_requests", "requests"],
35 ["client_http_hits", "hits"],
36 ["client_http_errors", "errors", "incremental", -1, 1]
39 'options': [None, "Squid Server Bandwidth", "kilobits / sec", "servers", "squid.servers.net" "area"],
41 ["server_all_kbytes_in", "in", "incremental", 8, 1],
42 ["server_all_kbytes_out", "out", "incremental", -8, 1]
45 'options': [None, "Squid Server Requests", "requests / sec", "servers", "squid.servers.requests", 'line'],
47 ["server_all_requests", "requests"],
48 ["server_all_errors", "errors", "incremental", -1, 1]
53 class Service(NetSocketService):
54 def __init__(self, configuration=None, name=None):
55 NetSocketService.__init__(self, configuration=configuration, name=name)
57 self.host = "localhost"
58 self.port = (3128, 8080)
60 self.definitions = CHARTS
64 Get data from http request
68 raw = self._get_raw_data().split('\n')
69 if "200 OK" not in raw[0]:
73 if row.startswith(("client", "server.all")):
75 data[tmp[0].replace('.', '_').strip(' ')] = int(tmp[1])
78 except (ValueError, AttributeError):
85 if not self.request.startswith("GET"):
86 self.request = "GET " + self.request
87 if not self.request.endswith(" HTTP/1.0\r\n\r\n"):
88 self.request += " HTTP/1.0\r\n\r\n"
89 self.request = self.request.encode()
92 if type(self.port) is tuple:
96 urls = ["cache_object://" + self.host + ":" + str(port) + "/counters",
97 "/squid-internal-mgr/counters"]
99 tmp = "GET " + url + " HTTP/1.0\r\n\r\n"
100 self.request = tmp.encode()
101 if self._get_data() is not None:
104 if self._get_data() is not None: