mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
Collectd plugin (#197)
Whats working: Enable / Disable Set hostname FQDN Lookup Send metrics to external collector Working plugins: contextswitch cpu df interface load memory processes uptime users What's planned: Export to Graphite More options on network plugin (like authentication)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
PLUGIN_NAME= collectd
|
||||
PLUGIN_VERSION= 0.1
|
||||
PLUGIN_COMMENT= Collect system and application performance metrics periodically
|
||||
PLUGIN_DEPENDS= collectd5
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
PLUGIN_DEVEL= yes
|
||||
|
||||
.include "../../Mk/plugins.mk"
|
||||
@@ -0,0 +1,6 @@
|
||||
collectd is a daemon which collects system and application
|
||||
performance metrics periodically and provides mechanisms
|
||||
to store the values in a variety of ways, for example
|
||||
in RRD files.
|
||||
|
||||
WWW: http://www.collectd.org
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2017 Michael Muenz
|
||||
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 collectd_services()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$services = array();
|
||||
|
||||
if (isset($config['OPNsense']['collectd']['general']['enabled']) && $config['OPNsense']['collectd']['general']['enabled'] == 1) {
|
||||
$services[] = array(
|
||||
'description' => gettext('collectd daemon'),
|
||||
'configd' => array(
|
||||
'restart' => array('collectd restart'),
|
||||
'start' => array('collectd start'),
|
||||
'stop' => array('collectd stop'),
|
||||
),
|
||||
'name' => 'collectd',
|
||||
'pidfile' => '/var/run/collectd.pid'
|
||||
);
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
*
|
||||
* 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\collectd\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\collectd\General;
|
||||
use \OPNsense\Core\Config;
|
||||
|
||||
class GeneralController extends ApiControllerBase
|
||||
{
|
||||
public function getAction()
|
||||
{
|
||||
// define list of configurable settings
|
||||
$result = array();
|
||||
if ($this->request->isGet()) {
|
||||
$mdlGeneral = new General();
|
||||
$result['general'] = $mdlGeneral->getNodes();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$result = array("result"=>"failed");
|
||||
if ($this->request->isPost()) {
|
||||
// load model and update with provided data
|
||||
$mdlGeneral = new General();
|
||||
$mdlGeneral->setNodes($this->request->getPost("general"));
|
||||
|
||||
// perform validation
|
||||
$valMsgs = $mdlGeneral->performValidation();
|
||||
foreach ($valMsgs as $field => $msg) {
|
||||
if (!array_key_exists("validations", $result)) {
|
||||
$result["validations"] = array();
|
||||
}
|
||||
$result["validations"]["general.".$msg->getField()] = $msg->getMessage();
|
||||
}
|
||||
|
||||
// serialize model to config and save
|
||||
if ($valMsgs->count() == 0) {
|
||||
$mdlGeneral->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
$result["result"] = "saved";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 - 2017 Deciso B.V.
|
||||
* Copyright (C) 2017 Michael Muenz
|
||||
*
|
||||
* 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\collectd\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\Core\Backend;
|
||||
use \OPNsense\collectd\General;
|
||||
|
||||
/**
|
||||
* Class ServiceController
|
||||
* @package OPNsense\collectd
|
||||
*/
|
||||
class ServiceController extends ApiControllerBase
|
||||
{
|
||||
/**
|
||||
* start collectd service (in background)
|
||||
* @return array
|
||||
*/
|
||||
public function startAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun("collectd start", true);
|
||||
return array("response" => $response);
|
||||
} else {
|
||||
return array("response" => array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* stop collectd service
|
||||
* @return array
|
||||
*/
|
||||
public function stopAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun("collectd stop");
|
||||
return array("response" => $response);
|
||||
} else {
|
||||
return array("response" => array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* restart collectd service
|
||||
* @return array
|
||||
*/
|
||||
public function restartAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun("collectd restart");
|
||||
return array("response" => $response);
|
||||
} else {
|
||||
return array("response" => array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve status of collectd
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function statusAction()
|
||||
{
|
||||
$backend = new Backend();
|
||||
$mdlGeneral = new General();
|
||||
$response = $backend->configdRun("collectd status");
|
||||
|
||||
if (strpos($response, "not running") > 0) {
|
||||
if ($mdlGeneral->enabled->__toString() == 1) {
|
||||
$status = "stopped";
|
||||
} else {
|
||||
$status = "disabled";
|
||||
}
|
||||
} elseif (strpos($response, "is running") > 0) {
|
||||
$status = "running";
|
||||
} elseif ($mdlGeneral->enabled->__toString() == 0) {
|
||||
$status = "disabled";
|
||||
} else {
|
||||
$status = "unkown";
|
||||
}
|
||||
|
||||
|
||||
return array("status" => $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* reconfigure collectd, generate config and reload
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
|
||||
$mdlGeneral = new General();
|
||||
$backend = new Backend();
|
||||
|
||||
$runStatus = $this->statusAction();
|
||||
|
||||
// stop collectd if it is running or not
|
||||
$this->stopAction();
|
||||
|
||||
// generate template
|
||||
$backend->configdRun('template reload OPNsense/collectd');
|
||||
|
||||
// (res)start daemon
|
||||
if ($mdlGeneral->enabled->__toString() == 1) {
|
||||
$this->startAction();
|
||||
}
|
||||
|
||||
return array("status" => "ok");
|
||||
} else {
|
||||
return array("status" => "failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (C) 2017 Michael Muenz
|
||||
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\collectd;
|
||||
|
||||
class GeneralController extends \OPNsense\Base\IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->title = gettext("collectd settings");
|
||||
$this->view->generalForm = $this->getForm("general");
|
||||
$this->view->pick('OPNsense/collectd/general');
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>general.enabled</id>
|
||||
<label>Enable</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will activate the collectd service.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.hostname</id>
|
||||
<label>Hostname</label>
|
||||
<type>text</type>
|
||||
<help>Set the hostname for this system.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.fqdnlookup</id>
|
||||
<label>FQDN lookup</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will enable the FQDNLookup option.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.interval</id>
|
||||
<label>Interval</label>
|
||||
<type>text</type>
|
||||
<help>Global interval when to fetch values in seconds.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_enable</id>
|
||||
<label>Enable network plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Network plugin can send values to other instances</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_host</id>
|
||||
<label>Network collector host</label>
|
||||
<type>text</type>
|
||||
<help>Set the IP address of the network collector.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_port</id>
|
||||
<label>Network collector port</label>
|
||||
<type>text</type>
|
||||
<help>Set the port of the network collector. Collectd is using 25826 per default.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_username</id>
|
||||
<label>Network collector username</label>
|
||||
<type>text</type>
|
||||
<help>Set the username to authenticate against network collector (optional).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_password</id>
|
||||
<label>Network collector password</label>
|
||||
<type>text</type>
|
||||
<help>Set the password to authenticate against network collector (optional).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_network_encryption</id>
|
||||
<label>Network collector encryption</label>
|
||||
<type>checkbox</type>
|
||||
<help>Enable encryption for authentication against network collector (optional).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_graphite_enable</id>
|
||||
<label>Enable graphite plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Graphite plugin stores values in Carbon, the storage layer of Graphite.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_graphite_node</id>
|
||||
<label>Graphite collector node name</label>
|
||||
<type>text</type>
|
||||
<help>Set the name of the graphite collector.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_graphite_host</id>
|
||||
<label>Graphite collector host</label>
|
||||
<type>text</type>
|
||||
<help>Set the IP address of the graphite collector.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_graphite_port</id>
|
||||
<label>Graphite collector port</label>
|
||||
<type>text</type>
|
||||
<help>Set the port of the graphite collector, Graphite is using 2003 per default.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_contextswitch_enable</id>
|
||||
<label>Enable contextswitch plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The ContextSwitch plugin collects the number of context switches done by the operating system.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_cpu_enable</id>
|
||||
<label>Enable cpu plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The CPU plugin collects the amount of time spent by the CPU in various states, most notably executing user code, executing system code, waiting for IO-operations and being idle.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_df_enable</id>
|
||||
<label>Enable df plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The DF plugin collects file system usage information, i. e. basically how much space on a mounted partition is used and how much is available.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_interface_enable</id>
|
||||
<label>Enable interface plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Interface plugin collects information about the traffic, packets per second and errors of interfaces.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_load_enable</id>
|
||||
<label>Enable load plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Load plugin collects the system load.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_memory_enable</id>
|
||||
<label>Enable memory plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Memory plugin collects physical memory utilization (Used, buffered, cached and free).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_processes_enable</id>
|
||||
<label>Enable processes plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Processes plugin collects the number of processes, grouped by their state (e. g. running, sleeping, zombies, etc.).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_uptime_enable</id>
|
||||
<label>Enable uptime plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Uptime plugin keeps track of the system uptime, providing informations such as the average running time or the maximum reached uptime over a certain period of time.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>general.p_users_enable</id>
|
||||
<label>Enable users plugin</label>
|
||||
<type>checkbox</type>
|
||||
<help>The Users plugin counts the number of users currently logged into the system (SSH).</help>
|
||||
</field>
|
||||
</form>
|
||||
@@ -0,0 +1,9 @@
|
||||
<acl>
|
||||
<page-services-collectd>
|
||||
<name>Services: collectd</name>
|
||||
<patterns>
|
||||
<pattern>ui/collectd/*</pattern>
|
||||
<pattern>api/collectd/*</pattern>
|
||||
</patterns>
|
||||
</page-services-collectd>
|
||||
</acl>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace OPNsense\collectd;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
/*
|
||||
Copyright (C) 2017 Michael Muenz
|
||||
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.
|
||||
*/
|
||||
|
||||
class General extends BaseModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<model>
|
||||
<mount>//OPNsense/collectd/general</mount>
|
||||
<description>collectd configuration</description>
|
||||
<items>
|
||||
<enabled type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<hostname type="TextField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
<mask>/^.{1,64}$/u</mask>
|
||||
</hostname>
|
||||
<fqdnlookup type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</fqdnlookup>
|
||||
<interval type="IntegerField">
|
||||
<default>10</default>
|
||||
<Required>N</Required>
|
||||
</interval>
|
||||
<p_network_enable type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</p_network_enable>
|
||||
<p_network_host type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/</mask>
|
||||
</p_network_host>
|
||||
<p_network_port type="IntegerField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<MinimumValue>1</MinimumValue>
|
||||
<MaximumValue>65535</MaximumValue>
|
||||
</p_network_port>
|
||||
<p_network_username type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z._\-]){1,128}$/u</mask>
|
||||
</p_network_username>
|
||||
<p_network_password type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z._\-\!\$\%\/\(\)\+\#\=]){1,128}$/u</mask>
|
||||
</p_network_password>
|
||||
<p_network_encryption type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</p_network_encryption>
|
||||
<p_graphite_enable type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</p_graphite_enable>
|
||||
<p_graphite_node type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
</p_graphite_node>
|
||||
<p_graphite_host type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/</mask>
|
||||
</p_graphite_host>
|
||||
<p_graphite_port type="IntegerField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<MinimumValue>1</MinimumValue>
|
||||
<MaximumValue>65535</MaximumValue>
|
||||
</p_graphite_port>
|
||||
<p_contextswitch_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_contextswitch_enable>
|
||||
<p_cpu_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_cpu_enable>
|
||||
<p_df_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_df_enable>
|
||||
<p_interface_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_interface_enable>
|
||||
<p_load_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_load_enable>
|
||||
<p_memory_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_memory_enable>
|
||||
<p_processes_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_processes_enable>
|
||||
<p_uptime_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_uptime_enable>
|
||||
<p_users_enable type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</p_users_enable>
|
||||
</items>
|
||||
</model>
|
||||
@@ -0,0 +1,5 @@
|
||||
<menu>
|
||||
<Services>
|
||||
<Collectd cssClass="fa fa-area-chart" url="/ui/collectd/general/index" />
|
||||
</Services>
|
||||
</menu>
|
||||
@@ -0,0 +1,60 @@
|
||||
{#
|
||||
|
||||
OPNsense® is Copyright © 2014 – 2017 by Deciso B.V.
|
||||
This file is Copyright © 2017 by Michael Muenz
|
||||
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'])}}
|
||||
<hr />
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
var data_get_map = {'frm_general_settings':"/api/collectd/general/get"};
|
||||
mapDataToFormUI(data_get_map).done(function(data){
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
});
|
||||
ajaxCall(url="/api/collectd/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
|
||||
// link save button to API set action
|
||||
$("#saveAct").click(function(){
|
||||
saveFormToEndpoint(url="/api/collectd/general/set", formid='frm_general_settings',callback_ok=function(){
|
||||
ajaxCall(url="/api/collectd/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
ajaxCall(url="/api/collectd/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p /var/db/collectd
|
||||
chown -R root:wheel /var/db/collectd
|
||||
chmod 750 /var/db/collectd
|
||||
@@ -0,0 +1,29 @@
|
||||
[start]
|
||||
command:/usr/local/opnsense/scripts/collectd/setup.sh;/usr/local/etc/rc.d/collectd start
|
||||
parameters:
|
||||
type:script
|
||||
message:starting collectd
|
||||
|
||||
[stop]
|
||||
command:/usr/local/etc/rc.d/collectd stop; exit 0
|
||||
parameters:
|
||||
type:script
|
||||
message:stopping collectd
|
||||
|
||||
[restart]
|
||||
command:/usr/local/opnsense/scripts/collectd/setup.sh;/usr/local/etc/rc.d/collectd restart
|
||||
parameters:
|
||||
type:script
|
||||
message:restarting collectd
|
||||
|
||||
[reconfigure]
|
||||
command:/usr/local/opnsense/scripts/collectd/setup.sh;/usr/local/etc/rc.d/collectd restart
|
||||
parameters:
|
||||
type:script
|
||||
message:reconfigure collectd
|
||||
|
||||
[status]
|
||||
command:/usr/local/etc/rc.d/collectd status;exit 0
|
||||
parameters:
|
||||
type:script_output
|
||||
message:request collectd status
|
||||
@@ -0,0 +1,2 @@
|
||||
collectd:/etc/rc.conf.d/collectd
|
||||
collectd.conf:/usr/local/etc/collectd.conf
|
||||
@@ -0,0 +1 @@
|
||||
collectd_enable="{% if helpers.exists('OPNsense.collectd.general.enabled') and OPNsense.collectd.general.enabled == '1' %}YES{% else %}NO{% endif %}"
|
||||
@@ -0,0 +1,110 @@
|
||||
{% if helpers.exists('OPNsense.collectd.general.enabled') and OPNsense.collectd.general.enabled == '1' %}
|
||||
|
||||
{% if helpers.exists('OPNsense.collectd.general.hostname') and OPNsense.collectd.general.hostname != '' %}
|
||||
Hostname "{{ OPNsense.collectd.general.hostname }}"
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.fqdnlookup') and OPNsense.collectd.general.fqdnlookup == '1' %}
|
||||
FQDNLookup true
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.interval') and OPNsense.collectd.general.interval != '' %}
|
||||
Interval {{ OPNsense.collectd.general.interval }}
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
||||
LoadPlugin syslog
|
||||
<Plugin syslog>
|
||||
LogLevel err
|
||||
</Plugin>
|
||||
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_contextswitch_enable') and OPNsense.collectd.general.p_contextswitch_enable == '1' %}
|
||||
LoadPlugin contextswitch
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_cpu_enable') and OPNsense.collectd.general.p_cpu_enable == '1' %}
|
||||
LoadPlugin cpu
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_df_enable') and OPNsense.collectd.general.p_df_enable == '1' %}
|
||||
LoadPlugin df
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_interface_enable') and OPNsense.collectd.general.p_interface_enable == '1' %}
|
||||
LoadPlugin interface
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_load_enable') and OPNsense.collectd.general.p_load_enable == '1' %}
|
||||
LoadPlugin load
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_memory_enable') and OPNsense.collectd.general.p_memory_enable == '1' %}
|
||||
LoadPlugin memory
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_enable') and OPNsense.collectd.general.p_network_enable == '1' %}
|
||||
LoadPlugin network
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_processes_enable') and OPNsense.collectd.general.p_processes_enable == '1' %}
|
||||
LoadPlugin processes
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_uptime_enable') and OPNsense.collectd.general.p_uptime_enable == '1' %}
|
||||
LoadPlugin uptime
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_users_enable') and OPNsense.collectd.general.p_users_enable == '1' %}
|
||||
LoadPlugin users
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_graphite_enable') and OPNsense.collectd.general.p_graphite_enable == '1' %}
|
||||
LoadPlugin write_graphite
|
||||
{% endif %}
|
||||
|
||||
##############################################################################
|
||||
# Plugin configuration #
|
||||
#----------------------------------------------------------------------------#
|
||||
# In this section configuration stubs for each plugin are provided. A desc- #
|
||||
# ription of those options is available in the collectd.conf(5) manual page. #
|
||||
##############################################################################
|
||||
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_enable') and OPNsense.collectd.general.p_network_enable == '1' %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_host') and OPNsense.collectd.general.p_network_host != '' %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_port') and OPNsense.collectd.general.p_network_port != '' %}
|
||||
<Plugin network>
|
||||
<Server "{{ OPNsense.collectd.general.p_network_host }}" "{{ OPNsense.collectd.general.p_network_port }}">
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_username') and OPNsense.collectd.general.p_network_username != '' %}
|
||||
Username "{{ OPNsense.collectd.general.p_network_username }}"
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_password') and OPNsense.collectd.general.p_network_password != '' %}
|
||||
Password "{{ OPNsense.collectd.general.p_network_password }}"
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_username') and OPNsense.collectd.general.p_network_username != '' %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_network_encryption') and OPNsense.collectd.general.p_network_encryption == '1' %}
|
||||
SecurityLevel Encrypt
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</Server>
|
||||
</Plugin>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_graphite_enable') and OPNsense.collectd.general.p_graphite_enable == '1' %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_graphite_node') and OPNsense.collectd.general.p_graphite_node != '' %}
|
||||
<Plugin write_graphite>
|
||||
<Node "{{ OPNsense.collectd.general.p_graphite_node }}">
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_graphite_host') and OPNsense.collectd.general.p_graphite_host != '' %}
|
||||
Host "{{ OPNsense.collectd.general.p_graphite_host }}"
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.collectd.general.p_graphite_port') and OPNsense.collectd.general.p_graphite_port != '' %}
|
||||
Port "{{ OPNsense.collectd.general.p_graphite_port }}"
|
||||
{% endif %}
|
||||
Protocol "tcp"
|
||||
ReconnectInterval 0
|
||||
LogSendErrors true
|
||||
Prefix "collectd"
|
||||
Postfix "collectd"
|
||||
StoreRates true
|
||||
AlwaysAppendDS false
|
||||
EscapeCharacter "_"
|
||||
SeparateInstances false
|
||||
PreserveSeparator false
|
||||
DropDuplicateFields false
|
||||
</Node>
|
||||
</Plugin>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user