Skip to content

Instantly share code, notes, and snippets.

@wa0x6e
Last active March 27, 2017 12:36
Show Gist options
  • Save wa0x6e/6587923 to your computer and use it in GitHub Desktop.
Save wa0x6e/6587923 to your computer and use it in GitHub Desktop.
Varnish cache hit ratio widget for Shopify's Dashing dashboard

Varnish Cache hit ratio widget for Dashing

Description

Varnish Dashing widget to display the ratio of cache hit/miss.

Dependencies

No dependencies

Usage

To use this widget:

  • copy varnish.rb into your /jobs folder

Then include the widget in a dashboard, by adding the following snippet to your dashboard layout file:

	<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="varnish_hit_rates" data-view="Meter" style="background-color: #2759a7"  data-title="Varnish hit ratio"></div>
    </li>
def get_stats
output = %x(varnishstat -1)
stats = {
:cache_hit => /cache_hit\s*(?<count>\d*)/m.match(output)[:count].to_i,
:cache_miss => /cache_miss\s*(?<count>\d*)/m.match(output)[:count].to_i
}
end
SCHEDULER.every('15s', first_in: '1s') {
stats = get_stats
if stats[:cache_miss] == 0 && stats[:cache_hit] == 0
hit_rates = 0
else
hit_rates = stats[:cache_hit] * 100 / (stats[:cache_hit] + stats[:cache_miss])
end
# Send memory usage stats in bytes
send_event('varnish_hit_rates', {
"min" => 0,
"max" => 100,
value: hit_rates
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment