Created
April 13, 2016 19:19
-
-
Save koalamon/6276712bafc67f8915b0ed5d10af2328 to your computer and use it in GitHub Desktop.
Varnish Stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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