Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegraf updated to 1.6.1, and fixes Redmine #8425 #517

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function telegraf_resync_config() {

[[inputs.system]]

[[inputs.pf]]

EOD;

Expand Down
11 changes: 7 additions & 4 deletions net-mgmt/telegraf/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Created by: Stefan Lambrev <cheffo@freebsd-bg.org>
# $FreeBSD$
# $FreeBSD: $

PORTNAME= telegraf
DISTVERSION= 1.5.3
DISTVERSION= 1.6.1
CATEGORIES= net-mgmt

MAINTAINER= girgen@FreeBSD.org
Expand All @@ -20,6 +20,9 @@ USE_GITHUB= yes

GH_ACCOUNT= influxdata:DEFAULT
GH_TUPLE= collectd:go-collectd:2ce1445:collectd_org/src/collectd.org \
tidwall:gjson:01f00f1:gjson/src/github.com/tidwall/gjson \
tidwall:match:1731857:match/src/github.com/tidwall/match \
go-redis:redis:877867d:redis/src/github.com/go-redis/redis \
aerospike:aerospike-client-go:95e1ad7:aerospike_client_go/src/github.com/aerospike/aerospike-client-go \
amir:raidman:c74861f:raidman/src/github.com/amir/raidman \
apache:thrift:4aaa92ec:thrift/src/github.com/apache/thrift \
Expand Down Expand Up @@ -82,7 +85,7 @@ GH_TUPLE= collectd:go-collectd:2ce1445:collectd_org/src/collectd.org \
rcrowley:go-metrics:1f30fe9:go_metrics/src/github.com/rcrowley/go-metrics \
samuel:go-zookeeper:1d7be4e:go_zookeeper/src/github.com/samuel/go-zookeeper \
satori:go.uuid:5bf94b6:go_uuid/src/github.com/satori/go.uuid \
shirou:gopsutil:384a551:gopsutil/src/github.com/shirou/gopsutil \
shirou:gopsutil:a5c2888:gopsutil/src/github.com/shirou/gopsutil \
shirou:w32:3c9377f:w32/src/github.com/shirou/w32 \
Shopify:sarama:3b1b388:sarama/src/github.com/Shopify/sarama \
Sirupsen:logrus:61e43dc:logrus/src/github.com/Sirupsen/logrus \
Expand Down Expand Up @@ -119,7 +122,7 @@ PLIST_SUB= TELEGRAF_PIDDIR=${TELEGRAF_PIDDIR}
post-patch:
@${MKDIR} ${WRKSRC}/src/github.com/${GH_ACCOUNT_DEFAULT}/${PORTNAME}
@cd ${WRKSRC} && ${MV} appveyor.yml CHANGELOG.md CONTRIBUTING.md Godeps \
LICENSE Makefile README.md accumulator.go agent aggregator.go circle.yml cmd docs etc filter \
LICENSE Makefile README.md accumulator.go agent aggregator.go cmd docs etc filter \
input.go internal logger metric metric.go output.go plugins processor.go scripts selfstat testutil \
${WRKSRC}/src/github.com/${GH_ACCOUNT_DEFAULT}/${PORTNAME}
${LN} -s nats ${WRKSRC}/src/github.com/nats-io/go-nats
Expand Down
59 changes: 59 additions & 0 deletions net-mgmt/telegraf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
This custom telegraf-1.6.1 port is to address a buffer/memory issue in Telegraf <= 1.5.3 on amd64 FreeBSD
and pfSense 11.1-RELEASE instances:

<https://redmine.pfsense.org/issues/8425>

<https://github.com/influxdata/telegraf/issues/3750>

I worked with an InfluxDB dev., and we found the issue. This modified port, fixes the
`[inputs.mem]` issue where memory measurement are not being reported, and throws
` Error in plug-in [inputs.mem]: error getting virtual memory info: cannot allocate memory` errors.

This port also installs the latest Telegraf version (1.6.1), which has a host of new and add'l external
golang deps not defined in the current Q2018 FreeBSD ports upstream version (telegraf v1.5.3).

ALSO: This newer port adds PF metrics (`pfctl/pfstat`) to Telegraf/InfluxDB. See screenshot below. Not
sure why the pfSense package maintainer never enabled this native plug-in/input in the .inc config file. *shrug*

New PF state measurements supported:

- pf
- entries (integer, count)
- searches (integer, count)
- inserts (integer, count)
- removals (integer, count)

### Example Output:

```
> pfctl -s info
Status: Enabled for 0 days 00:26:05 Debug: Urgent

State Table Total Rate
current entries 2
searches 11325 7.2/s
inserts 5 0.0/s
removals 3 0.0/s
Counters
match 11226 7.2/s
bad-offset 0 0.0/s
fragment 0 0.0/s
short 0 0.0/s
normalize 0 0.0/s
memory 0 0.0/s
bad-timestamp 0 0.0/s
congestion 0 0.0/s
ip-option 0 0.0/s
proto-cksum 0 0.0/s
state-mismatch 0 0.0/s
state-insert 0 0.0/s
state-limit 0 0.0/s
src-limit 0 0.0/s
synproxy 0 0.0/s
```


Build and use at your own risk.

## Screenshot:
![alt text](http://techdocs.cuccio.us/telegraf-pf.png "Screenshot: Graph of PF State Tables")
16 changes: 11 additions & 5 deletions net-mgmt/telegraf/distinfo
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
TIMESTAMP = 1521117537
SHA256 (influxdata-telegraf-1.5.3_GH0.tar.gz) = 0f2cedbed05a82938fefac14258390839a61aa82dd87a4350a608b70196e292b
SIZE (influxdata-telegraf-1.5.3_GH0.tar.gz) = 911976
TIMESTAMP = 15245723493
SHA256 (influxdata-telegraf-1.6.1_GH0.tar.gz) = 5f5af61b40fd6da742813e8e865f5a9e6545cfc92d88df904e9e2488f41104c9
SIZE (influxdata-telegraf-1.6.1_GH0.tar.gz) = 971026
SHA256 (go-redis-redis-877867d_GH0.tar.gz) = 118ca92e253f59dd02ca48edae2f99a092c65850d1e4ae58402a7e70d27c75f0
SIZE (go-redis-redis-877867d_GH0.tar.gz) = 78843
SHA256 (tidwall-gjson-01f00f1_GH0.tar.gz) = eb9388b5baccf375555ebe5274adaeef7acc39b9b8bf5d89e6aeb393d9f8efcc
SIZE (tidwall-gjson-01f00f1_GH0.tar.gz) = 39891
SHA256 (tidwall-match-1731857_GH0.tar.gz) = e331b585187933030daa6d79da92052170c47ea37f1ebb947675ec14f586702a
SIZE (tidwall-match-1731857_GH0.tar.gz) = 4274
SHA256 (collectd-go-collectd-2ce1445_GH0.tar.gz) = 5d27107b1f84ca89edf2f8a0e75b0b051d5f6a229da1fa90f1f53a6fa4ce7355
SIZE (collectd-go-collectd-2ce1445_GH0.tar.gz) = 39622
SHA256 (aerospike-aerospike-client-go-95e1ad7_GH0.tar.gz) = bbe30af22410d0bff33f28bdf24c7eab75d9756c310eaca8b9317e090ba4b936
Expand Down Expand Up @@ -127,8 +133,8 @@ SHA256 (samuel-go-zookeeper-1d7be4e_GH0.tar.gz) = 01cdf3957ff3bbdd78dbe716d2ad3d
SIZE (samuel-go-zookeeper-1d7be4e_GH0.tar.gz) = 32131
SHA256 (satori-go.uuid-5bf94b6_GH0.tar.gz) = eb26d69da0a36d9318183dd4a15b162cf8d6e4493f6c12ae635ba0a072e06da1
SIZE (satori-go.uuid-5bf94b6_GH0.tar.gz) = 7607
SHA256 (shirou-gopsutil-384a551_GH0.tar.gz) = a9aae364a2eb1fb8d608fc583237c67288b2eeb30ae46b8084c5e357cdce0750
SIZE (shirou-gopsutil-384a551_GH0.tar.gz) = 107169
SHA256 (shirou-gopsutil-a5c2888_GH0.tar.gz) = 5389be8ba02562d1490a9b58f5138986e741a156f45b558659f13eaa636de9fe
SIZE (shirou-gopsutil-a5c2888_GH0.tar.gz) = 114521
SHA256 (shirou-w32-3c9377f_GH0.tar.gz) = e88350823aa8a43767c3ed11b60854622e9f0ceb1d7029aa5923e0158d15a482
SIZE (shirou-w32-3c9377f_GH0.tar.gz) = 44304
SHA256 (Shopify-sarama-3b1b388_GH0.tar.gz) = 5a9d99b2aba298b380456c6f27390085f2ba41c97a7ed92e2d1748ddb791f4b2
Expand Down
9 changes: 9 additions & 0 deletions net-mgmt/telegraf/files/etc/inc/priv/telegraf.priv.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
global $priv_list;

$priv_list['page-services-telegraf'] = array();
$priv_list['page-services-telegraf']['name'] = "WebCfg - Services: Telegraf";
$priv_list['page-services-telegraf']['descr'] = "Allow access to Telegraf package GUI";
$priv_list['page-services-telegraf']['match'] = array();
$priv_list['page-services-telegraf']['match'][] = "pkg_edit.php?xml=telegraf.xml*";
?>
3 changes: 3 additions & 0 deletions net-mgmt/telegraf/files/pkg-deinstall.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/usr/local/bin/php -f /etc/rc.packages %%PORTNAME%% ${2}
7 changes: 7 additions & 0 deletions net-mgmt/telegraf/files/pkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ "${2}" != "POST-INSTALL" ]; then
exit 0
fi

/usr/local/bin/php -f /etc/rc.packages %%PORTNAME%% ${2}
2 changes: 1 addition & 1 deletion net-mgmt/telegraf/files/telegraf.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# $FreeBSD$
# $FreeBSD: head/net-mgmt/telegraf/files/telegraf.in 460975 2018-02-05 15:05:36Z girgen $

# PROVIDE: telegraf
# REQUIRE: DAEMON NETWORKING
Expand Down
131 changes: 131 additions & 0 deletions net-mgmt/telegraf/files/usr/local/pkg/telegraf.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/*
* telegraf.inc
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require_once("functions.inc");
require_once("globals.inc");
require_once("pkg-utils.inc");
require_once("service-utils.inc");
require_once("util.inc");

function telegraf_resync_config() {
global $g, $config;

$telegraf_conf = array();
if (is_array($config['installedpackages']['telegraf'])) {
foreach ($config['installedpackages']['telegraf']['config'][0] as $k => $v) {
$telegraf_conf[$k] = addslashes($v);
}
}

conf_mount_rw();

/* disable telegraf if not enabled */
if ($telegraf_conf['enable'] != "on") {
if (is_service_running("telegraf")) {
stop_service("telegraf");
}
unlink_if_exists("/usr/local/etc/rc.d/telegraf.sh");
unlink_if_exists("/usr/local/etc/telegraf.conf");
return;
}

if (empty($telegraf_conf['interval'])) {
$telegraf_conf['interval'] = 10;
}

/* generate telegraf.conf */
$cfg = <<< EOD
# This file is automatically generated by pfSense #
[agent]
interval = "{$telegraf_conf['interval']}s"
round_interval = true

[[inputs.cpu]]
percpu = true
totalcpu = true
fielddrop = ["time_*"]

[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs"]

[[inputs.diskio]]

[[inputs.kernel]]

[[inputs.mem]]

[[inputs.net]]

[[inputs.processes]]

[[inputs.swap]]

[[inputs.system]]

[[inputs.pf]]

EOD;

if ((is_array($telegraf_conf['telegraf_output']) && in_array("influxdb", $telegraf_conf['telegraf_output'])) || $telegraf_conf['telegraf_output'] == "influxdb") {
$cfg .= "[[outputs.influxdb]]\n";
$cfg .= "\turls = [\"" . $telegraf_conf['influx_server'] . "\"]\n";
$cfg .= "\tdatabase = \"" . $telegraf_conf['influx_db'] . "\"\n";

if (!empty($telegraf_conf['influx_user'])) {
$cfg .= "\tusername = \"" . $telegraf_conf['influx_user'] . "\"\n";
}
if (!empty($telegraf_conf['influx_pass'])) {
$cfg .= "\tpassword = \"" . base64_decode($telegraf_conf['influx_pass']) . "\"\n";
}
} else if ((is_array($telegraf_conf['telegraf_output']) && in_array("elasticsearch", $telegraf_conf['telegraf_output'])) || $telegraf_conf['telegraf_output'] == "elasticsearch") {
$cfg .= "[[outputs.elasticsearch]]\n";
$cfg .= "\tenable_sniffer = false\n";
$cfg .= "\thealth_check_interval = \"10s\"\n";
$cfg .= "\tindex_name = \"telegraf-%Y.%m.%d\"\n";
$cfg .= "\tmanage_template = true\n";
$cfg .= "\toverwrite_template = false\n";
$cfg .= "\ttemplate_name = \"telegraf\"\n";
$cfg .= "\turls = [\"" . $telegraf_conf['elasticsearch_server'] . "\"]\n";
}
$conffile = "/usr/local/etc/telegraf.conf";
file_put_contents($conffile, $cfg);

/* generate telegraf.sh rcfile */
$pidfile = "{$g['varrun_path']}/telegraf.pid";
$logfile = "{$g['varlog_path']}/telegraf.log";
write_rcfile(array(
"file" => "telegraf.sh",
"start" => "/usr/sbin/daemon -crP {$pidfile} /usr/local/bin/telegraf -config={$conffile} 2> {$logfile}",
"stop" => "/bin/kill `/bin/cat {$pidfile}`"
)
);

/* (re)start service */
if (is_service_running("telegraf")) {
restart_service("telegraf");
} else {
start_service("telegraf");
}

sleep(1);
conf_mount_ro();
}
?>
102 changes: 102 additions & 0 deletions net-mgmt/telegraf/files/usr/local/pkg/telegraf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
<packagegui>
<copyright>
<![CDATA[
/*
* telegraf.xml
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
]]>
</copyright>
<name>telegraf</name>
<title>Services: Telegraf</title>
<include_file>/usr/local/pkg/telegraf.inc</include_file>
<menu>
<name>Telegraf</name>
<section>Services</section>
<configfile>telegraf.xml</configfile>
<url>/pkg_edit.php?xml=telegraf.xml</url>
</menu>
<service>
<name>telegraf</name>
<rcfile>telegraf.sh</rcfile>
<executable>telegraf</executable>
<description>Telegraf daemon</description>
</service>
<fields>
<field>
<fielddescr>Enable</fielddescr>
<fieldname>enable</fieldname>
<type>checkbox</type>
<description>Enable Telegraf.</description>
<enablefields>interval,telegraf_output,influx_server,influx_db,influx_user,influx_pass,elasticsearch_server</enablefields>
</field>
<field>
<fielddescr>Update Interval</fielddescr>
<fieldname>interval</fieldname>
<type>input</type>
<description>Seconds. Default: 10 if not specified</description>
</field>
<field>
<fielddescr>Telegraf Output</fielddescr>
<fieldname>telegraf_output</fieldname>
<type>select</type>
<options>
<option><name>InfluxDB</name><value>influxdb</value></option>
<option><name>ElasticSearch</name><value>elasticsearch</value></option>
</options>
<multiple/>
</field>
<field>
<fielddescr>*InfluxDB Server</fielddescr>
<fieldname>influx_server</fieldname>
<type>input</type>
<description>Full HTTP or UDP endpoint URL for InfluxDB instance. E.g.: http://192.168.1.23:8086 for a default InfluxDB instalaltion</description>
</field>
<field>
<fielddescr>*InfluxDB Database</fielddescr>
<fieldname>influx_db</fieldname>
<type>input</type>
<description>Target database for metrics (created if does not exist)</description>
</field>
<field>
<fielddescr>InfluxDB Username</fielddescr>
<fieldname>influx_user</fieldname>
<type>input</type>
<description>Database user name if required by InfluxDB config</description>
</field>
<field>
<fielddescr>InfluxDB Password</fielddescr>
<fieldname>influx_pass</fieldname>
<type>password</type>
<description>Database password if required by InfluxDB config</description>
<encoding>base64</encoding>
</field>
<field>
<fielddescr>*ElasticSearch Servers</fielddescr>
<fieldname>elasticsearch_server</fieldname>
<type>input</type>
<description>Full HTTP endpoint URL for ElasticSearch instance. E.g.: http://192.168.1.23:9200</description>
</field>
</fields>
<custom_php_resync_config_command>
telegraf_resync_config();
</custom_php_resync_config_command>
</packagegui>