-
Notifications
You must be signed in to change notification settings - Fork 1
/
apm-report.py
149 lines (136 loc) · 3.98 KB
/
apm-report.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
import os
import csv
from python_graphql_client import GraphqlClient
FORMATTED_CSV_ORDER = [
'Tribe',
'Squad',
'squad',
'name',
'reporting',
'language',
'Environment',
'Application',
'applicationId',
'Cost-Center',
'feature',
'Location',
'accountid',
'Service',
'trustedAccountId',
'feature',
'account',
'squad',
'Alerting',
'Contact',
'guid',
'accountId',
'permalink',
'has_traces',
'apmSummary_apdexScore',
'apmSummary_errorRate',
'apmSummary_hostCount',
'apmSummary_instanceCount',
'apmSummary_nonWebThroughput',
'apmSummary_Throughput',
'apmSummary_webThroughput',
]
def get_trace_app_index():
# This file was generated by the following query:
# FROM TransactionTrace select count(*) facet applicationIds since 3 days ago limit max
#
with open('traces_by_app.csv', 'r') as f:
app_index = set()
reader = csv.DictReader(f)
for row in reader:
apps = (row['Application Ids']).split(":")
for app in apps:
if app:
app_index.add(int(app))
#print(app_index)
return app_index
def get_apm_metadata():
headers = {}
headers['Api-Key'] = os.getenv('USER_API_KEY')
headers['Content-Type'] = 'application/json'
client = GraphqlClient(endpoint="https://api.newrelic.com/graphql")
client.headers=headers
query = """
{
actor {
entitySearch(queryBuilder: {domain: APM, type: APPLICATION, name: ""}) {
results {
entities {
tags {
key
values
}
guid
name
reporting
permalink
accountId
account {
id
name
}
... on ApmApplicationEntityOutline {
guid
name
apmSummary {
apdexScore
errorRate
hostCount
instanceCount
nonWebResponseTimeAverage
nonWebThroughput
responseTimeAverage
throughput
webResponseTimeAverage
webThroughput
}
applicationId
}
}
}
}
}
}
"""
_result = client.execute(query=query)
return [data for data in _result['data']['actor']['entitySearch']['results']['entities']]
apps_with_traces = get_trace_app_index()
data = get_apm_metadata()
key_set = set()
apm_objects = []
for item in data:
scrubbed = {}
scrubbed['Tribe'] = 'UNKNOWN'
scrubbed['reporting'] = False
scrubbed['accountid'] = item['account']['id']
scrubbed['account'] = item['account']['name']
scrubbed['name'] = item['name']
scrubbed['applicationId'] = item['applicationId']
if item['applicationId'] in apps_with_traces:
scrubbed['has_traces'] = True
else:
scrubbed['has_traces'] = False
if (item['apmSummary']):
scrubbed['apmSummary_apdexScore'] = item['apmSummary']['apdexScore']
scrubbed['apmSummary_errorRate'] = item['apmSummary']['errorRate']
scrubbed['apmSummary_hostCount'] = item['apmSummary']['hostCount']
scrubbed['apmSummary_instanceCount'] = item['apmSummary']['instanceCount']
scrubbed['apmSummary_nonWebThroughput'] = item['apmSummary']['nonWebThroughput']
scrubbed['apmSummary_Throughput'] = item['apmSummary']['throughput']
scrubbed['apmSummary_webThroughput'] = item['apmSummary']['webThroughput']
scrubbed['reporting'] = item['reporting']
scrubbed['permalink'] = item['permalink']
for tag in item['tags']:
scrubbed[tag['key']] = tag['values'][0]
for k in scrubbed.keys():
key_set.add(k)
apm_objects.append(scrubbed)
apm_objects.sort(key = lambda i: (i['Tribe'], i['reporting']))
with open('apm-report.csv', 'w') as f:
w = csv.DictWriter(f, FORMATTED_CSV_ORDER, extrasaction='ignore')
w.writeheader()
w.writerows(apm_objects)