Révision 430d68ff
Add configuration, documentation, and autoconf
| plugins/varnish/varnish_devicedetect | ||
|---|---|---|
| 1 | 1 |
#!/bin/sh |
| 2 |
# -*- sh -*- |
|
| 2 | 3 |
|
| 3 |
# © 2012 - Stig Sandbeck Mathisen <ssm@fnord.no> |
|
| 4 |
# |
|
| 5 |
# varnish_devicedetect - Plugin to graph the device usage ratio of website |
|
| 6 |
# visitors |
|
| 7 |
# |
|
| 8 |
# This plugin reads data from the Varnish shared memory log, and presents a |
|
| 9 |
# stacked percentage graph of the device types of your website visitors for all |
|
| 10 |
# entries present in the log. |
|
| 11 |
# |
|
| 12 |
# Requires: |
|
| 13 |
# |
|
| 14 |
# * Varnish |
|
| 15 |
# |
|
| 16 |
# * varnish-devicedect from https://github.com/varnish/varnish-devicedetect |
|
| 17 |
# |
|
| 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 |
|
| 18 | 62 |
|
| 19 | 63 |
print_config() {
|
| 20 |
printf "graph_title Varnish device detection\n" |
|
| 21 |
printf "graph_vlabel percent\n" |
|
| 22 |
printf "graph_category varnish\n" |
|
| 23 |
printf "graph_args --lower-limit 0 --upper-limit 100\n" |
|
| 24 |
|
|
| 25 |
for device in bot mobile-android mobile-iphone pc tablet-android tablet-ipad; do |
|
| 26 |
printf "%s.label %s\n" $device $device |
|
| 27 |
printf "%s.type GAUGE\n" $device |
|
| 28 |
printf "%s.draw AREASTACK\n" $device |
|
| 29 |
done |
|
| 64 |
printf "graph_title Varnish device detection\n" |
|
| 65 |
printf "graph_vlabel percent\n" |
|
| 66 |
printf "graph_category varnish\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 |
|
| 30 | 83 |
} |
| 31 | 84 |
|
| 32 | 85 |
print_values() {
|
| 33 |
varnishlog -d -m 'TxHeader:X-UA-Device:' -I X-UA-Device \ |
|
| 34 |
| awk ' |
|
| 35 |
$4 == "X-UA-Device:" {
|
|
| 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:" {
|
|
| 36 | 105 |
total++; |
| 37 |
devices[$5]++ |
|
| 106 |
seen_devices[$5]++
|
|
| 38 | 107 |
} |
| 39 | 108 |
|
| 40 | 109 |
END {
|
| 41 |
for (device in devices) |
|
| 42 |
printf "%s.value %f\n", device, devices[device] / total * 100.0 |
|
| 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 |
} |
|
| 43 | 119 |
} |
| 44 | 120 |
' |
| 45 | 121 |
} |
| 46 | 122 |
|
| 47 | 123 |
case $1 in |
| 48 |
autoconf) |
|
| 49 |
printf "no\n" |
|
| 50 |
exit 1 |
|
| 51 |
;; |
|
| 52 |
config) |
|
| 53 |
print_config |
|
| 54 |
;; |
|
| 55 |
*) |
|
| 56 |
print_values |
|
| 57 |
;; |
|
| 124 |
autoconf) |
|
| 125 |
autoconf |
|
| 126 |
;; |
|
| 127 |
config) |
|
| 128 |
print_config |
|
| 129 |
;; |
|
| 130 |
*) |
|
| 131 |
print_values |
|
| 132 |
;; |
|
| 58 | 133 |
esac |
Formats disponibles : Unified diff