forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_loadtime
executable file
·114 lines (87 loc) · 2.62 KB
/
http_loadtime
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
#!/bin/bash
: << =cut
=head1 NAME
http_loadtime - Plugin to graph the HTTP response times of specific pages
=head1 CONFIGURATION
The following environment variables are used by this plugin
target - comma separated URL(s) to fetch (default: "http://localhost/")
example:
[http_loadtime]
env.target http://localhost.de,http://localhost.de/some-site.html
env.requisites true
Do not enable the download of page requisites (env.requisites) for https
sites since wget needs incredible long to perform this on big sites...
=head1 AUTHOR
Unknown authors
(2013) Axel Huebl
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
target=${target:-"http://localhost/"}
requisites=${requisites:-"false"}
urls=`echo $target | tr "," "\n"`
wget_opt="--user-agent munin/http_loadtime --no-cache -q"
if [ "$requisites" == "true" ]; then
wget_opt="$wget_opt --page-requisites"
fi
time_bin=`which time`
if [ "$1" = "autoconf" ]; then
result="yes"
command -v $time_bin 2>&1 >/dev/null || result=1
command -v tr 2>&1 >/dev/null || result=1
command -v wget 2>&1 >/dev/null || result=1
if [ "$result" != "yes" ]; then
echo "no (programs time, wget and tr required)"
exit 0
fi
# if $target contains more than one url
if ! wget -q -O /dev/null $target; then
# check if urls respond
#
for uri in $urls
do
wget --spider $uri $wget_opt
if [ "$?" != "0" ]; then
echo "no (Cannot run wget against \"$uri\")"
exit 0
fi
done
fi
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo "graph_title HTTP loadtime of a page"
echo "graph_args --base 1000 -l 0"
echo "graph_vlabel Load time in seconds"
echo "graph_category network"
echo "graph_info This graph shows the load time in seconds"
for uri in $urls
do
uri_short=`echo ${uri:0:30}`
if [ "$uri_short" != "$uri" ]; then uri_short=$uri_short"..."; fi
esc_uri="$(clean_fieldname "$uri")"
echo $esc_uri".label $uri_short"
echo $esc_uri".info page load time"
done
exit 0
fi
TEMPO_DIR=$(mktemp -dt munin_http_loadtime.XXXXXX) || exit 1
trap "rm -rf $TEMPO_DIR" EXIT
cd $TEMPO_DIR || exit 1
for uri in $urls
do
loadtime=`$time_bin -f "%e" wget $wget_opt --header='Accept-Encoding: gzip,deflate' $uri 2>&1`
if [ "$?" == "0" ]; then
esc_uri="$(clean_fieldname "$uri")"
echo $esc_uri".value $loadtime"
else
echo "Download error during $uri" 1>&2
exit 1
fi
done
exit 0