mirror of
https://github.com/opnsense/plugins.git
synced 2026-05-28 04:34:15 -04:00
net-mgmt/telegraf: version 1.7.0
This commit is contained in:
parent
6cb90bd889
commit
ed72f97596
13 changed files with 291 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
|||
PLUGIN_NAME= telegraf
|
||||
PLUGIN_VERSION= 1.5.1
|
||||
PLUGIN_VERSION= 1.7.0
|
||||
PLUGIN_COMMENT= Agent for collecting metrics and data
|
||||
PLUGIN_DEPENDS= telegraf
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 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\Telegraf\Api;
|
||||
|
||||
use \OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class KeyController extends ApiMutableModelControllerBase
|
||||
{
|
||||
static protected $internalModelName = 'key';
|
||||
static protected $internalModelClass = '\OPNsense\Telegraf\Key';
|
||||
|
||||
public function searchKeyAction()
|
||||
{
|
||||
return $this->searchBase('keys.key', array("enabled", "name", "value"));
|
||||
}
|
||||
public function getKeyAction($uuid = null)
|
||||
{
|
||||
$this->sessionClose();
|
||||
return $this->getBase('key', 'keys.key', $uuid);
|
||||
}
|
||||
public function addKeyAction()
|
||||
{
|
||||
return $this->addBase('key', 'keys.key');
|
||||
}
|
||||
public function delKeyAction($uuid)
|
||||
{
|
||||
return $this->delBase('keys.key', $uuid);
|
||||
}
|
||||
public function setKeyAction($uuid)
|
||||
{
|
||||
return $this->setBase('key', 'keys.key', $uuid);
|
||||
}
|
||||
public function toggleKeyAction($uuid)
|
||||
{
|
||||
return $this->toggleBase('keys.key', $uuid);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ class GeneralController extends \OPNsense\Base\IndexController
|
|||
public function indexAction()
|
||||
{
|
||||
$this->view->generalForm = $this->getForm("general");
|
||||
$this->view->formDialogEditTelegrafKey = $this->getForm("dialogEditTelegrafKey");
|
||||
$this->view->pick('OPNsense/Telegraf/general');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<form>
|
||||
<field>
|
||||
<id>key.enabled</id>
|
||||
<label>Enabled</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will enable or disable the key mapping.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>key.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>Set the name of this mapping.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>key.value</id>
|
||||
<label>Value</label>
|
||||
<type>text</type>
|
||||
<help>Set the value of the defined key.</help>
|
||||
</field>
|
||||
</form>
|
||||
|
|
@ -79,6 +79,12 @@
|
|||
<type>checkbox</type>
|
||||
<help>Read network interface metrics.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>input.pf</id>
|
||||
<label>PF</label>
|
||||
<type>checkbox</type>
|
||||
<help>Read PF values via pfctl.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>input.ping</id>
|
||||
<label>Ping</label>
|
||||
|
|
@ -93,4 +99,10 @@
|
|||
<allownew>true</allownew>
|
||||
<help>Set the Hosts to ping in a CSV list.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>input.haproxy</id>
|
||||
<label>HAProxy</label>
|
||||
<type>checkbox</type>
|
||||
<help>Enable the collection of HAProxy statistics.</help>
|
||||
</field>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -101,4 +101,28 @@
|
|||
<type>text</type>
|
||||
<help>Set the index name.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>output.prometheus_enable</id>
|
||||
<label>Enable Prometheus Output</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will enable Prometheus as output.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>output.prometheus_listen</id>
|
||||
<label>Prometheus Listen Port</label>
|
||||
<type>text</type>
|
||||
<help>Port to listen on.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>output.prometheus_exclude</id>
|
||||
<label>Prometheus Collector Exclude</label>
|
||||
<type>text</type>
|
||||
<help>Collectors to enable, valid entries are "gocollector" and "process". If unset, both are enabled.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>output.prometheus_stringaslabel</id>
|
||||
<label>Prometheus String as Label</label>
|
||||
<type>checkbox</type>
|
||||
<help>Send string metrics as Prometheus labels.</help>
|
||||
</field>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<model>
|
||||
<mount>//OPNsense/telegraf/input</mount>
|
||||
<description>Telegraf inputs configuration</description>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1</version>
|
||||
<items>
|
||||
<cpu type="BooleanField">
|
||||
<default>1</default>
|
||||
|
|
@ -55,6 +55,10 @@
|
|||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</network>
|
||||
<pf type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</pf>
|
||||
<ping type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
|
|
@ -62,5 +66,9 @@
|
|||
<ping_hosts type="CSVListField">
|
||||
<Required>N</Required>
|
||||
</ping_hosts>
|
||||
<haproxy type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</haproxy>
|
||||
</items>
|
||||
</model>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 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\Telegraf;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class Key extends BaseModel
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<model>
|
||||
<mount>//OPNsense/telegraf/key</mount>
|
||||
<description>Telegraf key configuration</description>
|
||||
<version>1.0.0</version>
|
||||
<items>
|
||||
<keys>
|
||||
<key type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<name type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z._\-]){1,128}$/u</mask>
|
||||
</name>
|
||||
<value type="TextField">
|
||||
<default></default>
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z._\-]){1,128}$/u</mask>
|
||||
</value>
|
||||
</key>
|
||||
</keys>
|
||||
</items>
|
||||
</model>
|
||||
|
|
@ -66,5 +66,20 @@
|
|||
<default>telegraf-%Y.%m.%d</default>
|
||||
<Required>N</Required>
|
||||
</elastic_indexname>
|
||||
<prometheus_enable type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>N</Required>
|
||||
</prometheus_enable>
|
||||
<prometheus_listen type="PortField">
|
||||
<default>9273</default>
|
||||
<Required>N</Required>
|
||||
</prometheus_listen>
|
||||
<prometheus_exclude type="CSVListField">
|
||||
<Required>N</Required>
|
||||
</prometheus_exclude>
|
||||
<prometheus_stringaslabel type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>N</Required>
|
||||
</prometheus_stringaslabel>
|
||||
</items>
|
||||
</model>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
|
||||
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#keys">{{ lang._('Tags') }}</a></li>
|
||||
</ul>
|
||||
<div class="tab-content content-box tab-content">
|
||||
<div id="general" class="tab-pane fade in active">
|
||||
|
|
@ -40,8 +41,38 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="keys" class="tab-pane fade in">
|
||||
<table id="grid-keys" class="table table-responsive" data-editDialog="dialogEditTelegrafKey">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
|
||||
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
|
||||
<th data-column-id="value" data-type="string" data-visible="true">{{ lang._('Value') }}</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5"></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="col-md-12">
|
||||
<hr />
|
||||
<button class="btn btn-primary" id="saveAct_key" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_key_progress"></i></button>
|
||||
<br /><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditTelegrafKey,'id':'dialogEditTelegrafKey','label':lang._('Edit Mapping')])}}
|
||||
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
var data_get_map = {'frm_general_settings':"/api/telegraf/general/get"};
|
||||
|
|
@ -50,21 +81,36 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
$('.selectpicker').selectpicker('refresh');
|
||||
});
|
||||
|
||||
ajaxCall(url="/api/telegraf/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
updateServiceControlUI('telegraf');
|
||||
|
||||
$("#grid-keys").UIBootgrid(
|
||||
{ 'search':'/api/telegraf/key/searchKey',
|
||||
'get':'/api/telegraf/key/getKey/',
|
||||
'set':'/api/telegraf/key/setKey/',
|
||||
'add':'/api/telegraf/key/addKey/',
|
||||
'del':'/api/telegraf/key/delKey/',
|
||||
'toggle':'/api/telegraf/key/toggleKey/'
|
||||
}
|
||||
);
|
||||
|
||||
// link save button to API set action
|
||||
$("#saveAct").click(function(){
|
||||
saveFormToEndpoint(url="/api/telegraf/general/set", formid='frm_general_settings',callback_ok=function(){
|
||||
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/telegraf/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
ajaxCall(url="/api/telegraf/service/status", sendData={}, callback=function(data,status) {
|
||||
updateServiceStatusUI(data['status']);
|
||||
});
|
||||
updateServiceControlUI('telegraf');
|
||||
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
});
|
||||
});
|
||||
});
|
||||
$("#saveAct_key").click(function(){
|
||||
saveFormToEndpoint(url="/api/telegraf/key/set", formid='frm_general_settings',callback_ok=function(){
|
||||
$("#saveAct_key_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/telegraf/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
updateServiceControlUI('telegraf');
|
||||
$("#saveAct_key_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
5
net-mgmt/telegraf/src/opnsense/scripts/OPNsense/Telegraf/setup.sh
Executable file
5
net-mgmt/telegraf/src/opnsense/scripts/OPNsense/Telegraf/setup.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
mkdir -p /var/log/telegraf
|
||||
chown -R telegraf:telegraf /var/log/telegraf
|
||||
chmod 750 /var/log/telegraf
|
||||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
[global_tags]
|
||||
|
||||
{% if helpers.exists('OPNsense.telegraf.key.keys.key') %}
|
||||
{% for key_list in helpers.toList('OPNsense.telegraf.key.keys.key') %}
|
||||
{% if key_list.enabled == '1' %}
|
||||
{{ key_list.name }} = "{{ key_list.value }}"
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
[agent]
|
||||
{% if helpers.exists('OPNsense.telegraf.general.interval') and OPNsense.telegraf.general.interval != '' %}
|
||||
interval = "{{ OPNsense.telegraf.general.interval }}s"
|
||||
|
|
@ -26,7 +34,6 @@
|
|||
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 %}
|
||||
|
|
@ -96,6 +103,21 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.telegraf.output.prometheus_enable') and OPNsense.telegraf.output.prometheus_enable == '1' %}
|
||||
[[outputs.prometheus_client]]
|
||||
{% if helpers.exists('OPNsense.telegraf.output.prometheus_listen') and OPNsense.telegraf.output.prometheus_listen != '' %}
|
||||
listen = ":{{ OPNsense.telegraf.output.prometheus_listen }}"
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.telegraf.output.prometheus_exclude') and OPNsense.telegraf.output.prometheus_exclude != '' %}
|
||||
collectors_exclude = [{{ "'" + ("','".join(OPNsense.telegraf.output.prometheus_exclude.split(','))) + "'" }}]
|
||||
{% endif %}
|
||||
{% if helpers.exists('OPNsense.telegraf.output.prometheus_stringaslabel') and OPNsense.telegraf.output.prometheus_stringaslabel == '1' %}
|
||||
string_as_label = true
|
||||
{% else %}
|
||||
string_as_label = false
|
||||
{% 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' %}
|
||||
|
|
@ -149,6 +171,10 @@
|
|||
[[inputs.net]]
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.telegraf.input.pf') and OPNsense.telegraf.input.pf == '1' %}
|
||||
[[inputs.pf]]
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.telegraf.input.ping') and OPNsense.telegraf.input.ping == '1' %}
|
||||
[[inputs.ping]]
|
||||
{% if helpers.exists('OPNsense.telegraf.input.ping_hosts') and OPNsense.telegraf.input.ping_hosts != '' %}
|
||||
|
|
@ -156,4 +182,9 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if helpers.exists('OPNsense.telegraf.input.haproxy') and OPNsense.telegraf.input.haproxy == '1' %}
|
||||
[[inputs.haproxy]]
|
||||
servers = ["socket:/var/run/haproxy.socket"]
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue