Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / php / php_time_execution @ aa3ee6dc

Historique | Voir | Annoter | Télécharger (2,22 ko)

1 5b9a5884 metfan
#!/bin/sh
2
#
3
# Plugin to monitor execution time of PHP with access.log from apache server.
4
# Need to use apache module mod_log_config and have  set logformat like this:
5
# LogFormat "%h %l %u %T/%D %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" time_combined
6
#
7
# Min, Max and Avg are calculated on number of page, default 10. On high traffic site, increase this value and you get a better
8
# stat, on low traffic site keep small value, it's must be avg number of page every 5 minutes.
9
#
10 8713eb37 Lars Kruse
# Require read permissions for $LOG
11 5b9a5884 metfan
#  (set in /etc/munin/plugin-conf.d/munin-node on debian)
12
# On busy servers you can change value type to COUNTER and set min to 0 to avoid minus peaks at logrotate
13
#
14 aa3ee6dc Lars Kruse
# Copyright (C) 2012 Ulrich Lusseau
15 5b9a5884 metfan
#
16
# Parameters:
17
#
18
#       config   (required)
19
#       autoconf (optional - used by munin-config)
20
#
21
# Magick markers (optional):
22
#%# family=auto
23
#%# capabilities=autoconf
24
#
25
# config example for /etc/munin/plugin-conf.d/munin-node
26
#[apache_generate_time]
27
#user root
28
#env.logfile /home/newsite/logs/access.log
29
#env.sitename mon-code
30
#env.nbrpage 10
31
#
32 17f78427 Lars Kruse
33 5b9a5884 metfan
LOG=${logfile:-/var/log/apache2/access.log}
34
NAME=${sitename:undefined}
35
NBRPAGE=${nbrpage}
36 17f78427 Lars Kruse
37
38 5b9a5884 metfan
if [ "$1" = "autoconf" ]; then
39
        if [ -r "$LOG" ]; then
40
                echo yes
41
        else
42
                echo no
43
        fi
44 e4cd049b Lars Kruse
        exit 0
45 5b9a5884 metfan
fi
46 17f78427 Lars Kruse
47 5b9a5884 metfan
if [ "$1" = "config" ]; then
48 17f78427 Lars Kruse
49 5b9a5884 metfan
        echo 'graph_title Time to generate PHP page ' $NAME 'v2'
50
        echo 'graph_args --base 1000 -l 0'
51
        echo 'graph_vlabel Time in microsecond'
52 17f78427 Lars Kruse
53 65652aa0 dipohl
        echo "graph_category webserver"
54 5b9a5884 metfan
        echo "graph_info This graph shows load time in ms of $target"
55
        echo "minloadtime.label Min time"
56
        echo "minloadtime.info Min time"
57
        echo "avgloadtime.label Avg time"
58
        echo "avgloadtime.info Avg time"
59
        echo "maxloadtime.label Max time"
60
        echo "maxloadtime.info Max time"
61 17f78427 Lars Kruse
62 5b9a5884 metfan
        exit 0
63
fi
64 17f78427 Lars Kruse
65 5b9a5884 metfan
 awk '($4 ~ /[0-9]+\/[0-9]+/ && $8 !~ /\.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG|txt|TXT|css|CSS|js|JS|zip|ZIP|bmp|BMP)$/)' $LOG     | sed -e :a -e '$q;N;'$NBRPAGE',$D;ba' | awk '{print $4}' | awk -F\/ ' MIN=="" || $2 < MIN {MIN=$2}  MAX=="" || $2 > MAX {MAX=$2}  {SUM += $2} END {print  "minloadtime.value ",MIN/1000,"\navgloadtime.value ",SUM/(NR*1000),"\nmaxloadtime.value ",MAX/1000}'