Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Last active July 24, 2017 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leandromoreira/9536537 to your computer and use it in GitHub Desktop.
Save leandromoreira/9536537 to your computer and use it in GitHub Desktop.
Post event on graphite using python as a client
# more about graphite events at http://obfuscurity.com/2014/01/Graphite-Tip-A-Better-Way-to-Store-Events
import json
import requests
def create_graphite_event(event_description, tags):
required_data = "Graphite needs SSD!" # I tried withouth data attribute and it didn't work
tags_string = " ".join(str(x) for x in tags) # Since you will pass an array but graphite expects multi tags like "a,b,c" or "a b c"
event = {"what": event_description, "tags": tags_string, "data": required_data}
try:
requests.post("http://localhost/events/", data=json.dumps(event), timeout=1)
except Exception as e:
print 'Error while creating graphite event:', e
#usage
create_graphite_event("deploy", ["v0.1.2", "angular_introduced", "profile_microservice"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment