Skip to content

Instantly share code, notes, and snippets.

@isra00
Created October 24, 2012 23:17
Show Gist options
  • Save isra00/3949544 to your computer and use it in GitHub Desktop.
Save isra00/3949544 to your computer and use it in GitHub Desktop.
APC usage by vhost (for Plesk)
<?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);
@isra00
Copy link
Author

isra00 commented Oct 24, 2012

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 ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment