root / plugins / solr / solr-stats @ 17f78427
Historique | Voir | Annoter | Télécharger (1,79 ko)
| 1 |
#!/usr/bin/php |
|---|---|
| 2 |
<?php |
| 3 |
/** |
| 4 |
* SolR Plugin |
| 5 |
* author : nicolas.moussikian@shopbot-inc.com |
| 6 |
* |
| 7 |
* This plugin allows to graph any data present in the stats report on a multi core SolR instance |
| 8 |
* AKA : http://127.0.0.1:8080/solr/[name of the core]/admin/stats.jsp |
| 9 |
* Verify the server where the munin-node instance is can access that URL |
| 10 |
* |
| 11 |
* You need to have a PHP 5.2.6+ CLI installed too |
| 12 |
* |
| 13 |
* Once the plugin is available you can simlink it with the following naming convention : |
| 14 |
* 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] |
| 15 |
*/ |
| 16 |
$action = empty($argv[1]) ? '' : $argv[1]; |
| 17 |
|
| 18 |
$tabParams = explode('-', $argv[0]);
|
| 19 |
|
| 20 |
$core = $tabParams[1]; |
| 21 |
$category = $tabParams[2]; |
| 22 |
$item = $tabParams[3]; |
| 23 |
$property = $tabParams[4]; |
| 24 |
|
| 25 |
if('config' === $action)
|
| 26 |
{
|
| 27 |
echo 'graph_category search ' . $core . "\n"; |
| 28 |
echo 'graph_title ' . $item . ' ' . $property . "\n"; |
| 29 |
echo 'graph_vlabel ' . $property . "\n"; |
| 30 |
echo $core . $item . $property . 'solr.label ' . $property . "\n"; |
| 31 |
} |
| 32 |
else |
| 33 |
{
|
| 34 |
$file = 'http://127.0.0.1:8080/solr/' . $core . '/admin/stats.jsp'; |
| 35 |
|
| 36 |
$doc = new DOMDocument('1.0', 'utf-8');
|
| 37 |
$doc->load($file); |
| 38 |
|
| 39 |
$xpath = new DOMXpath($doc); |
| 40 |
|
| 41 |
$elements = $xpath->query('/solr/solr-info/' . $category . '/entry');
|
| 42 |
|
| 43 |
foreach($elements as $element) |
| 44 |
{
|
| 45 |
if($item == trim($element->getElementsByTagName('name')->item(0)->textContent))
|
| 46 |
{
|
| 47 |
$stats = $element->getElementsByTagName('stat');
|
| 48 |
|
| 49 |
foreach($stats as $stat) |
| 50 |
{
|
| 51 |
if($property == trim($stat->getAttribute('name')))
|
| 52 |
{
|
| 53 |
echo $core . $item . $property . 'solr.value ' . floatval(trim($stat->textContent)) . "\n"; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
