forked from itsderek23/highgroove-scout-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
varnish.rb
43 lines (38 loc) · 1.32 KB
/
varnish.rb
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
# =================================================================================
# Varnish
#
# Created by Erik Wickstrom on 2011-08-23.
# Updated by Joshua Tuberville on 2012-08-29.
# =================================================================================
class Varnish < Scout::Plugin
OPTIONS=<<-EOS
metrics:
name: Varnishstat Metrics
default: client_conn,client_req,cache_hit,cache_hitpass,cache_miss,backend_conn,backend_fail
notes: A comma separated list of varnishstat metrics.
EOS
RATE = :minute # counter metrics are reported per-minute
def build_report
stats = {}
res = `varnishstat -1 2>&1`
if !$?.success?
return error("Unable to fetch stats",res)
end
res.each_line do |line|
#client_conn 211980 0.30 Client connections accepted
next unless /^(\w+)\s+(\d+)\s+(\d+\.\d+)\s(.+)$/.match(line)
stats[$1.to_sym] = $2.to_i
end
total = stats[:cache_miss] + stats[:cache_hit] + stats[:cache_hitpass]
hitrate = stats[:cache_hit].to_f / (total.nonzero? || 1) * 100
report(:hitrate => hitrate)
option(:metrics).split(/,\s*/).compact.each do |metric|
metric = metric.to_sym
if stats[metric]
counter(metric, stats[metric], :per=>RATE)
else
error("No such metric - #{metric}")
end
end
end
end