Created
March 18, 2016 23:04
-
-
Save krislindgren/3a9f8fb57ff7ea5add8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"stats":{ | |
"bytes_in":0, | |
"full_lb_data":{ | |
"loadbalancer_stat":{ | |
"status":"PARTIAL_UP", | |
"resp_bytes":0, | |
"name":"d991d466-4266-4ee9-bc23-127e2bf1ab16", | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"listener_stat":[ | |
{ | |
"status":"DOWN", | |
"protocol":2, | |
"name":"6bfb6333-be38-4ca9-a6ef-3305c54ada22", | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"total_reqs_succ":0, | |
"req_pkts":0, | |
"pool_stat_list":{ | |
"status":"DOWN", | |
"protocol":2, | |
"name":"f219294f-e571-450e-b6d9-3579ba75cc20", | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"total_reqs_succ":0, | |
"req_pkts":0, | |
"req_bytes":0, | |
"member_stat_list":[ | |
{ | |
"status":"DOWN", | |
"resp_bytes":0, | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"server":"_0f9e9_10_224_51_190_neutron", | |
"req_pkts":0, | |
"req_bytes":0, | |
"total_reqs_succ":0, | |
"tot_conns":0, | |
"port":8080 | |
} | |
], | |
"resp_bytes":0, | |
"tot_conns":0 | |
}, | |
"req_bytes":0, | |
"resp_bytes":0, | |
"tot_conns":0, | |
"port":8080 | |
}, | |
{ | |
"status":"ALL_UP", | |
"protocol":2, | |
"name":"dc63d30f-edfc-42da-8616-9f4baa220245", | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"total_reqs_succ":0, | |
"req_pkts":0, | |
"pool_stat_list":{ | |
"status":"ALL_UP", | |
"protocol":2, | |
"name":"6c0c1fa3-cc37-4eb6-ae58-37312d918c70", | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"total_reqs_succ":0, | |
"req_pkts":0, | |
"req_bytes":0, | |
"member_stat_list":[ | |
{ | |
"status":"ALL_UP", | |
"resp_bytes":0, | |
"cur_reqs":0, | |
"resp_pkts":0, | |
"cur_conns":0, | |
"total_reqs":0, | |
"server":"_336c0_10_224_51_167_neutron", | |
"req_pkts":0, | |
"req_bytes":0, | |
"total_reqs_succ":0, | |
"tot_conns":0, | |
"port":80 | |
} | |
], | |
"resp_bytes":0, | |
"tot_conns":0 | |
}, | |
"req_bytes":0, | |
"resp_bytes":0, | |
"tot_conns":0, | |
"port":80 | |
} | |
], | |
"req_pkts":0, | |
"req_bytes":0, | |
"address":"10.250.17.39", | |
"total_reqs_succ":0, | |
"tot_conns":0 | |
} | |
}, | |
"total_connections":0, | |
"active_connections":0, | |
"bytes_out":0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STATUS_MAP = { | |
0: "DISABLED", | |
1: "ALL_UP", | |
2: "PARTIAL_UP", | |
3: "FUNC_UP", | |
4: "DOWN", | |
5: "UNKNOWN" | |
} | |
def replace_status(self, data): | |
if isinstance(data, list): | |
for member in data: | |
self.replace_status(member) | |
if isinstance(data, dict): | |
if 'status' in data: | |
lb_val = data['status'] | |
new_val = self.STATUS_MAP.get(lb_val, lb_val) | |
data['status'] = new_val | |
for item in data.itervalues(): | |
self.replace_status(item) | |
return data | |
def stats(self, context, lb): | |
with a10.A10Context(self, context, lb) as c: | |
try: | |
name = self.meta(lb, 'id', lb.id) | |
r = c.client.slb.virtual_server.stats(name) | |
f = r.copy() | |
for s in f["virtual_server_stat"]["vport_stat_list"]: | |
vs = c.client.slb.virtual_service.get(s["name"]) | |
p = c.client.slb.service_group.stats(vs["virtual_service"]["service_group"]) | |
p["pool_stat_list"] = p.pop("service_group_stat") | |
s.update(p) | |
f["virtual_server_stat"]["listener_stat"] = f["virtual_server_stat"].pop("vport_stat_list") | |
f["loadbalancer_stat"] = f.pop("virtual_server_stat") | |
return { | |
"bytes_in": r["virtual_server_stat"]["req_bytes"], | |
"bytes_out": r["virtual_server_stat"]["resp_bytes"], | |
"active_connections": | |
r["virtual_server_stat"]["cur_conns"], | |
"total_connections": r["virtual_server_stat"]["tot_conns"], | |
"full_lb_stats": self.replace_status(f) | |
} | |
except Exception: | |
return { | |
"bytes_in": 0, | |
"bytes_out": 0, | |
"active_connections": 0, | |
"total_connections": 0, | |
"full_lb_stats": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment