Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reporting all rates as per-minute, added metadata, handling errors wh…

…en running varnishstats
  • Loading branch information...
commit 56b06669f7d389936bdef68423d126ee8ca49db7 1 parent 3bbbf0a
Derek Haynes itsderek23 authored
13 mongo_slow_queries/mongo_slow_queries.rb
View
@@ -30,6 +30,9 @@ class ScoutMongoSlow < Scout::Plugin
Notes: MongoDB standard port is 27017
attributes: advanced
EOS
+
+ # In order to limit the alert body size, only the first +MAX_QUERIES+ are listed in the alert body.
+ MAX_QUERIES = 10
def enable_profiling(db)
# set to slow_only or higher (>100ms)
@@ -102,7 +105,15 @@ def build_report
def build_alert(slow_queries)
subj = "Maximum Query Time exceeded on #{slow_queries.size} #{slow_queries.size > 1 ? 'queries' : 'query'}"
- {:subject => subj, :body => slow_queries.to_json}
+ # send a sampling of slow queries. the total # of queries + query is limited as scout will throwout large checkins.
+ queries = []
+ slow_queries[0..(MAX_QUERIES-1)].each do |sq|
+ if q=sq['query'] and q.size > 300
+ sq['query'] = q[0..300] + '...'
+ end
+ queries << sq
+ end
+ {:subject => subj, :body => queries.to_json}
end
end
24 varnish/varnish.rb
View
@@ -10,16 +10,18 @@ class Varnish < Scout::Plugin
metrics:
name: Varnishstat Metrics
default: client_conn,client_req,cache_hit,cache_hitpass,cache_miss,backend_conn,backend_fail
- notes: A comma separated list varnishstat metrics.
- rate:
- name: Metric Reporting Rate
- default: second
- notes: Whether the metrics should be report per second or minute
+ notes: A comma separated list of varnishstat metrics.
EOS
+
+ RATE = :minute # counter metrics are reported per-minute
def build_report
stats = {}
- `varnishstat -1`.each_line do |line|
+ 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
@@ -29,18 +31,10 @@ def build_report
hitrate = stats[:cache_hit].to_f / total * 100
report(:hitrate => hitrate)
- rate = option(:rate)
- if rate == "second" || rate == "minute"
- rate = rate.to_sym
- else
- error("Invalid rate - #{rate} - using second")
- rate = :second
- end
-
option(:metrics).split(/,\s*/).compact.each do |metric|
metric = metric.to_sym
if stats[metric]
- counter(metric, stats[metric], :per=>rate)
+ counter(metric, stats[metric], :per=>RATE)
else
error("No such metric - #{metric}")
end
25 varnish/varnish.yml
View
@@ -0,0 +1,25 @@
+metadata:
+ backend_fail:
+ label: Backend failures
+ units: /min
+ backend_conn:
+ label: Backend connections
+ units: /min
+ hitrate:
+ label: Hit rate
+ units: "%"
+ cache_hit:
+ label: Cache hits
+ units: /min
+ client_req:
+ label: Client requests
+ units: /min
+ client_conn:
+ label: Client connections
+ units: /min
+ cache_miss:
+ label: Cache miss
+ units: /min
+ cache_hitpass:
+ label: Cache hits for pass
+ units: /min
Please sign in to comment.
Something went wrong with that request. Please try again.