Highlighted
Enthusiast
Enthusiast

Python integration

Jump to solution

I've seen on github that you have a library to integrate Wavefront with Go.

Is there any plan to get something similar for Python?

Thanks!

Martin

vasily@wavefront.com
Correct Answer by vasily@wavefront.com on Jan 26, 2017 2:28 PM

Hi Martin,

Are you using any particular metrics framework in Python, or simply looking for a way to send metrics from Python code? In the latter case it's actually very simple:

  1. import time 
  2. import socket 
  3.  
  4.  
  5. def send_metric(proxy_socket, metric_name, metric_value, source, timestamp=None, point_tags=None😞 
  6.         timestamp = timestamp or int(time.time()) 
  7.         tags = ' ' + ' '.join("%s=\"%s\"" % (k, v) for (k, v) in point_tags.iteritems()) if point_tags else '' 
  8.         proxy_socket.send("%s %d %d source=%s%s\n" % (metric_name, metric_value, timestamp, source, tags)) 
  9.  
  10. # example usage 
  11. s = socket.socket() 
  12. s.connect(("localhost", 2878)) 
  13. send_metric(s, "metric.name", 1, "metric.source"
  14. send_metric(s, "metric.name", 2, "metric.source", point_tags={"dc": "west1", "env": "prod"}) 
  15. s.close() 

If you are using an existing metrics framework, chances are that it can send data in Graphite or OpenTSDB format which are natively supported by our proxy - but if it's not the case, please let us know and we'll see what we can do!

-Vasily

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Enthusiast
Enthusiast

Hi Martin,

Are you using any particular metrics framework in Python, or simply looking for a way to send metrics from Python code? In the latter case it's actually very simple:

  1. import time 
  2. import socket 
  3.  
  4.  
  5. def send_metric(proxy_socket, metric_name, metric_value, source, timestamp=None, point_tags=None😞 
  6.         timestamp = timestamp or int(time.time()) 
  7.         tags = ' ' + ' '.join("%s=\"%s\"" % (k, v) for (k, v) in point_tags.iteritems()) if point_tags else '' 
  8.         proxy_socket.send("%s %d %d source=%s%s\n" % (metric_name, metric_value, timestamp, source, tags)) 
  9.  
  10. # example usage 
  11. s = socket.socket() 
  12. s.connect(("localhost", 2878)) 
  13. send_metric(s, "metric.name", 1, "metric.source"
  14. send_metric(s, "metric.name", 2, "metric.source", point_tags={"dc": "west1", "env": "prod"}) 
  15. s.close() 

If you are using an existing metrics framework, chances are that it can send data in Graphite or OpenTSDB format which are natively supported by our proxy - but if it's not the case, please let us know and we'll see what we can do!

-Vasily

1 of 1 people found this helpful

View solution in original post

0 Kudos
4 Replies
Highlighted
Enthusiast
Enthusiast

Hi Martin,

Are you using any particular metrics framework in Python, or simply looking for a way to send metrics from Python code? In the latter case it's actually very simple:

  1. import time 
  2. import socket 
  3.  
  4.  
  5. def send_metric(proxy_socket, metric_name, metric_value, source, timestamp=None, point_tags=None😞 
  6.         timestamp = timestamp or int(time.time()) 
  7.         tags = ' ' + ' '.join("%s=\"%s\"" % (k, v) for (k, v) in point_tags.iteritems()) if point_tags else '' 
  8.         proxy_socket.send("%s %d %d source=%s%s\n" % (metric_name, metric_value, timestamp, source, tags)) 
  9.  
  10. # example usage 
  11. s = socket.socket() 
  12. s.connect(("localhost", 2878)) 
  13. send_metric(s, "metric.name", 1, "metric.source"
  14. send_metric(s, "metric.name", 2, "metric.source", point_tags={"dc": "west1", "env": "prod"}) 
  15. s.close() 

If you are using an existing metrics framework, chances are that it can send data in Graphite or OpenTSDB format which are natively supported by our proxy - but if it's not the case, please let us know and we'll see what we can do!

-Vasily

1 of 1 people found this helpful

View solution in original post

0 Kudos
Highlighted
Enthusiast
Enthusiast

Thanks Vasily!

I wasn't sure about the format and if there was something special required to make it to WF forwarder.

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi Vasily,

  Is there any python library to which can push the metrics periodically to the proxy?

0 Kudos
Highlighted
VMware Employee
VMware Employee

Actually, its pretty simple. Check out how durren​ did it in the code, here: GitHub - BillRothVMware/wavefront-weather-py

thanks

0 Kudos