Commit ecf9eb5f authored by Ad Schellevis's avatar Ad Schellevis

(SystemHealth) work in progress

parent 1370b96d
...@@ -26,18 +26,18 @@ ...@@ -26,18 +26,18 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
namespace OPNsense\SystemHealth; namespace OPNsense\Diagnostics;
/** /**
* Class IndexController * Class IndexController
* @package OPNsense\Proxy * @package OPNsense\Proxy
*/ */
class IndexController extends \OPNsense\Base\IndexController class SystemHealthController extends \OPNsense\Base\IndexController
{ {
public function indexAction() public function indexAction()
{ {
$this->view->title = "System Health"; $this->view->title = "System Health";
$this->view->pick('OPNsense/SystemHealth/index'); $this->view->pick('OPNsense/Diagnostics/systemhealth');
} }
} }
<?php
/**
* Copyright (C) 2015 Deciso B.V. - J. Schellevis
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\SystemHealth\Api;
use \OPNsense\Base\ApiControllerBase;
/**
* Class SettingsController
* @package OPNsense\SystemHealth
*/
class SettingsController extends ApiControllerBase
{
}
?>
...@@ -172,7 +172,7 @@ ...@@ -172,7 +172,7 @@
} }
function getRRDlist() { function getRRDlist() {
ajaxGet(url = "/api/systemhealth/service/getRRDlist/", sendData = {}, callback = function (data, status) { ajaxGet(url = "/api/diagnostics/systemhealth/getRRDlist/", sendData = {}, callback = function (data, status) {
if (status == "success") { if (status == "success") {
var category; var category;
var tabs=""; var tabs="";
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
// info bar - show loading info bar while refreshing data // info bar - show loading info bar while refreshing data
$('#loading').show(); $('#loading').show();
// API call to request data // API call to request data
ajaxGet(url = "/api/systemhealth/service/getSystemHealth/" + rrd_name + "/" + String(from) + "/" + String(to) + "/" + String(maxitems) + "/" + String(inverse) + "/" + String(detail), sendData = {}, callback = function (data, status) { ajaxGet(url = "/api/diagnostics/systemhealth/getSystemHealth/" + rrd_name + "/" + String(from) + "/" + String(to) + "/" + String(maxitems) + "/" + String(inverse) + "/" + String(detail), sendData = {}, callback = function (data, status) {
if (status == "success") { if (status == "success") {
var stepsize = data["d3"]["stepSize"]; var stepsize = data["d3"]["stepSize"];
var scale = "{{ lang._('seconds') }}"; var scale = "{{ lang._('seconds') }}";
...@@ -473,7 +473,7 @@ ...@@ -473,7 +473,7 @@
.tickFormat(function (d) { .tickFormat(function (d) {
return d3.time.format(dtformat)(new Date(d)) return d3.time.format(dtformat)(new Date(d))
}); });
chart.yAxis.axisLabel(data["x-axis_label"]); chart.yAxis.axisLabel(data["y-axis_label"]);
chart.useInteractiveGuideline(true); chart.useInteractiveGuideline(true);
chart.interactive(true); chart.interactive(true);
......
<?xml version="1.0"?>
<systemhealth>
<file-match>.*-packets$</file-match>
<title>System Information - Packets </title>
<y-axis_label>Packets/Second</y-axis_label>
</systemhealth>
\ No newline at end of file
<?xml version="1.0"?> <?xml version="1.0"?>
<details> <systemhealth>
<file-match>system-processor</file-match>
<title> System Information - Utilization and Processes</title> <title> System Information - Utilization and Processes</title>
<x-axis_label>[U]tilization , [#]Number</x-axis_label> <y-axis_label>[U]tilization , [#]Number</y-axis_label>
<field_units> <field_units>
<user>[U]</user> <user>[U]</user>
<nice>[U]</nice> <nice>[U]</nice>
...@@ -9,4 +10,4 @@ ...@@ -9,4 +10,4 @@
<interrupt>[#]</interrupt> <interrupt>[#]</interrupt>
<processes>[#]</processes> <processes>[#]</processes>
</field_units> </field_units>
</details> </systemhealth>
\ No newline at end of file \ No newline at end of file
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
""" """
Copyright (c) 2015 Deciso B.V. - J. Schellevis Copyright (c) 2015 Deciso B.V. - Ad Schellevis
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
...@@ -26,10 +26,29 @@ ...@@ -26,10 +26,29 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
fetch xmldata from rrd tool, but only if filename is valid (with or without .rrd extension)
""" """
import sys
import glob
import tempfile
import subprocess
import os.path
rrd_reports_dir = '/var/db/rrd'
if len(sys.argv) > 1:
filename = sys.argv[1]
# suffix rrd if not already in request
if filename.split('.')[-1] != 'rrd':
filename += '.rrd'
# scan rrd directory for requested file
for rrdFilename in glob.glob('%s/*.rrd' % rrd_reports_dir):
if os.path.basename(rrdFilename) == filename:
with tempfile.NamedTemporaryFile() as output_stream:
subprocess.check_call(['/usr/local/bin/rrdtool', 'dump', rrdFilename],
stdout=output_stream, stderr=subprocess.STDOUT)
output_stream.seek(0)
print (output_stream.read())
break
file = open('/Users/josschellevis/Development/opnsense/scripts/systemhealth/metadata/system-processor.xml', 'r')
file_contents = file.read()
print (file_contents)
file.close()
#!/usr/local/bin/python2.7
"""
Copyright (c) 2015 Deciso B.V. - Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
return a list of all available rrd files including additional definition data
"""
import re
import glob
import xml.etree.ElementTree
import os.path
import ujson
rrd_definition_dir = '%s/definitions' % os.path.dirname(os.path.abspath(__file__))
rrd_reports_dir = '/var/db/rrd'
# query all rrd files available and initialize with empty definition
result = {}
for filename in glob.glob('%s/*.rrd' % rrd_reports_dir):
rrdFilename = os.path.basename(filename).split('.')[0]
# determine topic and item name, fixes naming issues
if rrdFilename.split('-')[0] in ('system') and rrdFilename.find('-') > -1:
topic = rrdFilename.split('-')[0]
itemName = '-'.join(rrdFilename.split('-')[1:])
else:
topic = rrdFilename.split('-')[-1]
itemName = '-'.join(rrdFilename.split('-')[:-1])
result[rrdFilename] = {'title': '', 'y-axis_label': '', 'field_units': {}, 'topic': topic, 'itemName': itemName}
# scan all definition files
for filename in glob.glob('%s/*.xml' % rrd_definition_dir):
rrdFilename = os.path.basename(filename).split('.')[0]
try:
ruleXML=xml.etree.ElementTree.fromstring(open(filename).read())
rrdDef = {}
if ruleXML.tag == 'systemhealth':
# only parse systemhealth items
for child in ruleXML:
if len(list(child)) == 0:
# single items
rrdDef[child.tag] = child.text
else:
# named list items
rrdDef[child.tag] = {}
for subchild in child:
rrdDef[child.tag][subchild.tag] = subchild.text
else:
rrdDef['__msg'] = 'xml metadata not valid'
except xml.etree.ElementTree.ParseError:
# no valid xml, always return a valid (empty) data set
rrdDef = {'__msg': 'xml metadata load error'}
# link definition data to rrd file, use property file-match in xml to determine it's targets
if 'file-match' in rrdDef:
# remove file-match property from actual result
file_match = rrdDef['file-match']
del rrdDef['file-match']
for rrdFilename in result:
if re.search(file_match, rrdFilename) is not None:
for fieldname in rrdDef:
result[rrdFilename][fieldname] = rrdDef[fieldname]
print(ujson.dumps(result))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment