Skip to content

Instantly share code, notes, and snippets.

@koalamon
Created April 13, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koalamon/6276712bafc67f8915b0ed5d10af2328 to your computer and use it in GitHub Desktop.
Save koalamon/6276712bafc67f8915b0ed5d10af2328 to your computer and use it in GitHub Desktop.
Varnish Stats
<?php
function getStats()
{
exec('varnishstat -1', $output);
return implode("\n", $output);
}
$rawStats = getStats();
$hitString = 'MAIN.cache_hit';
$hit = (int)substr($rawStats, strpos($rawStats, $hitString) + strlen($hitString), 25);
$missString = 'MAIN.cache_miss';
$miss = (int)substr($rawStats, strpos($rawStats, $missString) + strlen($missString), 25);
$ratio = round((($hit / ($hit + $miss)) * 100), 2);
file_put_contents(__DIR__ . "/history/latest.log", date('c') . ';' . $hit . ';' . $miss . ';' . $ratio);
echo $ratio;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment