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 # charts order (can be overridden if you want less charts, or different order)
13 ORDER = ['clients_net', 'clients_requests', 'servers_net', 'servers_requests']
17 'options': [None, "Squid Client Bandwidth", "kilobits/s", "clients", "squid.clients.net" "area"],
19 ["client_http_kbytes_in", "in", "incremental", 8, 1],
20 ["client_http_kbytes_out", "out", "incremental", -8, 1],
21 ["client_http_hit_kbytes_out", "hits", "incremental", -8, 1]
24 'options': [None, "Squid Client Requests", "requests/s", "clients", "squid.clients.requests", 'line'],
26 ["client_http_requests", "requests"],
27 ["client_http_hits", "hits"],
28 ["client_http_errors", "errors", "incremental", -1, 1]
31 'options': [None, "Squid Server Bandwidth", "kilobits/s", "servers", "squid.servers.net" "area"],
33 ["server_all_kbytes_in", "in", "incremental", 8, 1],
34 ["server_all_kbytes_out", "out", "incremental", -8, 1]
37 'options': [None, "Squid Server Requests", "requests/s", "servers", "squid.servers.requests", 'line'],
39 ["server_all_requests", "requests"],
40 ["server_all_errors", "errors", "incremental", -1, 1]
45 class Service(NetSocketService):
46 def __init__(self, configuration=None, name=None):
47 NetSocketService.__init__(self, configuration=configuration, name=name)
49 self.host = "localhost"
52 self.definitions = CHARTS
56 Get data via http request
60 raw = self._get_raw_data().split('\n')
61 if "200 OK" not in raw[0]:
65 if row.startswith(("client", "server.all")):
67 data[tmp[0].replace('.', '_').strip(' ')] = int(tmp[1])
70 except (ValueError, AttributeError):
75 Parse essential configuration, autodetect squid configuration (if needed), and check if data is available
80 req = self.request.decode()
81 if not req.startswith("GET"):
83 if not req.endswith(" HTTP/1.0\r\n\r\n"):
84 req += " HTTP/1.0\r\n\r\n"
85 self.request = req.encode()
88 # if type(self.port) is tuple:
92 # urls = ["cache_object://" + self.host + ":" + str(port) + "/counters",
93 # "/squid-internal-mgr/counters"]
95 # tmp = "GET " + url + " HTTP/1.0\r\n\r\n"
96 # self.request = tmp.encode()
97 # if self._get_data() is not None:
101 if self._get_data() is not None: