-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathaurora.py
More file actions
51 lines (40 loc) · 1.58 KB
/
aurora.py
File metadata and controls
51 lines (40 loc) · 1.58 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
import diamond.collector
from urllib.request import urlopen
class AuroraCollector(diamond.collector.Collector):
def get_default_config_help(self):
config_help = super(AuroraCollector,
self).get_default_config_help()
config_help.update({
'host': 'Scheduler Hostname',
'port': 'Scheduler HTTP Metrics Port',
'path': 'Collector path. Defaults to "aurora"',
'scheme': 'http'
})
return config_help
def get_default_config(self):
config = super(AuroraCollector, self).get_default_config()
config.update({
'path': 'aurora',
'host': 'localhost',
'port': 8081,
'scheme': 'http'
})
return config
def collect(self):
url = "%s://%s:%s/vars" % (self.config['scheme'],
self.config['host'],
self.config['port'])
response = urlopen(url)
for line in response.readlines():
properties = line.split()
# Not all lines returned will have a numeric metric.
# To account for this, we attempt to cast the 'value'
# portion as a float. If that's not possible, NBD, we
# just move on.
try:
if len(properties) > 1:
subpath = properties[0].replace('/', '.').replace('_', '.')
value = float(properties[1])
self.publish(subpath, value)
except ValueError:
continue