Добавлен юнит для systemd
[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         connection.wfile.write('<table border="1"><tr><th>url</th><th>count</th><th>clients</th></tr>')
25         for i in self.stuff.clientcounter.clients:
26           connection.wfile.write('<tr>')
27           connection.wfile.write('<td>' + str(i) + ' </td><td> ' + str(self.stuff.clientcounter.clients[i][0]) + '</td><td>')
28           for client in self.stuff.clientcounter.clients[i][1]:
29             connection.wfile.write(str(client) + '<br>')
30           connection.wfile.write('</td></tr>')
31         connection.wfile.write('</table>')
32         connection.wfile.write('</body></html>')