-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_analytics.py
60 lines (44 loc) · 1.71 KB
/
user_analytics.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
from intermix import intermix
import settings
import datetime
import time
def main():
im = intermix(settings.API_TOKEN)
CLUSTER_ID = settings.CLUSTER_ID
users = im.get_users(CLUSTER_ID)
current_time = datetime.datetime.now()
params = {
"startDate": (current_time - datetime.timedelta(days=7)).strftime("%Y-%m-%dT%H:%M:%S"),
"endDate": current_time.strftime("%Y-%m-%dT%H:%M:%S"),
"resource": "query",
"users": None,
"dataPoints": 1,
"conjunction": "and"
}
template_query_count_new = "%(cluster_type)s/%(cluster_id)s/analytics"
print "User Query Analytics for Cluster {0}\n".format(CLUSTER_ID)
results = []
for userobject in users:
params["users"] = userobject["id"]
data = im.api_request(cluster_id=CLUSTER_ID, template=template_query_count_new, params=params)
time.sleep(0.1) # API load
serialized_data = {
"id": userobject["id"],
"username": userobject["username"],
"count": data["data"][0]["count"],
"avg_memory_MB": data["data"][0]["avg_memory"],
"avg_rows": data["data"][0]["avg_rows"],
"num_aborted": data["data"][0]["num_aborted"],
"num_diskbased": data["data"][0]["num_diskbased"],
"avg_queue_time_us": data["data"][0]["avg_queue_time"],
"avg_exec_time_us": data["data"][0]["avg_exec_time"],
"avg_duration_us": data["data"][0]["avg_duration"]
}
results.append(serialized_data)
# header
print "{}".format((",".join(list(results[0].keys()))))
# rows
for r in results:
print "{}".format((",".join(map(str,r.values()))))
if __name__ == "__main__":
main()