function _monitoring_munin_result in Monitoring 7
Returns the monitoring result.
Return value
string Monitoring result string.
1 call to _monitoring_munin_result()
- monitoring_munin_drush_callback in modules/
monitoring_munin/ monitoring_munin.drush.inc - Command callback for munin integration.
File
- modules/
monitoring_munin/ monitoring_munin.module, line 138 - Monitoring Munin module bootstrap file.
Code
function _monitoring_munin_result() {
$sensor_info = monitoring_sensor_manager()
->getEnabledSensorInfo();
$munin_enabled = array();
// Select only those sensors that are enabled for munin.
foreach (monitoring_munin_config() as $graph) {
foreach ($graph as $key => $value) {
// If the key does not represent label, continue.
if (strpos($key, '.label') === FALSE) {
continue;
}
// Retrieve sensor name from the label.
$label = str_replace('.label', '', $value);
$parts = explode('__', $label);
// Check if such sensor info exists.
if (!isset($sensor_info[$parts[1]])) {
continue;
}
$munin_enabled[$value] = $sensor_info[$parts[1]];
}
}
// Run enabled sensors.
$runner = new SensorRunner($munin_enabled);
$config = array();
/** @var \Drupal\monitoring\Result\SensorResultInterface $result */
foreach ($runner as $sensor_name => $result) {
$munin_settings = $result
->getSensorInfo()
->getSetting('munin');
$sensor_name = monitoring_munin_sensor_identifier($sensor_name);
// Compose multigraph results.
if (!empty($munin_settings['multigraphs'])) {
foreach ($munin_settings['multigraphs'] as $multigraph) {
$config[monitoring_munin_multigraph_identifier($multigraph)][$sensor_name] = $result
->toNumber();
}
}
else {
$config[$sensor_name][$sensor_name] = $result
->toNumber();
}
}
// Build the munin result output.
$output = '';
foreach ($config as $key => $multigraph) {
$output .= "multigraph {$key}\n";
foreach ($multigraph as $sensor_name => $value) {
$output .= $sensor_name . '.value ' . $value . "\n";
}
$output .= "\n";
}
return $output;
}