net-mgmt/netdata: new plugin (#1268)

This commit is contained in:
Michael 2019-03-23 08:45:52 +01:00 committed by Franco Fichtner
parent 1069a55a70
commit 0c3e752656
17 changed files with 682 additions and 0 deletions

View file

@ -0,0 +1,8 @@
PLUGIN_NAME= netdata
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Real-time performance monitoring
PLUGIN_DEPENDS= netdata
PLUGIN_MAINTAINER= m.muenz@gmail.com
PLUGIN_DEVEL= yes
.include "../../Mk/plugins.mk"

View file

@ -0,0 +1,9 @@
Netdata is distributed, real-time, performance and health monitoring
for systems and applications. It is a highly optimized monitoring agent
you install on all your systems and containers.
Netdata provides unparalleled insights, in real-time, of everything
happening on the systems it runs (including web servers, databases,
applications), using highly interactive web dashboards.
WWW: https://github.com/netdata/netdata

View file

@ -0,0 +1,49 @@
<?php
/*
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* 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.
*/
function netdata_services()
{
global $config;
$services = array();
if (isset($config['OPNsense']['netdata']['general']['enabled']) && $config['OPNsense']['netdata']['general']['enabled'] == 1) {
$services[] = array(
'description' => gettext('netdata daemon'),
'configd' => array(
'restart' => array('netdata restart'),
'start' => array('netdata start'),
'stop' => array('netdata stop'),
),
'name' => 'netdata',
'pidfile' => '/var/db/netdata/netdata.pid'
);
}
return $services;
}

View file

@ -0,0 +1,37 @@
<?php
/*
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* 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\Netdata\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
class GeneralController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\OPNsense\Netdata\General';
protected static $internalModelName = 'general';
}

View file

@ -0,0 +1,39 @@
<?php
/*
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* 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\Netdata\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\Netdata\General';
protected static $internalServiceTemplate = 'OPNsense/Netdata';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'netdata';
}

View file

@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* 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\Netdata;
class GeneralController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm('general');
$this->view->pick('OPNsense/Netdata/general');
}
}

View file

@ -0,0 +1,20 @@
<form>
<field>
<id>general.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help>Enable Netdata, you can reach the UI via address and port set below.</help>
</field>
<field>
<id>general.listen</id>
<label>Listen Address</label>
<type>text</type>
<help>Set the IP addresses to listen to.</help>
</field>
<field>
<id>general.port</id>
<label>Listen Port</label>
<type>text</type>
<help>Set the port to listen to.</help>
</field>
</form>

View file

@ -0,0 +1,9 @@
<acl>
<page-services-netdata>
<name>Services: Netdata</name>
<patterns>
<pattern>ui/netdata/*</pattern>
<pattern>api/netdata/*</pattern>
</patterns>
</page-services-netdata>
</acl>

View file

@ -0,0 +1,35 @@
<?php
/*
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
* 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\Netdata;
use OPNsense\Base\BaseModel;
class General extends BaseModel
{
}

View file

@ -0,0 +1,19 @@
<model>
<mount>//OPNsense/netdata/general</mount>
<description>Netdata configuration</description>
<version>0.0.1</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<listen type="HostnameField">
<default>127.0.0.1</default>
<Required>Y</Required>
</listen>
<port type="PortField">
<default>19999</default>
<Required>Y</Required>
</port>
</items>
</model>

View file

@ -0,0 +1,7 @@
<menu>
<Services>
<Netdata cssClass="fa fa-pie-chart">
<General url="/ui/netdata/general/index"/>
</Netdata>
</Services>
</menu>

View file

@ -0,0 +1,57 @@
{#
# Copyright (c) 2019 Deciso B.V.
# Copyright (c) 2019 Michael Muenz <m.muenz@gmail.com>
# 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.
#}
<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress"></i></button>
</div>
</div>
<script>
$(function() {
var data_get_map = {'frm_general_settings':"/api/netdata/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
updateServiceControlUI('netdata');
// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/netdata/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/netdata/service/reconfigure", sendData={}, callback=function(data,status) {
updateServiceControlUI('netdata');
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});
</script>

View file

@ -0,0 +1,11 @@
#!/bin/sh
mkdir -p /var/cache/netdata/
mkdir -p /var/db/netdata/
mkdir -p /var/log/netdata/
chown netdata:netdata /var/cache/netdata
chown netdata:netdata /var/db/netdata
chown netdata:netdata /var/log/netdata
chmod 750 /var/cache/netdata
chmod 750 /var/db/netdata
chmod 750 /var/log/netdata

View file

@ -0,0 +1,23 @@
[start]
command:/usr/local/opnsense/scripts/OPNsense/Netdata/setup.sh;/usr/local/etc/rc.d/netdata start
parameters:
type:script
message:starting Netdata
[stop]
command:/usr/local/etc/rc.d/netdata stop
parameters:
type:script
message:stopping Netdata
[restart]
command:/usr/local/opnsense/scripts/OPNsense/Netdata/setup.sh;/usr/local/etc/rc.d/netdata restart
parameters:
type:script
message:restarting Netdata
[status]
command:/usr/local/etc/rc.d/netdata status;exit 0
parameters:
type:script_output
message:request Netdata status

View file

@ -0,0 +1,2 @@
netdata:/etc/rc.conf.d/netdata
netdata.conf:/usr/local/etc/netdata/netdata.conf

View file

@ -0,0 +1,7 @@
{% if helpers.exists('OPNsense.netdata.general.enabled') and OPNsense.netdata.general.enabled == '1' %}
netdata_var_script="/usr/local/opnsense/scripts/OPNsense/Netdata/setup.sh"
netdata_enable="YES"
{% else %}
netdata_enable="NO"
{% endif %}
netdata_var_mfs="/var/cache/netdata /var/db/netdata /var/log/netdata"

View file

@ -0,0 +1,312 @@
{% if helpers.exists('OPNsense.netdata.general.enabled') and OPNsense.netdata.general.enabled == '1' %}
# $FreeBSD$
# netdata configuration
#
# You can uncomment and change any of the options below.
# The value shown in the commented settings, is the default value.
#
# global netdata configuration
[global]
history = 86400
bind to = {{ OPNsense.netdata.general.listen }}
disconnect idle web clients after seconds = 3600
run as user = netdata
web files owner = netdata
web files group = netdata
default port = {{ OPNsense.netdata.general.port }}
respect web browser do not track policy = yes
[plugins]
freebsd = yes
[registry]
[health]
[backend]
[plugin:tc]
[plugin:idlejitter]
[plugin:freebsd]
netdata server resources = yes
sysctl = yes
[plugin:cgroups]
[plugin:node.d]
[plugin:fping]
[plugin:apps]
[plugin:python.d]
[plugin:charts.d]
[plugin:freebsd:sysctl]
[system.idlejitter]
[system.load]
[system.active_processes]
[system.processes]
[mem.committed]
[system.cpu]
[cpu.cpu0]
[system.intr]
[system.dev_intr]
[system.soft_intr]
[system.ctxt]
[netdata.plugin_cgroups_cpu]
[system.forks]
[system.io]
[system.swap]
[system.ram]
[system.swapio]
[netdata.apps_cpu]
[netdata.apps_files]
[netdata.apps_fix]
[netdata.apps_children_fix]
[mem.pgfaults]
[system.ipc_semaphores]
[system.ipc_semaphore_arrays]
[system.ipc_shared_mem_segs]
[system.ipc_shared_mem_size]
[system.ipc_msq_queues]
[system.ipc_msq_messages]
[system.ipc_msq_size]
[system.softnet_stat]
[cpu.cpu0_softnet_stat]
[system.ipv4]
[system.ipv6]
[net.vtnet0]
[net_packets.vtnet0]
[net_errors.vtnet0]
[net_drops.vtnet0]
[net_events.vtnet0]
[net.vtnet1]
[net_packets.vtnet1]
[net_errors.vtnet1]
[net_drops.vtnet1]
[net_events.vtnet1]
[net.lo0]
[net_packets.lo0]
[net_errors.lo0]
[net_drops.lo0]
[net_events.lo0]
[netdata.plugin_proc_cpu]
[netdata.server_cpu]
[netdata.clients]
[netdata.requests]
[netdata.net]
[netdata.response_time]
[netdata.compression_ratio]
[system.interrupts]
[disk.vtbd0]
[disk_ops.vtbd0]
[disk_qops.vtbd0]
[disk_util.vtbd0]
[disk_iotime.vtbd0]
[ipv4.tcpsock]
[ipv4.tcppackets]
[ipv4.tcperrors]
[ipv4.tcphandshake]
[ipv4.tcpconnaborts]
[ipv4.tcpofo]
[ipv4.tcpsyncookies]
[ipv4.ecnpkts]
[ipv4.udppackets]
[ipv4.udperrors]
[ipv4.icmp]
[ipv4.icmp_errors]
[ipv4.icmpmsg]
[ipv4.packets]
[ipv4.fragsout]
[ipv4.fragsin]
[ipv4.errors]
[ipv6.packets]
[ipv6.errors]
[ipv6.icmp]
[ipv6.icmpneighbor]
[ipv6.icmptypes]
[disk_space./]
[disk_inodes./]
[disk_space./tmp]
[disk_inodes./tmp]
[disk_space./usr]
[disk_inodes./usr]
[disk_space./usr/home]
[disk_inodes./usr/home]
[disk_space./usr/ports]
[disk_inodes./usr/ports]
[disk_space./usr/ports/distfiles]
[disk_inodes./usr/ports/distfiles]
[disk_space./usr/ports/packages]
[disk_inodes./usr/ports/packages]
[disk_space./usr/src]
[disk_inodes./usr/src]
[disk_space./var]
[disk_inodes./var]
[disk_space./var/crash]
[disk_inodes./var/crash]
[disk_space./var/db]
[disk_inodes./var/db]
[disk_space./var/db/pkg]
[disk_inodes./var/db/pkg]
[disk_space./var/empty]
[disk_inodes./var/empty]
[disk_space./var/log]
[disk_inodes./var/log]
[disk_space./var/mail]
[disk_inodes./var/mail]
[disk_space./var/run]
[disk_inodes./var/run]
[disk_space./var/tmp]
[disk_inodes./var/tmp]
[system.uptime]
[disk_await.vtbd0]
[disk_avgsz.vtbd0]
[disk_svctm.vtbd0]
[nginx_local.connections]
[nginx_local.requests]
[nginx_local.connection_status]
[nginx_local.connect_rate]
[netdata.plugin_pythond_nginx_local]
[nginx_log_local.codes]
[netdata.plugin_pythond_nginx_log_local]
{% endif %}