@@ -9,6 +9,7 @@ import urllib
99from prometheus_client import start_http_server
1010from prometheus_client .core import CounterMetricFamily , GaugeMetricFamily , REGISTRY
1111
12+
1213class TinyproxyCollector (object ):
1314 def __init__ (self , stathost , tinyproxy ):
1415 self .stathost = stathost
@@ -19,29 +20,43 @@ class TinyproxyCollector(object):
1920 opener = urllib .request .build_opener (handler )
2021 urllib .request .install_opener (opener )
2122 response = urllib .request .urlopen ('http://{0}' .format (self .stathost ))
22- values = [float (x ) for x in re .findall (b'(?:<td>|: )(\d+)(?:</td>|<br />|\n </p>)' , response .read ())]
23- yield GaugeMetricFamily ('tinyproxy_connections_open' , 'Number of open connections' , values [0 ])
24- yield CounterMetricFamily ('tinyproxy_requests_total' , 'Number of requests' , values [1 ])
25- yield CounterMetricFamily ('tinyproxy_connections_bad_total' , 'Number of bad connections' , values [2 ])
26- yield CounterMetricFamily ('tinyproxy_connections_denied_total' , 'Number of denied connections' , values [3 ])
27- yield CounterMetricFamily ('tinyproxy_connections_refused_total' , 'Number of refused connections due to high load' , values [4 ])
23+ values = [
24+ float (x ) for x in re .findall (
25+ b'(?:<td>|: )(\d+)(?:</td>|<br />|\n </p>)' , response .read ())
26+ ]
27+ yield GaugeMetricFamily ('tinyproxy_connections_open' ,
28+ 'Number of open connections' , values [0 ])
29+ yield CounterMetricFamily ('tinyproxy_requests_total' ,
30+ 'Number of requests' , values [1 ])
31+ yield CounterMetricFamily ('tinyproxy_connections_bad_total' ,
32+ 'Number of bad connections' , values [2 ])
33+ yield CounterMetricFamily ('tinyproxy_connections_denied_total' ,
34+ 'Number of denied connections' , values [3 ])
35+ yield CounterMetricFamily (
36+ 'tinyproxy_connections_refused_total' ,
37+ 'Number of refused connections due to high load' , values [4 ])
38+
2839
2940def parse_args ():
30- parser = argparse .ArgumentParser (description = 'Prometheus exporter for Tinyproxy.' )
31- parser .add_argument (
32- '-l' , metavar = 'LISTEN' , default = ':9240' ,
33- help = 'address on which to expose metrics (default ":9240")'
34- )
41+ parser = argparse .ArgumentParser (
42+ description = 'Prometheus exporter for Tinyproxy.' )
3543 parser .add_argument (
36- '-s' , metavar = 'STATHOST' , default = 'tinyproxy.stats' ,
37- help = 'internal statistics page address (default "tinyproxy.stats")'
38- )
44+ '-l' ,
45+ metavar = 'LISTEN' ,
46+ default = ':9240' ,
47+ help = 'address on which to expose metrics (default ":9240")' )
3948 parser .add_argument (
40- '-t' , metavar = 'TINYPROXY' , default = '127.0.0.1:8888' ,
41- help = 'tinyproxy address (default "127.0.0.1:8888")'
42- )
49+ '-s' ,
50+ metavar = 'STATHOST' ,
51+ default = 'tinyproxy.stats' ,
52+ help = 'internal statistics page address (default "tinyproxy.stats")' )
53+ parser .add_argument ('-t' ,
54+ metavar = 'TINYPROXY' ,
55+ default = '127.0.0.1:8888' ,
56+ help = 'tinyproxy address (default "127.0.0.1:8888")' )
4357 return parser .parse_args ()
4458
59+
4560def main ():
4661 try :
4762 args = parse_args ()
@@ -54,5 +69,6 @@ def main():
5469 print (' Interrupted' )
5570 sys .exit (0 )
5671
72+
5773if __name__ == '__main__' :
5874 main ()
0 commit comments