]>
Commit | Line | Data |
---|---|---|
3decc5d1 JR |
1 | #!/bin/sh |
2 | ||
3 | : << =cut | |
4 | ||
5 | =head1 NAME | |
6 | ||
7 | http_loadtime - Plugin to graph the HTTP response times of specific pages | |
8 | ||
9 | =head1 CONFIGURATION | |
10 | ||
11 | The following environment variables are used by this plugin | |
12 | ||
13 | target - comma separated URL(s) to fetch (default: "http://localhost/") | |
14 | example: | |
15 | [http_loadtime] | |
16 | env.target http://localhost.de,http://localhost.de/some-site.html | |
17 | env.requisites true | |
18 | ||
19 | Do not enable the download of page requisites (env.requisites) for https | |
20 | sites since wget needs incredible long to perform this on big sites... | |
21 | ||
22 | =head1 AUTHOR | |
23 | ||
24 | Unknown authors | |
25 | (2013) Axel Huebl | |
26 | ||
27 | =head1 LICENSE | |
28 | ||
29 | GPLv2 | |
30 | ||
31 | =head1 MAGIC MARKERS | |
32 | ||
33 | #%# family=auto | |
34 | #%# capabilities=autoconf | |
35 | ||
36 | =cut | |
37 | ||
38 | target=${target:-"http://localhost/"} | |
39 | requisites=${requisites:-"false"} | |
40 | ||
41 | urls=$(echo "$target" | tr ',' '\n') | |
42 | ||
43 | ||
44 | request_url() { | |
45 | wget --user-agent "Munin - http_loadtime" --no-cache --quiet --output-document=/dev/null "$@" 2>/dev/null | |
46 | } | |
47 | ||
48 | ||
49 | escapeUri() { | |
50 | echo "$1" | sed 's!^\(https\?://\)\?[^/]\+/!!;s/[:/.-]/_/g' | |
51 | } | |
52 | ||
53 | shortenUri() { | |
54 | echo "$1" | sed 's!^http\(s\)\?://!\1:!;s!\.simplynuc\.!...!' | |
55 | } | |
56 | ||
57 | ||
58 | if [ "$1" = "autoconf" ]; then | |
59 | result="yes" | |
60 | command -v tr >/dev/null 2>&1 || result=1 | |
61 | command -v wget >/dev/null 2>&1 || result=1 | |
62 | if [ "$result" != "yes" ]; then | |
63 | echo "no (programs wget and tr required)" | |
64 | exit 0 | |
65 | fi | |
66 | ||
67 | # check if urls respond | |
68 | # | |
69 | for uri in $urls | |
70 | do | |
71 | if ! request_url --spider "$uri"; then | |
72 | echo "no (Cannot run wget against \"$uri\")" | |
73 | exit 0 | |
74 | fi | |
75 | done | |
76 | ||
77 | echo yes | |
78 | exit 0 | |
79 | fi | |
80 | ||
81 | ||
82 | if [ "$1" = "config" ]; then | |
83 | echo "graph_title HTTP loadtime of a page" | |
84 | echo "graph_args --base 1000 -l 0" | |
85 | echo "graph_vlabel Load time in seconds" | |
86 | echo "graph_category apache" | |
87 | echo "graph_info This graph shows the load time in seconds" | |
88 | for uri in $urls | |
89 | do | |
90 | uri_short=$(echo "$(shortenUri "$uri")" | cut -c 1-30) | |
91 | if [ "$uri_short" != "$(shortenUri "$uri")" ]; then uri_short="${uri_short}..."; fi | |
92 | echo "$(escapeUri "$uri").label $uri_short" | |
93 | echo "$(escapeUri "$uri").info $uri" | |
94 | done | |
95 | exit 0 | |
96 | fi | |
97 | ||
98 | ||
99 | for uri in $urls | |
100 | do | |
101 | start=$(date +%s.%N) | |
102 | if [ "$requisites" = "true" ]; then | |
103 | request_url --page-requisites "$uri" | |
104 | else | |
105 | request_url "$uri" | |
106 | fi | |
107 | loadtime=$(echo "$start" "$(date +%s.%N)" | awk '{ print($2 - $1); }') | |
108 | ||
109 | echo "$(escapeUri "$uri").value $loadtime" | |
110 | done |