Skip to content

Added HTTP protocol #6

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e36c621
Now supports HTTP protocol. Renamed TCP protocol to TELNET. Documents…
Nov 13, 2014
8830721
The metric is now built using Python variables. Removed HostPostfix a…
Nov 17, 2014
3f57dc1
Removed properties that no longer exist from the kairosdb.conf. Fixed…
Nov 17, 2014
f359d2c
Fixed bug where the metric name was being appended to.
Dec 2, 2014
6f85bc3
Added a formatter. A formatter is python code used to modify the metr…
Dec 8, 2014
fbaf118
Removed comment.
Dec 8, 2014
2f69f19
Added CPU formatter and changed tags to be a dictionary
Feb 4, 2015
0b421d3
added formatter for disk and interface
brianhks Feb 13, 2015
9146de3
fixed typo
brianhks Feb 13, 2015
cbaa2f5
Consolidated locking and updated foratter for disk and interface.
Feb 17, 2015
3b341c5
Updated writer to accept a URI instead of separate host, port and pro…
brianhks Feb 24, 2015
787e9a6
Added code to handle trailing / in uri
brianhks Feb 24, 2015
7c3e56b
Added default ports
brianhks Feb 25, 2015
be958e9
Fixed telnet protocol typo
brianhks Feb 26, 2015
7c8d0cf
Changed host separator default to . as we are putting it in a tag
brianhks Mar 4, 2015
c16de04
fixed https not sending data
brianhks Jun 12, 2015
fe892f0
Added ConvertToRate property. This converts DERIVE and COUNTER values…
Sep 23, 2015
21a7b84
Removed local test path
Sep 23, 2015
4e327ed
Fixed typo. Commented out debug logging statements. Added types.db to…
Sep 23, 2015
53dcd77
Fixed 2 bugs and added a check for divide by zero. The first bug was…
Sep 24, 2015
fc29ff7
Added gitignore file.
Sep 24, 2015
2cfe031
No longer check plugin name using regular expression. This is too eas…
Sep 24, 2015
8b2b320
Now supports plugin formatters. The default formatter is used if plug…
Jan 13, 2016
0b71b72
kairosdb_writer.py is now a class. This makes it easier to test and …
Jan 14, 2016
751e9e3
Fix bug where the connection was not closed for http ImproperConnecti…
Jun 17, 2016
c311d14
No longer send empty data to Kairos. Reset the connection to Kairos i…
Oct 25, 2016
568f6cd
Changed default telnet port to match with the Kairos default.
Oct 25, 2016
188f821
Incremented version number.
Oct 25, 2016
f9bc2b7
Added verbose mode and the discarding of metrics if not all metrics a…
May 11, 2018
8f483c0
Increased the version number.
May 11, 2018
e66d507
Merged master and added connection reset if response is not 204
brianhks Jan 9, 2019
513e87c
Removed double lock and changed error handling order
brianhks Jan 9, 2019
c533131
update version to 1.3
brianhks Jan 9, 2019
f09da2b
Added code to remove nan from being reported
brianhks Feb 26, 2019
7c9df49
add http timeout
Mar 4, 2020
1b83024
Merge pull request #4 from sigsegv0x0b/master
jsabin Mar 4, 2020
b6d7191
Updated script for Python3.
brianhks Mar 11, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
.idea/
66 changes: 63 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,72 @@ Add the following to your collectd config **or** use the included kairosdb.conf.
Import "kairosdb_writer"

<Module "kairosdb_writer">
KairosDBHost "localhost"
KairosDBPort 4242
KairosDBProtocol "tcp"
KairosDBURI "telnet://localhost:4242"
LowercaseMetricNames true
TypesDB "/usr/share/collectd/types.db" "/etc/collectd/types/custom.db"
ConvertToRate "interface", "cpu"
</Module>
</Plugin>


### Properties
*AddHostTag* - adds a host tag if true. True by default.

*Formatter* - the full path to a formatter. See the Formatters section below.

*PluginFormatterPath* - the path to the directory where plugin formatters exist. Optional. See the Formatters section below.

*HostSeparator* - separator character used between host name parts. Defaults to underscore("_").

*LowercaseMetricNames* - lower cases the metric name if true. Defaults to false.

*KairosDBURI* - URI for the Kairos host, must be in the form <protocol>://<host>[:<port>]. Protocol may be one of (telnet, http, https). Required.

*TypesDB* - Data-set specifications. See [Types.db](https://collectd.org/documentation/manpages/types.db.5.shtml).

*MetricName* - the name of the metric. This is built using pre-defined variables. See [Naming Schema](https://collectd.org/wiki/index.php/Naming_schema) for information about these variables.
For example, if the metric name is set to "collectd.%(plugin)s.%(plugin_instance)s.%(type)s.otherstuff", this will produce a metric name that looks like this
"collectd.processes.ps_state.blocked.value.otherstuff". The pre-defined variables are *host*, *plugin*, *plugin_instance*, *type*, and *type_instance*. The default is "collectd.%(plugin)s.%(plugin_instance)s.%(type)s.%(type_instance)s".

*MetricSeparator* - separator character used between metric name parts. Defaults to a period(".").

*ConvertToRate* - converts COUNTER and DERIVE values to rates for the listed plugins. This is a comma delimited list of plugin names. The counter values are suppressed and a new metric containing the rate is sent to KairosDB. The name for rates will contain "_rate" on the end of the name.

*Tags* - KairosDB tags to send. At least one tag is required. The host name is added as a tag by default unless AddHostTag is set to false. For example, "customer=acme"

*ThrowawaySampleAge* - Discards metrics if they have not been sent to Kairos in a certain period of time. The time specified is in seconds. Some plugins collect such a large number of metrics that the pushing of metrics may take so much time that not all metrics are sent to Kairos before the next reporting cycle. This option will discard any metrics that are not sent after the specified period of time.

*VerboseLogging* - Add additional logging information.


### Formatters
Formatters provide a way to customize the metric name or tags. A formatter is a python script that has a format function. See the ./examples/defaultFormatter.py for an example of a default formatter.
See the ./examples/cpuFormatter.py for an example of a plugin formatter.
There are two ways to create formatters.

1. Default Formatter - The "Formatter" property let's you specify the location of a single formatter that will be called for all plugins.
2. Plugin Formatters - Formatters that applies to a specific list of plugins can be created. These formatters are loaded from the "formatters" subdirectory where kairosdb_writer.py exists.

Formatters are used in the following way.

When the writer is first loaded the default formatter and the plugin formatters are loaded. If the "Formatter" property exists, the default formatter is loaded from the specified location.
All plugin formatter files that have a .py extension found in the "formatters" directory are loaded.

When the writer is called with values for a plugin then

1. If a plugin formatter exists for the plugin, its format function is called and the default formatter is not called.
2. If no plugin formatter is found and the default formatter exists then its format function is called.

#### Formatter Functions
Both the default formatter and specific plugin formatters must have a format function with the following signature. It returns the metric name and a dictionary of tags (tag name/value).

format(metric_name_template, tags, hostname, plugin, plugin_instance, type, type_instance)

Plugin formatters must also include a plugins function which is called when the writer is loaded. This returns a list of plugin names that this formatter applies to.

plugins()





14 changes: 14 additions & 0 deletions examples/cassandraFormatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Adds column family names as tags and removes them from the metric name.
# This was written for use with the FastJMX Collectd plugin that reads JMX metrics from Cassandra.
# NOTE: The code looks for "column_family" as the plugin name and replaces it with "cassandra". In the FastJMX configuration a value can have a "PluginName" property
# which is set to "cassandra" for all metrics except those that have metrics for all column families. These I set to "column_family" as a way to easily
# identify metrics that this plugin will modify.
# class Formatter:

# For column families, remove plugin_instance from name and change plugin name to "cassandra" and add column_families as a tag
def format_metric(metric_name_template, tags, hostname, plugin, plugin_instance, type, type_instance):
if plugin == 'column_family':
metric_name_template = metric_name_template.replace('%(plugin_instance)s.', '')
tags['column_family'] = plugin_instance
plugin = 'cassandra'
return metric_name_template % {'host': hostname, 'plugin': plugin, 'plugin_instance': plugin_instance, 'type': type, 'type_instance': type_instance}, tags
15 changes: 15 additions & 0 deletions examples/cpuFormatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sample formatter for the cpu plugin.
# cpu number and type are set as tags

def plugins():
return ["cpu"]


def format_metric(metric_name_template, tags, hostname, plugin, plugin_instance, type, type_instance):
metric_name_template = metric_name_template.replace('%(plugin_instance)s.', '')
metric_name_template = metric_name_template.replace('%(type)s.', '')
tags['cpu'] = plugin_instance
tags['type'] = type_instance
type_instance = 'utilization'

return metric_name_template % {'host': hostname, 'plugin': plugin, 'plugin_instance': plugin_instance, 'type': type, 'type_instance': type_instance}, tags
13 changes: 13 additions & 0 deletions examples/defaultFormatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample default formatter
# Disk and interface (network) plugin metrics names are set along with tags

def format_metric(metric_name_template, tags, hostname, plugin, plugin_instance, type, type_instance):
if plugin == 'disk':
metric_name_template = metric_name_template.replace('%(plugin_instance)s.', '')
tags['disk'] = plugin_instance

if plugin == 'interface':
metric_name_template = metric_name_template.replace('%(type_instance)s', '')
tags['interface'] = type_instance

return metric_name_template % {'host': hostname, 'plugin': plugin, 'plugin_instance': plugin_instance, 'type': type, 'type_instance': type_instance}, tags
20 changes: 11 additions & 9 deletions kairosdb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
</LoadPlugin>

<Plugin "python">
ModulePath "/usr/lib64/collectd/"
ModulePath "/usr/lib64/collectd/"

Import "kairosdb_writer"

<Module "kairosdb_writer">
#HostPostfix "myhost"
KairosDBURI "telnet://localhost:4242"
#KairosDBURI "http://localhost:8080"
#KairosDBURI "https://localhost:443"
LowercaseMetricNames true
TypesDB "/usr/share/collectd/types.db" #"/etc/collectd/types/custom.db"
#Formatter "/opt/proofpoint/.../Formatter.py"
#AddHostTag false
#HostSeparator "_"
KairosDBHost "localhost"
KairosDBPort 4242
KairosDBProtocol "tcp"
#MetricPrefix "collectd"
#MetricName "collectd.%(plugin)s.%(plugin_instance)s.%(type)s.%(type_instance)s"
#MetricSeparator "."
LowercaseMetricNames true
Tags "host=web01.company.local" "role=web01"
TypesDB "/usr/share/collectd/types.db" "/etc/collectd/types/custom.db"
#Tags "role=web01"
ConvertToRate "interface", "cpu"
</Module>
</Plugin>
Loading