Asterisk app: add IAX2 peer graphs (#11078)

* Asterisk app: add IAX2 peer graphs

* It's an entirely new graph and will not break existing graphs.
* The asterisk extend script must be updated to provide the appropriate poller data.
* The PR for librenms-agent/snmp/asterisk is here: https://github.com/librenms/librenms-agent/pull/274

* code climate, round 1

* clarified unit text

* code climate, round 2

* changes needed to properly generate test data

* linux_asterisk-v1 test data
This commit is contained in:
Joseph Tingiris
2020-02-03 12:47:27 -05:00
committed by GitHub
parent 051ca6503f
commit 02bc15c206
7 changed files with 208 additions and 29 deletions

View File

@@ -0,0 +1,30 @@
<?php
require 'includes/html/graphs/common.inc.php';
$i = 0;
$scale_min = 0;
$nototal = 1;
$unit_text = 'IAX2 Peers';
$rrd_filename = rrd_name($device['hostname'], array('app', 'asterisk', 'iax2', $app['app_id']));
$astiax2_access_array = array(
'iax2peers' => 'Total Peers',
'iax2online' => 'Online',
'iax2offline'=> 'Offline',
'iax2unmonitored' => 'Unmonitored'
);
$colours = 'mixed';
$rrd_list = array();
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($astiax2_access_array as $ds => $descr) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $descr;
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else {
echo "file missing: $rrd_filename";
}
require 'includes/html/graphs/generic_multi_line.inc.php';

View File

@@ -4,15 +4,15 @@ require 'includes/html/graphs/common.inc.php';
$i = 0;
$scale_min = 0;
$nototal = 1;
$unit_text = 'Peers';
$unit_text = 'SIP Peers';
$rrd_filename = rrd_name($device['hostname'], array('app', 'asterisk', 'stats', $app['app_id']));
$astsip_access_array = array(
'sippeers' => 'Total Sip Peers',
'sipmononline' => 'Sip Mon Online',
'sipmonoffline'=> 'Sip Mon Offline',
'sipunmononline' => 'Sip Unmon Online',
'sipunmonoffline' => 'Sip Unmon Offline'
'sippeers' => 'Total Peers',
'sipmononline' => 'Online (Monitored)',
'sipmonoffline'=> 'Offline (Monitored)',
'sipunmononline' => 'Online (Unmonitored)',
'sipunmonoffline' => 'Offline (Unmonitored)'
);
$colours = 'mixed';

View File

@@ -306,6 +306,7 @@ $graphs['asterisk'] = array(
'calls',
'channels',
'sip',
'iax2',
);
echo '<div class="panel panel-default">';
echo '<div class="panel-heading">';

View File

@@ -1,27 +1,23 @@
<?php
$graphs = array(
'asterisk_calls' => 'Asterisk - Calls',
'asterisk_channels' => 'Asterisk - Channels',
'asterisk_sip' => 'Asterisk - SIP'
);
$asterisk_graphs = array(
'asterisk_calls' => 'Asterisk - Calls',
'asterisk_channels' => 'Asterisk - Channels',
'asterisk_sip' => 'Asterisk - SIP Peers',
'asterisk_iax2' => 'Asterisk - IAX2 Peers'
);
foreach ($graphs as $key => $text) {
$graph_type = $key;
foreach ($asterisk_graphs as $asterisk_graphs_key => $asterisk_graphs_value) {
$graph_type = $asterisk_graphs_key;
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['id'] = $app['app_id'];
$graph_array['to'] = \LibreNMS\Config::get('time.now');
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;
$graph_array['type'] = 'application_'.$asterisk_graphs_key;
$graph_array['width'] = '215';
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$text.'</h3>
</div>
<div class="panel-body">
<div class="row">';
<div class="panel-heading"><h3 class="panel-title">'.$asterisk_graphs_value.'</h3></div>
<div class="panel-body"><div class="row">';
include 'includes/html/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div></div></div></div>';
}

View File

@@ -4,6 +4,9 @@ use LibreNMS\RRD\RrdDefinition;
$name = 'asterisk';
$app_id = $app['app_id'];
echo "$name, app_id=$app_id ";
if (!empty($agent_data[$name])) {
$rawdata = $agent_data[$name];
} else {
@@ -12,13 +15,17 @@ if (!empty($agent_data[$name])) {
$rawdata = snmp_walk($device, $oid, $options);
$rawdata = str_replace("<<<asterisk>>>\n", '', $rawdata);
}
# Format Data
$lines = explode("\n", $rawdata);
$asterisk = array();
$asterisk_metrics = array();
foreach ($lines as $line) {
list($var,$value) = explode('=', $line);
$asterisk[$var] = $value;
}
unset($lines);
# Asterisk stats
$rrd_name = array('app', $name, 'stats', $app_id);
$rrd_def = RrdDefinition::make()
@@ -29,7 +36,8 @@ $rrd_def = RrdDefinition::make()
->addDataset('sipmonoffline', 'GAUGE', 0, 10000)
->addDataset('sipunmononline', 'GAUGE', 0, 10000)
->addDataset('sipunmonoffline', 'GAUGE', 0, 10000);
$fields = array(
$sip_fields = array(
'calls' => $asterisk['Calls'],
'channels' => $asterisk['Channels'],
'sipeers' => $asterisk['SipPeers'],
@@ -38,8 +46,34 @@ $fields = array(
'sipunmononline' => $asterisk['SipUnMonOnline'],
'sipunmonoffline' => $asterisk['SipUnMonOffline']
);
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
data_update($device, 'app', $tags, $fields);
update_application($app, $rawdata, $fields);
unset($lines, $asterisk, $rrd_name, $rrd_def, $fields, $tags, $rawdata);
$asterisk_metrics['stats'] = $sip_fields;
$sip_tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
data_update($device, 'app', $sip_tags, $sip_fields);
unset($rrd_name, $rrd_def, $sip_fields, $sip_tags);
# Additional iax2 stats
$rrd_name = array('app', $name, 'iax2', $app_id);
$rrd_def = RrdDefinition::make()
->addDataset('iax2peers', 'GAUGE', 0, 10000)
->addDataset('iax2online', 'GAUGE', 0, 10000)
->addDataset('iax2offline', 'GAUGE', 0, 10000)
->addDataset('iax2unmonitored', 'GAUGE', 0, 10000);
$iax2_fields = array(
'iax2peers' => $asterisk['Iax2Peers'],
'iax2online' => $asterisk['Iax2Online'],
'iax2offline' => $asterisk['Iax2Offline'],
'iax2unmonitored' => $asterisk['Iax2Unmonitored']
);
$asterisk_metrics['iax2'] = $iax2_fields;
$iax2_tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
data_update($device, 'app', $iax2_tags, $iax2_fields);
update_application($app, $rawdata, $asterisk_metrics);
unset($rrd_name, $rrd_def, $iax2_fields, $iax2_tags);
unset($asterisk, $asterisk_metrics, $rawdata); // these are used for all rrds

View File

@@ -0,0 +1,97 @@
{
"applications": {
"discovery": {
"applications": [
{
"app_type": "asterisk",
"app_state": "UNKNOWN",
"discovered": 1,
"app_state_prev": null,
"app_status": "",
"app_instance": ""
}
],
"application_metrics": []
},
"poller": {
"applications": [
{
"app_type": "asterisk",
"app_state": "OK",
"discovered": 1,
"app_state_prev": "UNKNOWN",
"app_status": "",
"app_instance": ""
}
],
"application_metrics": [
{
"metric": "iax2_iax2offline",
"value": 292,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "iax2_iax2online",
"value": 687,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "iax2_iax2peers",
"value": 979,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "iax2_iax2unmonitored",
"value": 0,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_calls",
"value": 0,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_channels",
"value": 0,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_sipeers",
"value": 48,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_sipmonoffline",
"value": 20,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_sipmononline",
"value": 28,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_sipunmonoffline",
"value": 0,
"value_prev": null,
"app_type": "asterisk"
},
{
"metric": "stats_sipunmononline",
"value": 0,
"value_prev": null,
"app_type": "asterisk"
}
]
}
}
}

View File

@@ -0,0 +1,21 @@
1.3.6.1.2.1.1.1.0|4|Linux joseph.tingiris 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.8072.3.2.10
1.3.6.1.2.1.1.3.0|67|1081
1.3.6.1.2.1.1.4.0|4|<private>
1.3.6.1.2.1.1.5.0|4|<private>
1.3.6.1.2.1.1.6.0|4|<private>
1.3.6.1.2.1.25.1.1.0|67|391359940
1.3.6.1.4.1.8072.1.3.2.2.1.21.8.97.115.116.101.114.105.115.107|2|1
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.1|4|<<<asterisk>>>
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.2|4|Channels=0
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.3|4|Calls=0
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.4|4|SipPeers=48
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.5|4|SipMonOnline=28
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.6|4|SipMonOffline=20
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.7|4|SipUnMonOnline=0
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.8|4|SipUnMonOffline=0
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.9|4|Iax2Peers=979
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.10|4|Iax2Online=687
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.11|4|Iax2Offline=292
1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107.12|4|Iax2Unmonitored=0
1.3.6.1.6.3.10.2.1.3.0|2|11