Skip to content

Commit 8a259d1

Browse files
authored
update Sneck for for version 1.1.0 (librenms#18105)
* add in support for .data.run_time for sneck * update the app page * add sneck_run_time.inc.php * add run_time for sneck to apps.inc.php * add pretty display of per test run time * add total run to app page * fix metrics * remove a stray ; * rename sneck_run_time to sneck_runtime for the graph and change "Run Time" to Runtime" for display
1 parent cddc169 commit 8a259d1

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$name = 'sneck';
4+
$unit_text = 'Seconds';
5+
$colours = 'psychedelic';
6+
$dostack = 0;
7+
$printtotal = 0;
8+
$addarea = 0;
9+
$transparency = 15;
10+
11+
$rrd_filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'run_time']);
12+
13+
$rrd_list = [
14+
];
15+
16+
if (Rrd::checkRrdExists($rrd_filename)) {
17+
$rrd_list[] = [
18+
'filename' => $rrd_filename,
19+
'descr' => 'Runtime',
20+
'ds' => 'data',
21+
];
22+
}
23+
24+
require 'includes/html/graphs/generic_multi_line.inc.php';

includes/html/pages/apps.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
$graphs['sneck'] = [
103103
'results',
104104
'time',
105+
'runtime',
105106
];
106107
$graphs['ntp-client'] = [
107108
'stats',

includes/html/pages/device/apps/sneck.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
}
4949
}
5050
}
51+
// run time
52+
if (isset($app->data['data']['run_time'])) {
53+
echo '<b>Runtime:</b> ' . htmlspecialchars($app->data['data']['run_time']) . " seconds<br>\n";
54+
}
5155
print_optionbar_end();
5256
}
5357
}
@@ -70,6 +74,10 @@
7074
if (isset($app->data['data'][$type][$type_name]['ran'])) {
7175
echo '<b>Ran:</b> ' . htmlspecialchars($app->data['data'][$type][$type_name]['ran']) . "<br>\n";
7276
}
77+
// run time
78+
if (isset($app->data['data'][$type][$type_name]['run_time'])) {
79+
echo '<b>Runtime:</b> ' . htmlspecialchars($app->data['data'][$type][$type_name]['run_time']) . " seconds<br>\n";
80+
}
7381
// exit code
7482
if (isset($app->data['data'][$type][$type_name]['exit'])) {
7583
echo '<b>Exit:</b> ' . htmlspecialchars($app->data['data'][$type][$type_name]['exit']) . "<br>\n";
@@ -93,6 +101,10 @@
93101
'sneck_time' => 'Time Difference',
94102
];
95103

104+
if (isset($app->data['data']['checks'])) {
105+
$graphs['sneck_runtime'] = 'Runtime';
106+
}
107+
96108
foreach ($graphs as $key => $text) {
97109
$graph_type = $key;
98110
$graph_array['height'] = '100';

includes/polling/applications/sneck.inc.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@
8080
$tags = ['name' => $name, 'app_id' => $app->app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name];
8181
app('Datastore')->put($device, 'app', $tags, $fields);
8282

83+
// run_time is only present in version 1.1.0 and up
84+
if (isset($json_return['data']) and isset($json_return['data']['run_time']) and is_numeric($json_return['data']['run_time'])) {
85+
$rrd_def = RrdDefinition::make()
86+
->addDataset('data', 'GAUGE', 0);
87+
88+
$rrd_name = ['app', $name, $app->app_id, 'run_time'];
89+
90+
// $fields is also used for storing metrics, so don't stomp it
91+
$run_time_fields = [
92+
'data' => $json_return['data']['run_time'],
93+
];
94+
$fields['run_time'] = $json_return['data']['run_time'];
95+
96+
$tags = ['name' => $name, 'app_id' => $app->app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name];
97+
app('Datastore')->put($device, 'app', $tags, $run_time_fields);
98+
99+
// if this is over 300, it took 300+ seconds to run, meaning we are currently ingesting data for a previous time slot
100+
if ($json_return['data']['run_time'] >= 300) {
101+
$log_message = 'Sneck took ' . $json_return['data']['run_time'] . ' seconds to run';
102+
Eventlog::log($log_message, $device['device_id'], 'application', Severity::Error);
103+
}
104+
}
105+
83106
// save the return status for each alerting possibilities
84107
foreach ($json_return['data']['checks'] as $key => $value) {
85108
$fields['check_' . $key] = $value['exit'];

0 commit comments

Comments
 (0)