-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoidToProm.py
More file actions
executable file
·73 lines (55 loc) · 1.89 KB
/
BoidToProm.py
File metadata and controls
executable file
·73 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""
This module grabs teamleaderboard information from api.boid.com and sends it to a prometheus pushgateway.
"""
__author__ = "ghobson"
__created__ = ""
__revision__ = ""
__date__ = ""
from prometheus_client import Enum, Gauge, Info, push_to_gateway, pushadd_to_gateway, CollectorRegistry
import requests, json, time, sys, getopt
PROMETHEUS_GATEWAY = '127.0.0.1:9091'
PROMETHEUS_JOB = 'boid'
REPORT_TYPE = 'api'
DEBUG = False
def debugmsg(someText):
if DEBUG:
sys.stderr.write(someText)
registry = CollectorRegistry()
bLabels = ['team_name', 'report_type']
boidTeamPowerGauge = Gauge('boid_team_power', 'total team boid power', bLabels, registry=registry)
boidTeamBonusGauge = Gauge('boid_team_bonus', 'team bonus', bLabels, registry=registry)
def logToPrometheus(line):
name = line['name']
power = float(line['power'])
bonus = float(line['bonus'])
boidTeamPowerGauge.labels(team_name=name, report_type=REPORT_TYPE).set(power)
boidTeamBonusGauge.labels(team_name=name, report_type=REPORT_TYPE).set(bonus)
if(DEBUG):
print(line)
return True
def promFlush():
pushadd_to_gateway(PROMETHEUS_GATEWAY, job=PROMETHEUS_JOB, registry=registry)
if __name__ == '__main__':
null = None
false = False
true = True # fix the json below
try:
opts, args = getopt.getopt(sys.argv[1:], "hdt:", ["help", "debug", "test"])
except getopt.error as msg:
print(msg)
sys.exit("Invalid arguments.")
for o, a in opts:
if o in ("-h", "--help"):
print("Usage: promgateway -d")
sys.exit()
if o in ("-d", "--debug"):
DEBUG = True
if o in ("-t", "--test"):
logToPrometheus(testToc)
promFlush()
sys.exit()
data = json.load(sys.stdin)
for team in data:
logToPrometheus(team)
promFlush()