diff --git a/net-mgmt/telegraf/Makefile b/net-mgmt/telegraf/Makefile new file mode 100644 index 000000000..6001637fc --- /dev/null +++ b/net-mgmt/telegraf/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= telegraf +PLUGIN_VERSION= 0.1 +PLUGIN_COMMENT= Agent for collecting metrics and data +PLUGIN_DEPENDS= telegraf +PLUGIN_MAINTAINER= m.muenz@gmail.com +PLUGIN_DEVEL= yes + +.include "../../Mk/plugins.mk" diff --git a/net-mgmt/telegraf/pkg-descr b/net-mgmt/telegraf/pkg-descr new file mode 100644 index 000000000..b2d0aee11 --- /dev/null +++ b/net-mgmt/telegraf/pkg-descr @@ -0,0 +1,10 @@ +Telegraf is the Agent for Collecting & Reporting Metrics & Data. +Telegraf has plugins or integrations to source a variety of +metrics directly from the system it’s running on, pull metrics +from third-party APIs, or even listen for metrics via a StatsD +and Kafka consumer services. It also has output plugins to send +metrics to a variety of other datastores, services, and message +queues, including InfluxDB, Graphite, OpenTSDB, Datadog, Librato, +Kafka, MQTT, NSQ, and many others. + +WWW: https://www.influxdata.com/time-series-platform/telegraf/ diff --git a/net-mgmt/telegraf/src/etc/inc/plugins.inc.d/telegraf.inc b/net-mgmt/telegraf/src/etc/inc/plugins.inc.d/telegraf.inc new file mode 100644 index 000000000..e7535e1c8 --- /dev/null +++ b/net-mgmt/telegraf/src/etc/inc/plugins.inc.d/telegraf.inc @@ -0,0 +1,49 @@ + gettext('telegraf agent'), + 'configd' => array( + 'restart' => array('telegraf restart'), + 'start' => array('telegraf start'), + 'stop' => array('telegraf stop'), + ), + 'name' => 'telegraf', + 'pidfile' => '/var/run/telegraf.pid' + ); + } + + return $services; +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/GeneralController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/GeneralController.php new file mode 100644 index 000000000..963d21f05 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/GeneralController.php @@ -0,0 +1,77 @@ +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; + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/InputController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/InputController.php new file mode 100644 index 000000000..2553e6d37 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/InputController.php @@ -0,0 +1,77 @@ +request->isGet()) { + $mdlInput = new Input(); + $result['input'] = $mdlInput->getNodes(); + } + return $result; + } + + public function setAction() + { + $result = array("result"=>"failed"); + if ($this->request->isPost()) { + // load model and update with provided data + $mdlInput = new Input(); + $mdlInput->setNodes($this->request->getPost("input")); + + // perform validation + $valMsgs = $mdlInput->performValidation(); + foreach ($valMsgs as $field => $msg) { + if (!array_key_exists("validations", $result)) { + $result["validations"] = array(); + } + $result["validations"]["input.".$msg->getField()] = $msg->getMessage(); + } + + // serialize model to config and save + if ($valMsgs->count() == 0) { + $mdlInput->serializeToConfig(); + Config::getInstance()->save(); + $result["result"] = "saved"; + } + } + return $result; + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/OutputController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/OutputController.php new file mode 100644 index 000000000..cd754a8d5 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/OutputController.php @@ -0,0 +1,77 @@ +request->isGet()) { + $mdlOutput = new Output(); + $result['output'] = $mdlOutput->getNodes(); + } + return $result; + } + + public function setAction() + { + $result = array("result"=>"failed"); + if ($this->request->isPost()) { + // load model and update with provided data + $mdlOutput = new Output(); + $mdlOutput->setNodes($this->request->getPost("output")); + + // perform validation + $valMsgs = $mdlOutput->performValidation(); + foreach ($valMsgs as $field => $msg) { + if (!array_key_exists("validations", $result)) { + $result["validations"] = array(); + } + $result["validations"]["output.".$msg->getField()] = $msg->getMessage(); + } + + // serialize model to config and save + if ($valMsgs->count() == 0) { + $mdlOutput->serializeToConfig(); + Config::getInstance()->save(); + $result["result"] = "saved"; + } + } + return $result; + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/ServiceController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/ServiceController.php new file mode 100644 index 000000000..6405ae545 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/Api/ServiceController.php @@ -0,0 +1,149 @@ +request->isPost()) { + $backend = new Backend(); + $response = $backend->configdRun("telegraf start", true); + return array("response" => $response); + } else { + return array("response" => array()); + } + } + + /** + * stop telegraf service + * @return array + */ + public function stopAction() + { + if ($this->request->isPost()) { + $backend = new Backend(); + $response = $backend->configdRun("telegraf stop"); + return array("response" => $response); + } else { + return array("response" => array()); + } + } + + /** + * restart telegraf service + * @return array + */ + public function restartAction() + { + if ($this->request->isPost()) { + $backend = new Backend(); + $response = $backend->configdRun("telegraf restart"); + return array("response" => $response); + } else { + return array("response" => array()); + } + } + + /** + * retrieve status of telegraf + * @return array + * @throws \Exception + */ + public function statusAction() + { + $backend = new Backend(); + $mdlGeneral = new General(); + $response = $backend->configdRun("telegraf 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 telegraf, 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 telegraf if it is running or not + $this->stopAction(); + + // generate template + $backend->configdRun('template reload OPNsense/Telegraf'); + + // (res)start daemon + if ($mdlGeneral->enabled->__toString() == 1) { + $this->startAction(); + } + + return array("status" => "ok"); + } else { + return array("status" => "failed"); + } + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/GeneralController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/GeneralController.php new file mode 100644 index 000000000..6fe9fdb69 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/GeneralController.php @@ -0,0 +1,39 @@ +view->title = gettext("Telegraf Settings"); + $this->view->generalForm = $this->getForm("general"); + $this->view->pick('OPNsense/Telegraf/general'); + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/InputController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/InputController.php new file mode 100644 index 000000000..897fde613 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/InputController.php @@ -0,0 +1,39 @@ +view->title = gettext("Telegraf Inputs"); + $this->view->inputForm = $this->getForm("input"); + $this->view->pick('OPNsense/Telegraf/input'); + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/OutputController.php b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/OutputController.php new file mode 100644 index 000000000..2669d7b33 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/OutputController.php @@ -0,0 +1,39 @@ +view->title = gettext("Telegraf Outputs"); + $this->view->outputForm = $this->getForm("output"); + $this->view->pick('OPNsense/Telegraf/output'); + } +} diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/general.xml b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/general.xml new file mode 100644 index 000000000..751392b89 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/general.xml @@ -0,0 +1,62 @@ +
+ + general.enabled + + checkbox + This will activate the telegraf agent. + + + general.interval + + text + Default data collection interval for all inputs in seconds. + + + general.roundinterval + + checkbox + Rounds collection interval to 'interval', e.g. if interval="10s" then always collect on :00, :10, :20, etc. + + + general.metric_batch_size + + text + Telegraf will send metrics to outputs in batches of at most metric_batch_size metrics. This controls the size of writes that Telegraf sends to output plugins. + + + general.metric_buffer_limit + + text + For failed writes, Telegraf will cache metric_buffer_limit metrics for each output, and will flush this buffer on a successful write. + + + general.collection_jitter + + text + Collection jitter is used to jitter the collection by a random amount. Each plugin will sleep for a random time within jitter before collecting. Input value are seconds. + + + general.flush_interval + + text + Default flushing interval for all outputs. You should not set this below interval. + + + general.flush_jitter + + text + Jitter the flush interval by a random amount. This is primarily to avoid large write spikes for users running a large number of telegraf instances. + + + general.hostname + + text + Override default hostname, if empty use system hostname. + + + general.omit_hostname + + checkbox + If set to true, do no set the "host" tag in the Telegraf agent. + +
diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/input.xml b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/input.xml new file mode 100644 index 000000000..c44357f19 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/input.xml @@ -0,0 +1,74 @@ +
+ + input.cpu + + checkbox + Read metrics about CPU usage. + + + input.cpu_percpu + + checkbox + Whether to report Per-CPU stats or not. + + + input.cpu_totalcpu + + checkbox + Whether to report total system CPU stats or not. + + + input.cpu_collect_cpu_time + + checkbox + If true, collect raw CPU time metrics. + + + input.disk + + checkbox + Read metrics about disk usage by mount point. + + + input.disk_mount_points + + text + By default, Telegraf gather stats for all mountpoints. Setting mountpoints will restrict the stats to the specified mountpoints. + + + input.disk_ignore_fs + + text + Ignore some mountpoints by filesystem type. For example (dev)tmpfs (usually present on /run, /var/run, /dev/shm or /dev). + + + input.diskio + + checkbox + Read metrics about disk IO by device. + + + input.mem + + checkbox + Read metrics about memory usage. + + + input.processes + + checkbox + Get the number of processes and group them by status. + + + input.swap + + checkbox + Read metrics about swap memory usage. + + + input.system + + checkbox + Read metrics about system load and uptime. + +
diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/output.xml b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/output.xml new file mode 100644 index 000000000..37c0c2fef --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/output.xml @@ -0,0 +1,38 @@ +
+ + output.influx_enable + + checkbox + This will enable InfluxDB as output. + + + output.influx_url + + text + Set the URL where metrics shoud be sent to. + + + output.influx_database + + text + Set the name of the database on InfluxDB. + + + output.influx_timeout + + text + Write timeout (for the InfluxDB client), formatted as a string. If not provided, will default to 5s. 0s means no timeout (not recommended). + + + output.influx_username + + text + Set the username for authentication. + + + output.influx_password + + text + Set the password for authentication. + +
diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/ACL/ACL.xml b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/ACL/ACL.xml new file mode 100644 index 000000000..d5fbeb3f1 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/ACL/ACL.xml @@ -0,0 +1,9 @@ + + + Services: Telegraf + + ui/telegraf/* + api/telegraf/* + + + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/General.php b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/General.php new file mode 100644 index 000000000..ed04d359d --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/General.php @@ -0,0 +1,35 @@ + + //OPNsense/telegraf/general + Telegraf general configuration + 1.0.0 + + + 0 + Y + + + 10 + Y + + + 1 + Y + + + 1000 + Y + + + 10000 + Y + + + 0 + Y + + + 10 + Y + + + 0 + Y + + + + N + + + 0 + Y + + + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Input.php b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Input.php new file mode 100644 index 000000000..0bb26d44f --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Input.php @@ -0,0 +1,35 @@ + + //OPNsense/telegraf/input + Telegraf inputs configuration + 1.0.0 + + + 1 + N + + + 1 + N + + + 1 + N + + + 0 + N + + + 1 + N + + + + N + + + + N + + + 1 + N + + + 1 + N + + + 1 + N + + + 0 + N + + + 1 + N + + + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Menu/Menu.xml b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Menu/Menu.xml new file mode 100644 index 000000000..a65cadbdf --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Menu/Menu.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Output.php b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Output.php new file mode 100644 index 000000000..706945e43 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/models/OPNsense/Telegraf/Output.php @@ -0,0 +1,35 @@ + + //OPNsense/telegraf/output + Telegraf outputs configuration + 1.0.0 + + + 0 + N + + + + N + + + + N + + + 5 + N + + + + N + + + + N + + + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/general.volt b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/general.volt new file mode 100644 index 000000000..3909801d2 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/general.volt @@ -0,0 +1,70 @@ +{# + +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. + +#} + + +
+
+
+ {{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}} +
+
+ +
+
+
+
+ + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/input.volt b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/input.volt new file mode 100644 index 000000000..9df20427b --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/input.volt @@ -0,0 +1,70 @@ +{# + +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. + +#} + + +
+
+
+ {{ partial("layout_partials/base_form",['fields':inputForm,'id':'frm_input_settings'])}} +
+
+ +
+
+
+
+ + diff --git a/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/output.volt b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/output.volt new file mode 100644 index 000000000..631a38815 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/mvc/app/views/OPNsense/Telegraf/output.volt @@ -0,0 +1,70 @@ +{# + +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. + +#} + + +
+
+
+ {{ partial("layout_partials/base_form",['fields':outputForm,'id':'frm_output_settings'])}} +
+
+ +
+
+
+
+ + diff --git a/net-mgmt/telegraf/src/opnsense/service/conf/actions.d/actions_telegraf.conf b/net-mgmt/telegraf/src/opnsense/service/conf/actions.d/actions_telegraf.conf new file mode 100644 index 000000000..dcb94c791 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/service/conf/actions.d/actions_telegraf.conf @@ -0,0 +1,29 @@ +[start] +command:/usr/local/etc/rc.d/telegraf start +parameters: +type:script +message:starting telegraf + +[stop] +command:/usr/local/etc/rc.d/telegraf stop; exit 0 +parameters: +type:script +message:stopping telegraf + +[restart] +command:/usr/local/etc/rc.d/telegraf restart +parameters: +type:script +message:restarting telegraf + +[reconfigure] +command:/usr/local/etc/rc.d/telegraf restart +parameters: +type:script +message:reconfigure telegraf + +[status] +command:/usr/local/etc/rc.d/telegraf status;exit 0 +parameters: +type:script_output +message:request telegraf status diff --git a/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/+TARGETS b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/+TARGETS new file mode 100644 index 000000000..0958f7dd8 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/+TARGETS @@ -0,0 +1,2 @@ +telegraf:/etc/rc.conf.d/telegraf +telegraf.conf:/usr/local/etc/telegraf.conf diff --git a/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf new file mode 100644 index 000000000..599493506 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf @@ -0,0 +1,5 @@ +{% if helpers.exists('OPNsense.telegraf.general.enabled') and OPNsense.telegraf.general.enabled == '1' %} +telegraf_enable="YES" +{% else %} +telegraf_enable="NO" +{% endif %} diff --git a/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf.conf b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf.conf new file mode 100644 index 000000000..04ae5d200 --- /dev/null +++ b/net-mgmt/telegraf/src/opnsense/service/templates/OPNsense/Telegraf/telegraf.conf @@ -0,0 +1,109 @@ +{% if helpers.exists('OPNsense.telegraf.general.enabled') and OPNsense.telegraf.general.enabled == '1' %} + +[global_tags] + +[agent] +{% if helpers.exists('OPNsense.telegraf.general.interval') and OPNsense.telegraf.general.interval != '' %} + interval = "{{ OPNsense.telegraf.general.interval }}s" +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.round_interval') and OPNsense.telegraf.general.round_interval == '1' %} + round_interval = true +{% else %} + round_interval = false +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.metric_batch_size') and OPNsense.telegraf.general.metric_batch_size != '' %} + metric_batch_size = {{ OPNsense.telegraf.general.metric_batch_size }} +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.metric_buffer_limit') and OPNsense.telegraf.general.metric_buffer_limit != '' %} + metric_buffer_limit = {{ OPNsense.telegraf.general.metric_buffer_limit }} +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.collection_jitter') and OPNsense.telegraf.general.collection_jitter != '' %} + collection_jitter = "{{ OPNsense.telegraf.general.collection_jitter }}s" +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.flush_jitter') and OPNsense.telegraf.general.flush_jitter != '' %} + flush_jitter = "{{ OPNsense.telegraf.general.flush_jitter }}s" +{% endif %} + precision = "" + debug = false + quiet = true + logfile = "/var/log/telegraf.log" +{% if helpers.exists('OPNsense.telegraf.general.hostname') and OPNsense.telegraf.general.hostname != '' %} + hostname = "{{ OPNsense.telegraf.general.hostname }}" +{% endif %} +{% if helpers.exists('OPNsense.telegraf.general.omit_hostname') and OPNsense.telegraf.general.omit_hostname == '1' %} + omit_hostname = true +{% else %} + omit_hostname = false +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.output.influx_enable') and OPNsense.telegraf.output.influx_enable == '1' %} +[[outputs.influxdb]] +{% if helpers.exists('OPNsense.telegraf.output.influx_url') and OPNsense.telegraf.output.influx_url != '' %} + urls = ["{{ OPNsense.telegraf.output.influx_url }}"] +{% endif %} +{% if helpers.exists('OPNsense.telegraf.output.influx_database') and OPNsense.telegraf.output.influx_database != '' %} + database = "{{ OPNsense.telegraf.output.influx_database }}" +{% endif %} + retention_policy = "" + write_consistency = "any" +{% if helpers.exists('OPNsense.telegraf.output.influx_timeout') and OPNsense.telegraf.output.influx_timeout != '' %} + timeout = "{{ OPNsense.telegraf.output.influx_timeout }}s" +{% endif %} +{% if helpers.exists('OPNsense.telegraf.output.influx_username') and OPNsense.telegraf.output.influx_username != '' %} + username = "{{ OPNsense.telegraf.output.influx_username }}" +{% endif %} +{% if helpers.exists('OPNsense.telegraf.output.influx_password') and OPNsense.telegraf.output.influx_password != '' %} + password = "{{ OPNsense.telegraf.output.influx_password }}" +{% endif %} +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.cpu') and OPNsense.telegraf.input.cpu == '1' %} +[[inputs.cpu]] +{% if helpers.exists('OPNsense.telegraf.input.cpu_percpu') and OPNsense.telegraf.input.cpu_percpu == '1' %} + percpu = true +{% else %} + percpu = false +{% endif %} +{% if helpers.exists('OPNsense.telegraf.input.cpu_totalcpu') and OPNsense.telegraf.input.cpu_totalcpu == '1' %} + totalcpu = true +{% else %} + totalcpu = false +{% endif %} +{% if helpers.exists('OPNsense.telegraf.input.collect_cpu_time') and OPNsense.telegraf.input.collect_cpu_time == '1' %} + collect_cpu_time = true +{% else %} + collect_cpu_time = false +{% endif %} +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.disk') and OPNsense.telegraf.input.disk == '1' %} +[[inputs.disk]] +{% if helpers.exists('OPNsense.telegraf.input.disk_mount_points') and OPNsense.telegraf.input.disk_mount_points != '' %} + mount_points = ["{{ OPNsense.telegraf.input.disk_mount_points }}"] +{% endif %} +{% if helpers.exists('OPNsense.telegraf.input.disk_ignore_fs') and OPNsense.telegraf.input.disk_ignore_fs != '' %} + ignore_fs = ["{{ OPNsense.telegraf.input.disk_ignore_fs }}"] +{% endif %} +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.diskio') and OPNsense.telegraf.input.diskio == '1' %} +[[inputs.diskio]] +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.mem') and OPNsense.telegraf.input.mem == '1' %} +[[inputs.mem]] +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.processes') and OPNsense.telegraf.input.processes == '1' %} +[[inputs.processes]] +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.swap') and OPNsense.telegraf.input.swap == '1' %} +[[inputs.swap]] +{% endif %} + +{% if helpers.exists('OPNsense.telegraf.input.system') and OPNsense.telegraf.input.system == '1' %} +[[inputs.system]] +{% endif %} + +{% endif %}