Projet

Général

Profil

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

root / plugins / varnish / varnish_devicedetect @ eaf6c2d7

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

1
#!/bin/sh
2
# -*- sh -*-
3

    
4
: <<EOF
5

    
6
=head1 NAME
7

    
8
varnish_devicedetect - Plugin to graph the device usage ratio of
9
website visitors
10

    
11
=head1 APPLICABLE SYSTEMS
12

    
13
Servers running varnish, and using the "varnish-devicedetect" VCL
14
(https://github.com/varnish/varnish-devicedetect)
15

    
16
=head1 CONFIGURATION
17

    
18
The plugin runs "varnishlog", and graphs the last 5 minutes of log
19
entries.
20

    
21
This configuration section shows the defaults of the plugin
22

    
23
=over 2
24

    
25
  [varnish_devicedetect]
26
  env.devices bot mobile-android mobile-iphone pc tablet-android tablet-ipad
27

    
28
=back
29

    
30
The "devices" list is a space separated list of devices, which should
31
match the headers set by the varnish-devicedect VCL.
32

    
33
=head1 INTERPRETATION
34

    
35
This plugin reads data from the Varnish shared memory log, and
36
presents a stacked percentage graph of the device types of your
37
website visitors for all entries present in the log, for the last 5
38
minutes.
39

    
40
The percentage shown per device is that of all devices, not just the
41
ones specified by env.devices.
42

    
43
=head1 AUTHOR
44

    
45
© 2012 - Stig Sandbeck Mathisen <ssm@fnord.no>
46

    
47
=head1 LICENSE
48

    
49
GPLv2
50

    
51
=head1 MAGIC MARKERS
52

    
53
 #%# family=auto
54
 #%# capabilities=autoconf
55

    
56
=cut
57

    
58
EOF
59

    
60
devices=${devices:-bot mobile-android mobile-iphone pc tablet-android tablet-ipad}
61
export devices
62

    
63
print_config() {
64
  printf "graph_title Varnish device detection\n"
65
  printf "graph_vlabel percent\n"
66
  printf "graph_category webserver\n"
67
  printf "graph_args --rigid --lower-limit 0 --upper-limit 100\n"
68

    
69
  for device in $devices; do
70
    printf "%s.label %s\n" $device $device
71
    printf "%s.type GAUGE\n" $device
72
    printf "%s.draw AREASTACK\n" $device
73
  done
74
}
75

    
76
autoconf() {
77
    if $(which varnishlog >/dev/null); then
78
        printf "yes\n"
79
    else
80
        printf "no (no varnishlog in path)\n"
81
        return 1
82
    fi
83
}
84

    
85
print_values() {
86
  varnishlog -d -i TxHeader -i ReqEnd -I X-UA-Device: \
87
    | awk '
88
  BEGIN {
89
    start_time = systime() - 300
90
    active = 0
91

    
92
    # Initialize the devices array, so we print all, even the ones
93
    # with zero value.
94

    
95
    split(ENVIRON["devices"], devices)
96
    for (device in devices) {
97
      seen_devices[devices[device]] = 0
98
    }
99
  }
100

    
101
  active == 0 && $2 == "ReqEnd" && $5 >= start_time {
102
    active = 1
103
  }
104
  active == 1 && $2 == "TxHeader" && $4 == "X-UA-Device:" {
105
    total++;
106
    seen_devices[$5]++
107
  }
108

    
109
  END {
110
    for (device in devices) {
111

    
112
      if (total > 0)
113
        percentage = seen_devices[devices[device]] / total * 100.0
114
      else
115
        percentage = 0
116

    
117
      printf "%s.value %f\n", devices[device], percentage
118
    }
119
  }
120
'
121
}
122

    
123
case $1 in
124
  autoconf)
125
    autoconf
126
    ;;
127
  config)
128
    print_config
129
    ;;
130
  *)
131
    print_values
132
    ;;
133
esac