-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstackstorm_exporter.py
55 lines (40 loc) · 1.66 KB
/
stackstorm_exporter.py
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import requests
import time
import json
import prometheus_client
from prometheus_client import start_http_server, Metric, REGISTRY
class JsonCollector(object):
def __init__(self):
pass
def collect(self):
#Get the Json from st2 api
st2_host = os.environ.get('ST2_HOST', 'http://localhost/')
st2_api_key = os.environ.get('ST2_API_KEY')
st2_host_url = st2_host.rstrip("/")
headers = {'St2-Api-Key': st2_api_key }
status = 'running'
url = st2_host + '/api/v1/executions?status=' + status + '&parent=null'
r = requests.get(url, headers=headers, verify=False)
metric = Metric('jobs_running', 'Current Jobs Running', 'gauge')
metric.add_sample('jobs_running', value=float(len(r.json())), labels={})
yield metric
status = 'failed'
url = st2_host + '/api/v1/executions?status=' + status + '&parent=null'
r = requests.get(url, headers=headers, verify=False)
metric = Metric('jobs_failed', 'Number of failed jobs', 'gauge')
metric.add_sample('jobs_failed', value=float(len(r.json())), labels={})
yield metric
status = 'succeeded'
url = st2_host + '/api/v1/executions?status=' + status + '&parent=null'
r = requests.get(url, headers=headers, verify=False)
metric = Metric('jobs_succeeded', 'Number of failed jobs', 'gauge')
metric.add_sample('jobs_succeeded', value=float(len(r.json())), labels={})
yield metric
if __name__ == "__main__":
start_http_server(8000)
REGISTRY.register(JsonCollector())
while True: time.sleep(1)