4 Replies Latest reply on Dec 12, 2017 4:58 AM by shivkumar4

    Python integration

    Enthusiast

      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

        • 1. Re: Python integration
          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

          • 2. Re: Python integration
            Enthusiast

            Thanks Vasily!

             

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

            • 3. Re: Python integration
              Enthusiast

              Hi Vasily,

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

              • 4. Re: Python integration
                shivkumar4 Lurker

                The scipy.integrate sub-package provides several integration techniques including an ordinary differential equation integrator. An overview of the module is provided by the help command- that help to solve the problem:

                help(integrate)

                Methods for Integrating Functions given function object.

                 

                 

                   quad          -- General purpose integration.

                   dblquad       -- General purpose double integration.

                   tplquad       -- General purpose triple integration.

                   fixed_quad    -- Integrate func(x) using Gaussian quadrature of order n.

                   quadrature    -- Integrate with given tolerance using Gaussian quadrature.

                   romberg       -- Integrate func using Romberg integration.

                 

                 

                Methods for Integrating Functions given fixed samples.

                 

                 

                   trapz         -- Use trapezoidal rule to compute integral from samples.

                   cumtrapz      -- Use trapezoidal rule to cumulatively compute integral.

                   simps         -- Use Simpson's rule to compute integral from samples.

                   romb          -- Use Romberg Integration to compute integral from

                                    (2**k + 1) evenly-spaced samples.