File: http_loadtime.in

package info (click to toggle)
munin 2.0.6-4%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,944 kB
  • sloc: perl: 11,577; sh: 2,939; java: 1,880; makefile: 726; python: 272
file content (73 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download
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
#!@@BASH@@
# -*- sh -*-

: << =cut

=head1 NAME

http_loadtime - Plugin to graph HTTP response time of a specific page

=head1 CONFIGURATION

The following environment variables are used by this plugin

 target - URL to fetch (default: "http://localhost/")

=head1 BUGS

This plugin used to be marked for auto-configuraiton.  Unfortunately
it does not test if the $target is reachable or not, and the plugin
has been made a contrib plugin pending fixing.

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=contrib
 #%# capabilities=autoconf

=cut

target=${target:-"http://localhost/"}

if [ "$1" = "autoconf" ]; then
    result="yes"
    command -v wget 2>/dev/null || result=1
    if [ "$result" != "yes" ]; then
    	echo "no (need time and wget programs)"
	    exit 0
    fi
    if ! $wget_bin -q -O /dev/null $target; then
        echo "no (Cannot run wget against \"$target\")"
        exit 0
    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 load time in seconds of $target"
    echo "loadtime.label loadtime"
    echo "loadtime.info Load time"
    exit 0
fi

TMPDIR=`mktemp -d` || exit 1

trap "rm -rf $TMPDIR" EXIT

cd $TMPDIR || exit 1
loadtime=$((time -p wget -p --no-cache --delete-after $target -q) 2>&1 | awk '/^real / { print $2 }')
cd ..

echo "loadtime.value $loadtime"