Skip to content

Python module for sending metrics to Graphite over UDP

Notifications You must be signed in to change notification settings

pkmurph/python-graphiteudp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-graphiteudp

Python module for sending metrics to Graphite over UDP.

Features

  • Simple module-level interface, can be configured by one module and that configuration will be reused across an application importing it
  • Uses python-socketcache to minimise DNS lookups and creating new socket objects for minimum performance impact on the application
  • Supports a debug mode where metric messages are logged and not sent
  • Logs messages for network errors instead of blowing up

Example

import graphiteudp

# By default, sends metrics to localhost:2003 with no prefix.
graphiteudp.init()
graphiteudp.send("foo", 1)

# Send to a specific host, add a prefix, and log messages instead of sending them.
graphiteudp.init("graphite.example.com", prefix = "myapp", debug = True)
# Generates log message: DEBUG 'myapp.bar.monkey 123.000000 1354307985\n' -> ('graphite.example.com', 2003)
graphiteudp.send("bar.monkey", 123)

For multiple modules in the same application, graphiteudp.init() only needs to be called once.

foo.py
import graphiteudp
graphiteudp.init(...)
import bar
bar.py
import graphiteudp
graphiteudp.send("bar.things", 1)

Multiple client objects can be maintained if you need to.

import graphiteudp

g = graphiteudp.GraphiteUDPClient(...)
g.send("foo", 1)

BUGS

Unknown.

TODO

  • Should use the adns module for non-blocking DNS where available.
  • Should probably not depend on python-socketcache, but should use it where available.
  • Add a simple Timer class supporting with syntax (__enter__ and __exit__)
  • Tests

Contributing

Contributions welcome!

About

Python module for sending metrics to Graphite over UDP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%