1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Use APCu functions when available (make plugin compatible with PHP using APCu)

Detect available functions (apc_ or apcu_ ones) and call the right ones.
This commit is contained in:
Ricardo Sanz 2021-03-21 21:53:14 +01:00 committed by Lars Kruse
parent da87fcd6c7
commit f76c34f5c6

View file

@ -1,24 +1,34 @@
<?php <?php
$ret = array(); $ret = array();
if(function_exists("apc_cache_info") && function_exists("apc_sma_info")) // Detect APC functions to call.
$apc_fn_name = "";
if(function_exists("apcu_cache_info") && function_exists("apcu_sma_info"))
{
$apc_fn_name = "apcu";
} elseif (function_exists("apc_cache_info") && function_exists("apc_sma_info"))
{
$apc_fn_name = "apc";
}
if(!empty($apc_fn_name))
{ {
switch ($_GET["act"]) switch ($_GET["act"])
{ {
case "memory": case "memory":
$tmp = apc_sma_info(); $tmp = call_user_func($apc_fn_name . "_sma_info");
$ret["mem_used"] = $tmp["seg_size"]-$tmp["avail_mem"]; $ret["mem_used"] = $tmp["seg_size"]-$tmp["avail_mem"];
$ret["mem_avail"] = $tmp["avail_mem"]; $ret["mem_avail"] = $tmp["avail_mem"];
break; break;
case "hits": case "hits":
$tmp = apc_cache_info(); $tmp = call_user_func($apc_fn_name . "_cache_info");
$ret["num_hits"] = $tmp["num_hits"]; $ret["num_hits"] = $tmp["num_hits"];
$ret["num_misses"] = $tmp["num_misses"]; $ret["num_misses"] = $tmp["num_misses"];
break; break;
case "percents": case "percents":
$tmp = apc_sma_info(); $tmp = call_user_func($apc_fn_name . "_sma_info");
$ret["memory"] = 100-(($tmp["avail_mem"] / $tmp["seg_size"])*100); $ret["memory"] = 100-(($tmp["avail_mem"] / $tmp["seg_size"])*100);
$tmp = apc_cache_info(); $tmp = apcu_cache_info();
$ret["hits"] = ($tmp["num_hits"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100; $ret["hits"] = ($tmp["num_hits"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100;
$ret["misses"] = ($tmp["num_misses"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100; $ret["misses"] = ($tmp["num_misses"] / ( $tmp["num_hits"]+$tmp["num_misses"]) ) * 100;
break; break;