Tanzu Observability

 View Only
  • 1.  Python integration

    Posted Jul 27, 2017 08:57 PM

    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



  • 2.  RE: Python integration
    Best Answer

    Posted Jul 27, 2017 08:57 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

    1 of 1 people found this helpful



  • 3.  RE: Python integration

    Posted Jul 27, 2017 08:58 PM

    Thanks Vasily!

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



  • 4.  RE: Python integration

    Posted Feb 07, 2018 02:00 AM

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

    thanks



  • 5.  RE: Python integration

    Posted Jul 27, 2017 08:58 PM

    Hi Vasily,

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