forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wireguard application graph cleanup and new wireguard interface/globa…
…l metrics. (librenms#15847)
- Loading branch information
1 parent
c855d6c
commit d7c31e0
Showing
7 changed files
with
354 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$name = 'wireguard'; | ||
$polling_type = 'app'; | ||
$bigdescrlen = 100; | ||
$smalldescrlen = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,60 @@ | ||
<?php | ||
|
||
$name = 'wireguard'; | ||
$polling_type = 'app'; | ||
|
||
if (isset($vars['interface']) && isset($vars['client'])) { | ||
$interface = $vars['interface']; | ||
$client = $vars['client']; | ||
$interface_client = $vars['interface'] . '-' . $vars['client']; | ||
} else { | ||
$interface_client_list = Rrd::getRrdApplicationArrays($device, $app->app_id, $name); | ||
$interface_client = $interface_client_list[0] ?? ''; | ||
} | ||
require 'wireguard-common.inc.php'; | ||
|
||
$unit_text = 'Minutes'; | ||
$interface_client_map = $app->data['mappings'] ?? []; | ||
$colours = 'psychedelic'; | ||
$metric_desc = 'Last Handshake'; | ||
$metric_name = 'minutes_since_last_handshake'; | ||
$rrd_list = []; | ||
$rrdArray = []; | ||
$scale_min = 0; | ||
$unitlen = 7; | ||
|
||
if (isset($vars['interface']) && isset($vars['client'])) { | ||
// This section draws the individual graphs in the device application page | ||
// displaying the SPECIFIED wireguard interface and client metric. | ||
$wg_intf_client = $vars['interface'] . '-' . $vars['client']; | ||
$rrdArray[$wg_intf_client] = [ | ||
$metric_name => ['descr' => $metric_desc], | ||
]; | ||
} elseif (! isset($vars['interface']) && ! isset($vars['client'])) { | ||
// This section draws the graph for the application-specific pages | ||
// displaying ALL wireguard interfaces' clients' metrics. | ||
foreach ($interface_client_map as $wg_intf => $wg_client_list) { | ||
foreach ($wg_client_list as $wg_client) { | ||
$wg_intf_client = $wg_intf . '-' . $wg_client; | ||
$rrdArray[$wg_intf_client] = [ | ||
$metric_name => [ | ||
'descr' => $wg_intf_client . ' ' . $metric_desc, | ||
], | ||
]; | ||
} | ||
} | ||
} | ||
|
||
$rrdArray = [ | ||
'minutes_since_last_handshake' => ['descr' => 'Last Handshake'], | ||
]; | ||
if (! $rrdArray) { | ||
graph_error('No Data to Display', 'No Data'); | ||
} | ||
|
||
$rrd_filename = Rrd::name($device['hostname'], [ | ||
$polling_type, | ||
$name, | ||
$app->app_id, | ||
$interface_client, | ||
]); | ||
$i = 0; | ||
foreach ($rrdArray as $wg_intf_client => $wg_metric) { | ||
$rrd_filename = Rrd::name($device['hostname'], [ | ||
$polling_type, | ||
$name, | ||
$app->app_id, | ||
$wg_intf_client, | ||
]); | ||
|
||
if (Rrd::checkRrdExists($rrd_filename)) { | ||
foreach ($rrdArray as $rrdVar => $rrdValues) { | ||
$rrd_list[] = [ | ||
'filename' => $rrd_filename, | ||
'descr' => $rrdValues['descr'], | ||
'ds' => $rrdVar, | ||
]; | ||
if (Rrd::checkRrdExists($rrd_filename)) { | ||
$rrd_list[$i]['filename'] = $rrd_filename; | ||
$rrd_list[$i]['descr'] = $wg_metric[$metric_name]['descr']; | ||
$rrd_list[$i]['ds'] = $metric_name; | ||
$i++; | ||
} else { | ||
graph_error('No Data file ' . basename($rrd_filename), 'No Data'); | ||
} | ||
} else { | ||
d_echo('RRD ' . $rrd_filename . ' not found'); | ||
} | ||
|
||
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php'; |
69 changes: 42 additions & 27 deletions
69
includes/html/graphs/application/wireguard_traffic.inc.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,59 @@ | ||
<?php | ||
|
||
$name = 'wireguard'; | ||
$polling_type = 'app'; | ||
|
||
if (isset($vars['interface']) && isset($vars['client'])) { | ||
$interface = $vars['interface']; | ||
$client = $vars['client']; | ||
$interface_client = $vars['interface'] . '-' . $vars['client']; | ||
} else { | ||
$interface_client_list = Rrd::getRrdApplicationArrays($device, $app->app_id, $name); | ||
$interface_client = $interface_client_list[0] ?? ''; | ||
} | ||
|
||
$unit_text = 'Bytes'; | ||
|
||
$ds_in = 'bytes_rcvd'; | ||
$in_text = 'Rcvd'; | ||
$ds_out = 'bytes_sent'; | ||
$out_text = 'Sent'; | ||
require 'wireguard-common.inc.php'; | ||
|
||
$unit_text = 'Bytes/s'; | ||
$format = 'bytes'; | ||
$print_total = true; | ||
|
||
$in_text = 'In'; | ||
$out_text = 'Out'; | ||
$colour_area_in = 'FF3300'; | ||
$colour_line_in = 'FF0000'; | ||
$colour_area_out = 'FF6633'; | ||
$colour_line_out = 'CC3300'; | ||
|
||
$colour_area_in_max = 'FF6633'; | ||
$colour_area_out_max = 'FF9966'; | ||
|
||
$rrd_filename = Rrd::name($device['hostname'], [ | ||
$polling_type, | ||
$name, | ||
$app->app_id, | ||
$interface_client, | ||
]); | ||
if (! isset($vars['interface']) && ! isset($vars['client'])) { | ||
// This section is called if we're being asked to graph | ||
// the host's wireguard global metrics. | ||
$ds_in = 'bytes_rcvd_total'; | ||
$ds_out = 'bytes_sent_total'; | ||
} elseif (isset($vars['interface']) && isset($vars['client'])) { | ||
// This section is called if we're being asked to graph | ||
// a wireguard interface's client metrics. | ||
$flattened_name = $vars['interface'] . '-' . $vars['client']; | ||
$ds_in = 'bytes_rcvd'; | ||
$ds_out = 'bytes_sent'; | ||
} elseif (isset($vars['interface'])) { | ||
// This section is called if we're being asked to graph | ||
// a wireguard interface's metrics. | ||
$flattened_name = $vars['interface']; | ||
$ds_in = 'bytes_rcvd_total_intf'; | ||
$ds_out = 'bytes_sent_total_intf'; | ||
} | ||
|
||
if (! isset($vars['interface']) && ! isset($vars['client'])) { | ||
$rrd_filename = Rrd::name($device['hostname'], [ | ||
$polling_type, | ||
$name, | ||
$app->app_id, | ||
]); | ||
} elseif (isset($vars['interface'])) { | ||
$rrd_filename = Rrd::name($device['hostname'], [ | ||
$polling_type, | ||
$name, | ||
$app->app_id, | ||
$flattened_name, | ||
]); | ||
} | ||
|
||
if (! isset($rrd_filename)) { | ||
graph_error('No Data to Display', 'No Data'); | ||
} | ||
|
||
if (! Rrd::checkRrdExists($rrd_filename)) { | ||
d_echo('RRD ' . $rrd_filename . ' not found'); | ||
graph_error('No Data file ' . basename($rrd_filename), 'No Data'); | ||
} | ||
|
||
require 'includes/html/graphs/generic_duplex.inc.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.