-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (111 loc) · 3.42 KB
/
Makefile
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
SHELL := /usr/bin/zsh
# output folder
DIST := dist
# num_pings
N := 64
ip = ip a | grep -o '172\.27\.21\....'
IP := $(shell $(ip))
SKIP := $(shell $(ip) | awk -F. '{print $$4}')
SERVERS := $(shell seq 145 154 | sed '/${SKIP}/d')
hostname = 172.27.21.$1
## Create Reports
## ====================================================
DATE_TM := $(shell date +%Y%m%d-%H%M%S)
REPORTS := ${SERVERS:%=${DIST}/report.%.txt}
all : ${DIST}/${DATE_TM}.ping_report.txt
${DIST}/${DATE_TM}.ping_report.txt : ${REPORTS}
cat $^ > $@
.INTERMEDIATE: ${REPORTS}
${DIST}/report.%.txt : ${DIST}
ping -c $N $(call hostname,$*) \
| tail -n4 \
> $@
${DIST} :
mkdir -p $@
## Generate Plot
## ====================================================
DATE := $(shell date +%Y%m%d)
COLUMNS := ${SERVERS:%=${DIST}/column.%.txt}
COLOR_NAMES := dark-red,dark-green,dark-blue,dark-magenta,
COLOR_NAMES += dark-pink,dark-violet,orange-red,brown,
COLOR_NAMES += dark-goldenrod,sea-green
awk_frac_hr = \
{ h = substr($$1,1,2); \
m = substr($$1,3,2); \
printf("%7.4f\n",h+m/60) \
}
colors = \
echo $(COLOR_NAMES) \
| tr -d ' ' | tr ',' '\n' | awk '{print NR,$$1}'
servernames = \
echo ${SERVERS} | tr ' ' '\n' | awk '{print NR,$$1}'
plot_meta = join \
<($(servernames)) \
<($(colors)) \
| awk '{print "$1",$$2,$$3}'
plot_fmt = \"%s\" u 1:%d w l t \"%s\" lc rgb \"%s\", \n
plot_cmd = plot $(shell \
$(call plot_meta,$1) \
| awk '{printf ("$(plot_fmt)",$$1,1+NR,$$2,$$3)}' \
) ;
gnuplot_script = \
set term "png" size 1280,720 \
font "Linux Libertine" ; \
set output "$1" ; \
set grid ; \
set logscale y ; \
set title "Ping statistics for $3" \
font ",16"; \
set xlabel "Time (in hours of the day)" \
offset 0,0.5 ; \
set ylabel "Network Latency (in ms)" \
offset 2,0 ; \
$(call plot_cmd,$2)
plot: ${DIST}/${DATE}-summary.png
${DIST}/${DATE}-summary.png : ${DIST}/plot-data.txt
gnuplot -p -e '$(call gnuplot_script,$@,$<,${IP})'
.INTERMEDIATE: ${DIST}/plot-data.txt
${DIST}/plot-data.txt : ${DIST}/col-head.txt ${COLUMNS}
paste $^ > $@
.INTERMEDIATE: ${DIST}/col-head.txt
${DIST}/col-head.txt :
; ls ${DIST}/${DATE}-*.ping_report.txt -1 \
| cut -d/ -f2 \
| cut -d. -f1 \
| cut -d- -f2 \
| awk '${awk_frac_hr}' \
> $@
.INTERMEDIATE: ${COLUMNS}
${DIST}/column.%.txt :
cat ${DIST}/${DATE}-*.ping_report.txt \
| awk -v RS= '/\.$* ping/' \
| awk '/^rtt/' \
| awk '{print $$4}' \
| awk -F/ '{print $$2}' \
> $@
## Update Self
## ====================================================
## WARNING:
## --------------------------------
## Update this repository. This may require to
## enable/bypass/login-to proxy server in order to
## establish connection to the git repository.
self-update :
git pull
## Log archive
## ====================================================
YYYY := $(shell echo ${DATE} | cut -c -4)
MM := $(shell echo ${DATE} | cut -c 5-6)
DD := $(shell echo ${DATE} | cut -c 7-)
daily-archive : ${DIST}/${YYYY}/${MM}/${DD}.tar.bz2
${DIST}/${YYYY}/${MM}/${DD}.tar.bz2 : ${DIST}/${YYYY}/${MM}
tar cjf $@ dist/${DATE}-*.ping_report.txt
rm dist/${DATE}-*.ping_report.txt
monthly-archive : ${DIST}/${YYYY}/${MM}.tar.bz2
${DIST}/${YYYY}/${MM}.tar.bz2 : ${DIST}/${YYYY}
tar cjf $@ ${DIST}/${YYYY}/${MM}/*.tar.bz2
rm ${DIST}/${YYYY}/${MM}/*.tar.bz2
mv -t ${DIST}/${YYYY}/${MM} \
${DIST}/${YYYY}${MM}*-summary.png
${DIST}/${YYYY} ${DIST}/${YYYY}/${MM} :
mkdir -p $@