forked from openwallet-foundation/acapy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.py
94 lines (88 loc) · 2.35 KB
/
search.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
import csv
from elasticsearch_dsl import connections
from elasticsearch_dsl import Search
connections.create_connection(hosts=["localhost"], timeout=20)
s = Search(index="fluentd-*")
# only return the selected fields
s = s.source(
[
"str_time",
"timestamp",
"handler",
"ellapsed_milli",
"thread_id",
"msg_id",
"outcome",
"traced_type",
]
)
s = s.sort("timestamp")
events = []
for x in s.scan():
events.append(
{
"str_time": x.str_time,
"timestamp": x.timestamp,
"handler": x.handler,
"ellapsed_milli": x.ellapsed_milli,
"thread_id": x.thread_id,
"msg_id": x.msg_id,
"outcome": x.outcome,
"traced_type": x.traced_type,
}
)
sorted_events = sorted(events, key=lambda i: i["timestamp"])
threads = {}
thread_count = 0
agents = {}
with open("agent-events.csv", "w", newline="") as csvfile:
spamwriter = csv.writer(csvfile)
i = 0
spamwriter.writerow(
[
"idx",
"str_time",
"timestamp",
"handler",
"ellapsed_milli",
"thread_id",
"msg_id",
"outcome",
"traced_type",
"delta_agent",
"delta_thread",
]
)
for x in sorted_events:
if x["handler"] in agents:
delta_agent = x["timestamp"] - agents[x["handler"]]
if delta_agent < 0:
print(i, delta_agent)
else:
delta_agent = 0
agents[x["handler"]] = x["timestamp"]
if x["thread_id"] in threads:
delta_thread = x["timestamp"] - threads[x["thread_id"]]
if delta_thread < 0:
print(i, delta_thread)
else:
delta_thread = 0
thread_count = thread_count + 1
threads[x["thread_id"]] = x["timestamp"]
i = i + 1
spamwriter.writerow(
[
i,
x["str_time"],
x["timestamp"],
x["handler"],
x["ellapsed_milli"],
x["thread_id"],
x["msg_id"],
x["outcome"],
x["traced_type"],
delta_agent,
delta_thread,
]
)
print("Total threads=", thread_count)