2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

[NEW] use curl instead of relying on allow_url_fopen if extension exists

[FIX] indexSize now returns values in Bytes and graph is 1024 based
[NEW] fieldValueCache aliases declaration
[FIX] (minor) admin path contains two '/'
This commit is contained in:
intsimoa 2012-07-09 09:42:22 +02:00
parent 5c77c1a93b
commit de967ad499

View File

@ -1,27 +1,31 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/** /**
* Wfsolr Plugin (https://github.com/lexsimon/contrib/master/plugins/solr/wfsolr_) * Wfsolr Plugin https://github.com/lexsimon/contrib/master/plugins/solr/wfsolr_
* "Wf" stands for "RBS Web Factory" (http://www.rbs.fr.fr/webfactory/) * "Wf" stands for "RBS Web Factory" (http://www.rbs.fr.fr/webfactory/)
* author : alexandre.simon@rbs.fr * @author : alexandre.simon@rbs.fr
*
* Derived from nicolas.moussikian@shopbot-inc.com's plugin (https://raw.github.com/munin-monitoring/contrib/master/plugins/solr/solr-stats) * Derived from nicolas.moussikian@shopbot-inc.com's plugin (https://raw.github.com/munin-monitoring/contrib/master/plugins/solr/solr-stats)
* This plugin allows to graph any data present in the stats report on a multi core Solr instance * This plugin allows to graph any data present in the stats report on a
* multi-core Solr instance
* AKA : http://127.0.0.1:8080/solr/[name of the core]/admin/stats.jsp * AKA : http://127.0.0.1:8080/solr/[name of the core]/admin/stats.jsp
* Verify the server where the munin-node instance is can access that URL * Verify the server where the munin-node instance is can access that URL
* *
* You need to have a PHP 5.2.6+ CLI installed too, allow_url_open directive on * You need to have a PHP 5.2.6+ CLI installed too with curl extension or
* allow_url_fopen directive on
* *
* Once the plugin is available you can symlink it with the following naming convention : * Once the plugin is available you can symlink it with the following naming convention :
* solr-[name of the core]-[name of the stats section - ex.: CORE]-[name of the entry in the xml - ex.: searcher]-[name of the stat to graph - ex.: numDocs] * wfsolr-[name of the core]-[name of the stats section - ex.: CORE]-[name of the entry in the xml - ex.: searcher]-[name of the stat to graph - ex.: numDocs]
* *
* Alexandre SIMON additions : * Alexandre SIMON additions:
* - solr-[name of the core]-alias * - wfsolr-<coreName>-alias ; use suggest to get the list of available aliases
* - suggest implementation * - suggest implementation
* - support for solr_(host|port|webapp) environment variables * - support for solr_(host|port|webapp) environment variables
* - default core handling * - default core handling
* - error handling * - error handling
* - TODO: use curl to make requests * - unit conversion
* - use curl to get URL contents instead of relying on allow_url_fopen
*/ */
$action = isset($argv[1]) ? $argv[1] : ''; $action = isset($argv[1]) ? $argv[1] : '';
@ -45,6 +49,10 @@ $pathAliases = array("numDocs" => array("CORE", "searcher", "numDocs"),
"documentCacheHitRatio" => array("CACHE", "documentCache", "hitratio"), "documentCacheHitRatio" => array("CACHE", "documentCache", "hitratio"),
"documentCacheLookups" => array("CACHE", "documentCache", "lookups"), "documentCacheLookups" => array("CACHE", "documentCache", "lookups"),
"documentCacheWarmupTime" => array("CACHE", "documentCache", "warmupTime"), "documentCacheWarmupTime" => array("CACHE", "documentCache", "warmupTime"),
"fieldValueCacheSize" => array("CACHE", "fieldValueCache", "size"),
"fieldValueCacheHitRatio" => array("CACHE", "fieldValueCache", "hitratio"),
"fieldValueCacheLookups" => array("CACHE", "fieldValueCache", "lookups"),
"fieldValueCacheWarmupTime" => array("CACHE", "filterCache", "warmupTime"),
"filterCacheSize" => array("CACHE", "filterCache", "size"), "filterCacheSize" => array("CACHE", "filterCache", "size"),
"filterCacheHitRatio" => array("CACHE", "filterCache", "hitratio"), "filterCacheHitRatio" => array("CACHE", "filterCache", "hitratio"),
"filterCacheLookups" => array("CACHE", "filterCache", "lookups"), "filterCacheLookups" => array("CACHE", "filterCache", "lookups"),
@ -100,12 +108,12 @@ function getSolrAdminUrl($core = null)
{ {
$url .= "$core/"; $url .= "$core/";
} }
$url .= "/admin"; $url .= "admin";
return $url; return $url;
} }
/** /**
* Assure some conversions. KB and GB converted to MB * Assure some conversions. KB, MB and GB are converted to Bytes
*/ */
function wffloatval($val) function wffloatval($val)
{ {
@ -113,20 +121,58 @@ function wffloatval($val)
$valEnd = substr($val, -2); $valEnd = substr($val, -2);
if ($valEnd == "KB") if ($valEnd == "KB")
{ {
$fVal = $fVal / 1024; $fVal = $fVal * 1024;
}
elseif ($valEnd == "MB")
{
$fVal = $fVal * 1048576;
} }
elseif ($valEnd == "GB") elseif ($valEnd == "GB")
{ {
$fVal = $fVal * 1024; $fVal = $fVal * 1073741824;
} }
return $fVal; return $fVal;
} }
if ("config" == $action) function wfGetUrl($url)
{ {
echo 'graph_category Solr ' . $core . "\n"; if (extension_loaded("curl"))
echo 'graph_title ' . $item . ' ' . $property . "\n"; {
echo 'graph_vlabel ' . $property . "\n"; $ch = curl_init();
$options = array(CURLOPT_URL => $url);
$options[CURLOPT_TIMEOUT] = 5;
$options[CURLOPT_CONNECTTIMEOUT] = 5;
$options[CURLOPT_RETURNTRANSFER] = true;
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
}
else
{
$content = file_get_contents($url);
}
if ($content === false)
{
throw new Exception("Could not get $url", 8);
}
return $content;
}
try
{
if ("config" == $action)
{
if ($property == "indexSize")
{
echo "graph_args --base 1024 -l 0\n";
}
echo "graph_category Solr $core\n";
echo "graph_title $item $property\n";
echo "graph_vlabel $property\n";
if ($core !== null) if ($core !== null)
{ {
echo $core; echo $core;
@ -136,12 +182,12 @@ if ("config" == $action)
echo "Default_core"; echo "Default_core";
} }
echo $item . $property . 'solr.label ' . $property . "\n"; echo $item . $property . 'solr.label ' . $property . "\n";
} }
elseif ("suggest" == $action) elseif ("suggest" == $action)
{ {
$url = getSolrAdminUrl()."/cores?action=STATUS"; $url = getSolrAdminUrl()."/cores?action=STATUS";
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!$doc->load($url)) if (!$doc->loadXML(wfGetUrl($url)))
{ {
echo "Could not load $url as XML\n"; echo "Could not load $url as XML\n";
exit(4); exit(4);
@ -161,9 +207,9 @@ elseif ("suggest" == $action)
echo "$alias\n"; echo "$alias\n";
} }
} }
} }
else else
{ {
if ($category === null) if ($category === null)
{ {
echo "No core defined\n"; echo "No core defined\n";
@ -171,7 +217,7 @@ else
} }
$url = getSolrAdminUrl($core)."/stats.jsp"; $url = getSolrAdminUrl($core)."/stats.jsp";
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!$doc->load($url)) if (!$doc->loadXML(wfGetUrl($url)))
{ {
echo "Could not load $url as XML\n"; echo "Could not load $url as XML\n";
exit(6); exit(6);
@ -197,4 +243,11 @@ else
} }
echo "Bad path: $category | $item | $property\n"; echo "Bad path: $category | $item | $property\n";
exit(7); exit(7);
}
}
catch (Exception $e)
{
echo "ERROR: ".$e->getMessage()."\n";
$exitCode = ($e->getCode() != 0) ? $e->getCode() : 1;
exit($exitCode);
} }