Created
October 24, 2012 23:17
-
-
Save isra00/3949544 to your computer and use it in GitHub Desktop.
APC usage by vhost (for Plesk)
This file contains hidden or 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 | |
$apc_entries = apc_cache_info(); | |
$apc_entries = $apc_entries['cache_list']; | |
$usage_data = array(); | |
foreach ($apc_entries as $entry) { | |
$filename = $entry['filename']; | |
$num_hits = $entry['num_hits']; | |
$mem_size = $entry['mem_size']; | |
$slices = ''; | |
if (preg_match('/\/var\/www\/vhosts\/([a-z\.]+)\/.*/i', $filename, $slices)) { | |
$vhost = $slices[1]; | |
if (!isset($usage_data[$vhost])) { | |
$usage_data[$vhost] = array( | |
'hits' => 0, | |
'mem_size' => 0, | |
'load' => 0 | |
); | |
} | |
$usage_data[$vhost]['hits'] += $num_hits; | |
$usage_data[$vhost]['mem_size'] += $mem_size; | |
//This metric approximates RAM usage | |
$usage_data[$vhost]['load'] += $num_hits * $mem_size; | |
} | |
} | |
print_r($usage_data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it's a print_r() at the end. It's up to you what you do with that data. Personally, I send it to Datadog ;-)