-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggr.awk
More file actions
44 lines (42 loc) · 1.58 KB
/
aggr.awk
File metadata and controls
44 lines (42 loc) · 1.58 KB
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
BEGIN{
node_name = ENVIRON["NODE_NAME"] ? ENVIRON["NODE_NAME"] : "edge";
col_time = ENVIRON["COL_TIME"] ? ENVIRON["COL_TIME"] : 3;
col_ip = ENVIRON["COL_IP"] ? ENVIRON["COL_IP"] : 1;
col_status = ENVIRON["COL_STATUS"] ? ENVIRON["COL_STATUS"] : 8;
server_addr = ENVIRON["VIZ_SERVER"] ? ENVIRON["VIZ_SERVER"] : "http://localhost:9009/liveReqStat";
aggr_interval = ENVIRON["AGGR_INTERVAL_SEC"] ? ENVIRON["AGGR_INTERVAL_SEC"] : 1 ;
lastTime = systime(); r200 = 0; r300 = 0; r400 = 0; r500 = 0; rOther = 0;
printf "%-30s %-5d %-5d %-5d %-5d %-5s\n","TIMESTAMP", 200, 300, 400, 500, "rOther";
}
{
# change timestamp and print aggregated
accTime = $col_time; srcIP = $col_ip; status = $col_status;
# if source ip is localhost, ignore.
if(srcIP == "127.0.0.1") next;
currTime = systime();
if(currTime - lastTime > aggr_interval){
printf "%-30s %-5d %-5d %-5d %-5d %-5d\n",accTime, r200, r300, r400, r500, rOther;
result = "{ \
\"node\":\"" node_name "\", \
\"interval\":" aggr_interval ", \
\"updated\":" currTime ", \
\"accTime\":\"" accTime "\", \
\"200\":" r200 ", \
\"300\":" r300", \
\"400\":" r400", \
\"500\":" r500", \
\"other\":" rOther" \
}"
system("curl -s -m 0.7 --retry 0 -d '" result "' -H 'Content-Type:application/json' -X POST " server_addr);
# reset timer
lastTime = currTime;
# reset metrics.
r200 = 0; r300 = 0; r400 = 0; r500 = 0; rOther = 0;
}
firstCode = substr(status,1,1);
if(firstCode == 2){ r200++; next; };
if(firstCode == 3){ r300++; next; };
if(firstCode == 4){ r400++; next; };
if(firstCode == 5){ r500++; next; };
rOther++;
}