Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
ctl.send_block(cmd="stats", flags=ctl_flags)
global_stats = ctl.receive_stats()
except:
pass
# Get zone metrics.
zone_stats = dict()
try:
ctl.send_block(cmd="zone-stats", flags=ctl_flags)
zone_stats = ctl.receive_stats()
except:
pass
# Disconnect from the server.
ctl.send(libknot.control.KnotCtlType.END)
ctl.close()
# Publish the stats.
stats = {**global_stats, **zone_stats}
self.wfile.write(bytes(json.dumps(stats, indent=4, sort_keys=True), "utf-8"))
try:
ctl.send_block(cmd="stats", flags="F")
global_stats = ctl.receive_stats()
except:
pass
# Get zone metrics.
zone_stats = dict()
try:
ctl.send_block(cmd="zone-stats", flags="F")
zone_stats = ctl.receive_stats()
except:
pass
# Disconnect from the server.
ctl.send(libknot.control.KnotCtlType.END)
ctl.close()
# Prepare the metrics to publish.
output = io.StringIO()
stats = {**global_stats, **zone_stats}
timestamp = str(int(time.time()))
for metric in stats["server"]:
print("server,instance=" + instance + ",metric=" + metric + " value=" +
stats["server"][metric] + " " + timestamp, file=output)
for group in stats["mod-stats"]:
for metric in stats["mod-stats"][group]:
print(group + ",instance=" + instance + ",metric=" + metric +
" value=" + stats["mod-stats"][group][metric] + " " + timestamp,