1cf9b5efeb2f979fd37d4a85b97a4fa8345f56c4
[vpproxy.git] / plugins / stat_plugin.py
1 '''
2 Simple statistics plugin
3
4 To use it, go to http://127.0.0.1:8000/stat
5 '''
6 from modules.PluginInterface import VPProxyPlugin
7
8
9 class Stat(VPProxyPlugin):
10     handlers = ('stat', )
11
12     def __init__(self, VPConfig, VPStuff):
13         self.config = VPConfig
14         self.stuff = VPStuff
15
16     def handle(self, connection):
17         connection.send_response(200)
18         connection.send_header('Content-type', 'text/html')
19         connection.end_headers()
20         connection.wfile.write(
21             '<html><body><h4>Connected clients: ' + str(self.stuff.clientcounter.total) + '</h4>')
22         connection.wfile.write(
23             '<h5>Concurrent connections limit: ' + str(self.config.maxconns) + '</h5>')
24         for i in self.stuff.clientcounter.clients:
25             connection.wfile.write(str(i) + ' : ' + str(self.stuff.clientcounter.clients[i][0]) + ' ' +
26                                    str(self.stuff.clientcounter.clients[i][1]) + '<br>')
27         connection.wfile.write('</body></html>')