-
Notifications
You must be signed in to change notification settings - Fork 2
/
geckoboard.py
408 lines (378 loc) · 12.2 KB
/
geckoboard.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#! /usr/bin/python
import unirest, json, time, urllib2
from datetime import datetime
from urllib2 import urlopen
from timeit import Timer
#####################################
geckoboard_key = 'EDIT ME!' #geckoboard api key, find from geckoboard portal
appId = 'EDIT ME!' #appid of crittercism registered app
access_token = 'EDIT ME!' #request access_token by using the provided client id
#####################################
#get and push api status
url = 'https://developers.crittercism.com:443/v1.0/base'
request_api = urllib2.Request(url)
response_api = json.load(urllib2.urlopen(request_api))
#get response time
def fetch():
response_page = urlopen(url)
timer = Timer(fetch)
response_time = timer.timeit(1)
#get api status
status = response_api['status']
if status == 'active':
status = "Up"
else:
status = "Down"
#push api status
"""create monitoring widget"""
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-129ea4fa-9a17-4f61-801b-a377c60e9b67",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"status": status,
"downTime": "",
"responseTime": "%.3f" % response_time
}}))
#fetch daily app loads
def fetch_daily_appLoads(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/graph",
headers={
"Content-Type": "application/json",
"Authorization" : "Bearer %s" % access_token
},
params=json.dumps({"params":{
"graph": "appLoads",
"duration": 1440,
"appId": appId,
}})
)
try:
return response.body['data']['series'][0]['points'][0]
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_app_loads')
return None
#push daily app loads
"""create number widget"""
def push_daily_appLoads(appLoads):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-3ace4a63-945e-423f-88c3-c7c9c6325374",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"item": [
{
"value": appLoads,
"text": "Daily App Loads"
}
]
}}))
#fetch daily app crashes
def fetch_daily_app_crashes(access_token,appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/graph",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer %s" % access_token
},
params=json.dumps({"params":{
"graph": "crashes",
"duration": 1440,
"appId": appId
}})
)
try:
return response.body['data']['series'][0]['points'][0]
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_app_crashes')
return None
#push daily app crashes
"""create number widget"""
def push_daily_app_crashes(crashes):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-dc7d33b9-4023-4c1f-acc7-9559cd804671",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"item": [
{
"value": crashes,
"text": "Daily App Crashes"
}
]
}}))
#fetch daily active users
def fetch_daily_active_users(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/graph",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer %s" % access_token
},
params=json.dumps({"params":{
"graph": "dau",
"duration": 1440,
"appId": appId
}})
)
try:
return response.body['data']['series'][0]['points'][0]
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_app_loads')
return None
#push daily active users
"""create number widget"""
def push_daily_active_users(dau):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-64e65b64-30f5-46f0-9edb-43b25d5f6c10",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"item": [
{
"value": dau,
"text": "Daily Active Users"
}
]
}}))
#fetch daily crash percent
def fetch_daily_crash_percent(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/graph",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer %s" % access_token
},
params=json.dumps({"params":{
"value_type": "percent",
"graph": "crashPercent",
"duration": 1440,
"appId": appId
}})
)
try:
crash_rate = float(response.body['data']['series'][0]['points'][0])
return crash_rate / 100
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_crash_percent')
return None
#push daily crash percent
"""create number widget"""
def push_daily_crash_percent(crash_rate):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-05aaac70-bb20-4533-a129-03a6fe9fabb5",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"item": [
{
"value": crash_rate,
"text": "Daily Crash Rate"
}
]
}}))
#fetch daily crashes by os
def fetch_daily_crashes_os(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/pie",
headers={
"Content-Type": "application/json",
"Authorization" : "Bearer %s" % access_token
},
params=json.dumps({"params":{
"graph": "crashes",
"duration": 1440,
"groupBy": "os",
"appId": appId
}})
)
os_list = []
try:
for series in response.body['data']['slices']:
os_list.append((series['label'], series['value']))
os_list = sorted(os_list, key=lambda x: x[1], reverse=True)[0:4]
return map(list, zip(*os_list))
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_crashes_os')
return [None, None]
#push daily crashes by os
"""create pie chart"""
def push_daily_crashes_os(os_list):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-941b1040-d241-4106-a78e-6603c2a29a53",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"item": [
{
"value": os_list[1][0], #os one value
"label": os_list[0][0], #os name
},
{
"value": os_list[1][1], #os two value
"label": os_list[0][1], #os name
},
{
"value": os_list[1][2], #os three value
"label": os_list[0][2], #os name
},
{
"value": os_list[1][3], #os three value
"label": os_list[0][3], #os name
}
]
}}))
#fetch daily app loads by device
def fetch_daily_app_loads_device(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/errorMonitoring/pie",
headers={
"Content-Type": "application/json",
"Authorization" : "Bearer %s" % access_token,
},
params=json.dumps({"params":{
"graph": "appLoads",
"duration": 1440,
"appId": appId,
"groupBy": "device"
}})
)
device_list = []
try:
for device in response.body['data']['slices']:
device_list.append((device['label'], device['value']))
device_list = sorted(device_list, key=lambda x: x[1], reverse=True)[0:5]
return map(list, zip(*device_list))
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_app_loads_device')
return [None, None]
#push daily app loads by device
"""create funnel chart since Geckoboard API has no bar chart"""
def push_daily_app_loads_device(device_list):
response = unirest.post(
# "https://push.geckoboard.com/v1/send/106305-6557c1f1-9c30-4701-8940-971fc1b7eb3c",
"https://push.geckoboard.com/v1/send/106305-58cd87cd-15ac-409a-a379-f7097abc1e9d",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
#"type": "reverse",
"percentage": "hide",
"item": [
{
"value": device_list[1][0], #apploads device one
"label": device_list[0][0] #device one name
},
{
"value": device_list[1][1], #apploads device two
"label": device_list[0][1] #device two name
},
{
"value": device_list[1][2], #apploads device three
"label": device_list[0][2] #device three name
},
{
"value": device_list[1][3], #apploads device four
"label": device_list[0][3] #device four name
},
{
"value": device_list[1][4], #apploads device five
"label": device_list[0][4] #device five name
}
]
}}))
#fetch service monitoring error rate (top three offenders)
def fetch_daily_service_monitoring_rate(access_token, appId):
response = unirest.post(
"https://developers.crittercism.com:443/v1.0/performanceManagement/pie",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer %s" % access_token,
},
params=json.dumps({"params":{
"groupBy": "service",
"graph": "errors",
"duration": 60,
"appId": appId
}})
)
service_list = []
try:
for service in response.body['data']['slices']:
service_list.append((service['label'], service['value']))
service_list = sorted(service_list, key=lambda x: x[1], reverse=True)[0:4]
return map(list, zip(*service_list))
except KeyError as e:
print 'ERROR: Could not access %s in %s.' % (str(e), 'fetch_daily_service_monitoring_rate')
return [None, None]
#push service monitoring error rate (top three offenders)
"""create funnel chart since Geckoboard API has no bar chart"""
def push_daily_service_monitoring_rate(service_list):
response = unirest.post(
"https://push.geckoboard.com/v1/send/106305-e02412d0-eef7-47a6-82f8-39b8e8d5efc6",
headers={"Accept": "application/json", "Content-Type": "application/json"},
params=json.dumps({
"api_key": geckoboard_key,
"data": {
"type": "reverse",
"percentage": "hide",
"item": [
{
"value": "%.2f" % service_list[1][0], #seconds
"label": service_list[0][0] #name of request
},
{
"value": "%.2f" % service_list[1][1], #seconds
"label": service_list[0][1] #name of request
},
{
"value": "%.2f" % service_list[1][2], #seconds
"label": service_list[0][2] #name of request
}
]
}}))
def main():
#updates daily app loads
appLoads = fetch_daily_appLoads(access_token, appId)
if appLoads is not None:
push_daily_appLoads(appLoads)
time.sleep(1)
#updates daily app crashes
crashes = fetch_daily_app_crashes(access_token, appId)
if crashes is not None:
push_daily_app_crashes(crashes)
time.sleep(1)
#updates daily active users
dau = fetch_daily_active_users(access_token, appId)
if dau is not None:
push_daily_active_users(dau)
time.sleep(1)
#updates daily crash percent
crash_rate = fetch_daily_crash_percent(access_token, appId)
if crash_rate is not None:
push_daily_crash_percent(crash_rate)
time.sleep(1)
#updates daily crashes by os
os_list = fetch_daily_crashes_os(access_token, appId)
if os_list is not None:
push_daily_crashes_os(os_list)
time.sleep(1)
#updates daily app loads by device
device_list = fetch_daily_app_loads_device(access_token, appId)
if device_list is not None:
push_daily_app_loads_device(device_list)
time.sleep(1)
#updates daily service monitoring rate (error rate)
service_list = fetch_daily_service_monitoring_rate(access_token, appId)
if service_list is not None:
push_daily_service_monitoring_rate(service_list)
time.sleep(1)
if __name__=='__main__':
main()