Coder Social home page Coder Social logo

python-ostrich's Introduction

python-ostrich

This is a port of the Scala Ostrich library. This port is currently a work in progress, so only the stuff covered in the unit tests are considered to be completed.

Stats API

There are three kinds of statistics that ostrich captures:

  • counters

    A counter is a value that never decreases. Examples might be "widgets_sold" or "births". You just click the counter each time a countable event happens, and graphing utilities usually graph the deltas over time. To increment a counter, use:

      stats.incr("births")
      
      # or
    
      stats.incr("widgets_sold", 5)
    
  • gauges

    A gauge is a value that has a discrete value at any given moment, like "heap_used" or "current_temperature". It's usually a measurement that you only need to take when someone asks. To define a gauge, stick this code somewhere in the server initialization:

      stats.make_gauge("current_temperature", lambda: my_thermometer.get_temperature_in_celcius())
    
      # you can also create a gauge by decorating a method:
    
      @stats.gauge("current_temperature")
      def current_temperature():
          return my_thermometer.get_temperature_in_celcius()
    

    Gauge methods should always return a number (either an integer or a float)

  • timings

    A timing is a stopwatch timer around code, like so:

      with stats.time("translation"):
          document.translate("de", "en")
    
      # you can also time something by decorating the method:
    
      @stats.time("translation")
      def translation():
          document.translate("de", "en")
    

    Timings are collected in aggregate, and the aggregation is reported through the "stats" command. The aggregation includes the count (number of timings performed), sum, maximum, minimum, average, standard deviation, and sum of squares (useful for aggregating the standard deviation).

Dump stats as JSON

There is a stats.json_encoder function provided to make dumping that stats to JSON easy.

json.dumps(stats.stats(reset=False), default=stats.json_encoder)

Twisted Web Resource

If you are using Twisted Web, there is a ready to use Resource available:

from ostrich.twisted import StatsResource

This resource will respond to the query string parameter reset=(0|1). If not specified, the default is reset=0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.