Skip to content
Easy python bindings to write to Carbon ( Re-write of carbonclient)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin added script to allow for running software via cli Mar 28, 2013
debian export everything from graphitesend.graphitesend to graphitesend, so … Nov 26, 2015
docs @vikram-narayan spotted some typo Nov 26, 2015
examples No harm getting closer to py3 Dec 7, 2014
graphitesend
tests Remove test that broke for no reason Sep 8, 2018
.env added .env for virtualenv Mar 26, 2013
.gitignore added emacs tmp files to ignore list Nov 13, 2013
.travis.yml Set gevent to 1.1.0 for Python 2.6 Jan 6, 2017
CHANGELOG release 0.10.0 Mar 25, 2017
HOW_TO_RELEASE.md release 0.10.0 Mar 25, 2017
LICENSE.txt Fix license year Sep 8, 2018
README
README.md Add message stating that the project is no longer maintained Sep 8, 2018
requirements-asynchronous.txt Tweak how requirements are installed Dec 23, 2015
requirements-test.txt lock flake8 - due to python2.6 support (#68) Oct 31, 2016
requirements.txt Added python2.6 support Mar 23, 2016
setup.py release 0.10.0 Mar 25, 2017
tox.ini Merge branch 'factor_formatter' of https://github.com/zillow/graphite… Nov 3, 2016

README.md

graphitesend

Build Status Changelog Coverage Status

Easy python bindings to write to Carbon ( Re-write of carbonclient).

Warning

This project is no longer maintained. Lacking rights to publish new versions, a collaborator has forked the project and maintain it there: graphitesender

Read The Docs

graphitesend.rtfd.org

Blog posts

dansysadm.com

Example Scripts

The github repo of graphitesend-examples has lots of examples using graphitesend to grab data from your local linux system.

Installing

pip

$ pip install graphitesend

easy_install

$ easy_install graphitesend

or

source

$ git clone git://github.com/daniellawrence/graphitesend.git
$ cd graphitesend
$ python ./setup.py install

Usage Example

Very basic sending of a metric called metric with a value of 45

>>> import graphitesend
>>> graphitesend.init()
>>> graphitesend.send('metric', 45)
>>> graphitesend.send('metric2', 55)

The above would send the following metric to graphite

system.localhostname.metric 45 epoch-time-stamp
system.localhostname.metric2 55 epoch-time-stamp

Cleaning up the interface and using a group of cpu to alter the metric prefix

>>> import graphitesend
>>> g = graphitesend.init(group='cpu')
>>> g.send('metric', 45)
>>> g.send('metric2', 55)

The above would send the following metric to graphite

system.localhostname.cpu.metric 45 epoch-time-stamp
system.localhostname.cpu.metric2 55 epoch-time-stamp

Using a different prefix (other then system.hostname)

>>> import graphitesend
>>> g = graphitesend.init(prefix='apache.rc')
>>> g.send('404', 4)
>>> g.send('200', 500)

The above would send the following metric to graphite

apache.rc.localhostname.404 4 epoch-time-stamp
apache.rc.localhostname.200 500 epoch-time-stamp

To get rid of localhostname, set another argument — system_name

>>> import graphitesend
>>> g = graphitesend.init(prefix='apache.rc', system_name='')
>>> g.send('404', 4)
>>> g.send('200', 500)

The above would send the following metric to graphite

apache.rc.404 4 epoch-time-stamp
apache.rc.200 500 epoch-time-stamp

Sending a dict()

    >>> import graphitesend
    >>> g = graphitesend.init()
    >>> g.send_dict({'metric': 45, 'metric2': 55})

Sending a list()

    >>> import graphitesend
    >>> g = graphitesend.init()
    >>> g.send_list([('metric', 45), ('metric2', 55)])

Sending a list(), with a custom timestamp for all metric-value pairs

    >>> import graphitesend
    >>> g = graphitesend.init()
    >>> g.send_list([('metric', 45), ('metric2', 55)], timestamp=12345)

Sending a list(), with a custom timestamp for each metric-value pairs

    >>> import graphitesend
    >>> g = graphitesend.init()
    >>> g.send_list([('metric', 45, 1234), ('metric2', 55, 1234)])

Learning? Use dryrun.

With dryrun enabled the data will never get sent to a remote service, it will just print out what would have been sent.

    >>> import graphitesend
    >>> g = graphitesend.init(dryrun=True)
    >>> g.send_list([('metric', 45, 1234), ('metric2', 55, 1234)])

Example: the init()

Set a metric prefix (Default arg)

>>> g = graphitesend.init('prefix')
>>> print g.send('metric', 1)
sent 34 long message: prefix.metric 1.000000 1365068929

set a metric prefix using kwargs

>>> g = graphitesend.init(prefix='prefix')
>>> print g.send('metric', 2)
sent 34 long message: prefix.metric 2.000000 1365068929

Squash any dots in the hostname

>>> g = graphitesend.init(fqdn_squash=True)
>>> print g.send('metric', 3)
sent 56 long message: systems.host_example_com.metric 2.00000 1365069029

view the default prefix, hardset systems. then followed by the name of the host that execute the send().

>>> g = graphitesend.init()
>>> print g.send('metric', 3)
sent 44 long message: systems.<system_name>.metric 3.000000 1365069029

Set a suffix, handy if you have a bunch of timers or percentages

>>> g = graphitesend.init(suffix='_ms')
>>> print g.send('metric', 4)
sent 47 long message: systems.<system_name>.metric_ms 4.000000 1365069100

set a system_name if your submitting results for a different system

>>> g = graphitesend.init(system_name='othersystem')
>>> print g.send('metric', 5)
sent 47 long message: systems.othersystem.metric 5.000000 1365069100

Lowercase all the metric names that are send to the graphite server.

>>> g = graphitesend.init(lowercase_metric_names=True)
>>> print g.send('METRIC', 6)
sent 47 long message: systems.<hostname>.metric 6.000000 1365069100

Set a group name, handy if you just parsed iostat and want to prefix all the metrics with iostat, after its already in the <system_name> directory.

>>> g = graphitesend.init(group='groupname')
>>> print g.send('metric', 6)
sent 54 long message: systems.<system_name>.groupname.metric 6.000000 136506924

Connect to a different graphite server

>>> graphitesend.init(graphite_server='graphite.example.com')

Connect to a different graphite server port

>>> graphitesend.init(graphite_port=2003)

Send async messages

>>> graphitesend.init(asynchronous=True)

Change connect timeout (default 2)

>>> graphitesend.init(timeout_in_seconds=5)

CLI

Just added -- A cli script that allows for anything to send metrics over to graphite (not just python).

The usage is very simple you need to give the command a metric and a value.

	$ graphitesend name.of.the.metric 666

Send more* then 1 metric and value

	$ graphitesend name.of.the.metric 666
	$ graphitesend name.of.the.other_metric 2

* Call it 2 times ;)

Porcelain Overview

init

Create the module instance of GraphiteSend.

send

Make sure that we have an instance of the GraphiteClient. Then send the metrics to the graphite server.

send_dict

Make sure that we have an instance of the GraphiteClient. Then send the metrics to the graphite server.

reset

Disconnect from the graphite server and destroy the module instance.

TCP vs UDP

There is a new branch for UDP support called 'udp and tcp'. TCP will continue to be the default with UDP as an option

You can’t perform that action at this time.