Skip to content

Commit 9d16a56

Browse files
committed
Use gnlpy.ipvs module to fetch LVS information
1 parent 8efb11a commit 9d16a56

File tree

3 files changed

+34
-47
lines changed

3 files changed

+34
-47
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "ansible/roles/proxy-munin-node/files/monitoring-munin-haproxy"]
1111
path = ansible/roles/proxy-munin-node/files/monitoring-munin-haproxy
1212
url = https://github.com/mit-scripts/monitoring-munin-haproxy.git
13+
[submodule "ansible/roles/ldirectord-status/files/ldirectord-status/gnlpy"]
14+
path = ansible/roles/ldirectord-status/files/ldirectord-status/gnlpy
15+
url = https://github.com/facebook/gnlpy.git

ansible/roles/ldirectord-status/files/ldirectord-status/ldirectord-http.py

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,38 @@
44
import subprocess
55
import re
66
import socket
7+
from gnlpy import ipvs
78

8-
# Ignore the input from the finger protocol
9-
sys.stdin.readline()
9+
# Ignore the HTTP request
10+
while sys.stdin.readline().strip():
11+
pass
1012

11-
print("HTTP/1.0 200 OK")
12-
print("Content-type: text/html")
13-
print("")
13+
print("HTTP/1.0 200 OK\r")
14+
print("Content-type: text/html\r")
15+
print("\r")
1416
print("<html><head><title>scripts.mit.edu server status</title></head><body><h1>scripts.mit.edu server status</h1><p>The following table shows a list of the servers that are currently handling web requests for scripts.mit.edu:</p>")
15-
lines = subprocess.check_output(['/sbin/ipvsadm', '-L', '-n']).split(b'\n')
16-
realserver = re.compile('( -> )([^:]*):([^ ]*) *[^ ]* *([^ ]*) *([^ ]*) *([^ ]*)')
17-
fwm = re.compile('^FWM ([0-9]*)')
18-
ipaddress = re.compile('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
19-
show = 1
20-
header = ''
21-
for line in lines:
22-
line = line.decode('utf8')
23-
fwmline = fwm.match(line)
24-
if fwmline:
25-
if show:
26-
print("</table>")
27-
mark = fwmline.group(1)
28-
show = 1
29-
if mark == '22':
30-
pool = 'Fedora 20'
31-
elif mark == '32':
32-
pool = 'Fedora 30'
33-
else:
34-
show = 0
35-
if show:
36-
print("<p><b>%s servers</b></p><table>" % (pool))
37-
print(header)
38-
elif show:
39-
realline = realserver.match(line)
40-
if not realline:
41-
continue
42-
(preamble, ip, port, weight, inactive, active) = realline.groups()
43-
target = ip
44-
if ipaddress.match(ip):
45-
try:
46-
target = socket.gethostbyaddr(ip)[0]
47-
except:
48-
pass
49-
line = '<tr><td>' + target + '</td><td>' + weight + '</td><td>'
50-
line += inactive + '</td><td>' + active + '</td></tr>'
51-
if not header: # The header isn't set yet - this is it!
52-
header = line
53-
show = 0
54-
else:
55-
print(line)
56-
if show:
17+
18+
def row(target, weight, inactive, active):
19+
try:
20+
target = socket.gethostbyaddr(target)[0]
21+
except:
22+
pass
23+
line = '<tr><td>' + target + '</td><td>' + str(weight) + '</td><td>'
24+
line += str(inactive) + '</td><td>' + str(active) + '</td></tr>'
25+
return line
26+
27+
pools = ipvs.IpvsClient().get_pools()
28+
for pool in pools:
29+
mark = pool.service().fwmark()
30+
if mark == 22:
31+
pool_name = 'Fedora 20'
32+
elif mark == 32:
33+
pool_name = 'Fedora 30'
34+
# TODO: Add query parameter/URL for all pools?
35+
else:
36+
continue
37+
print("<table><tr style='text-align: left'><th>%s servers</th><th>Weight</th><th>ActiveConn</th><th>InActConn</th></tr>" % (pool_name,))
38+
for dest in pool.dests():
39+
print(row(dest.ip(), dest.weight(), dest.counters().get('active_conns', 0), dest.counters().get('inact_conns', 0)))
5740
print("</table>")
5841
print("</body></html>")

0 commit comments

Comments
 (0)