Port of the Scala Ostrich library
Python Shell
Switch branches/tags
hudson-python-ostrich-41 hudson-python-ostrich-40 hudson-python-ostrich-40-SUCCESS hudson-python-ostrich-39-FAILURE hudson-python-ostrich-38 hudson-python-ostrich-38-SUCCESS hudson-python-ostrich-37 hudson-python-ostrich-37-SUCCESS hudson-python-ostrich-36 hudson-python-ostrich-36-SUCCESS hudson-python-ostrich-35-FAILURE hudson-python-ostrich-33 hudson-python-ostrich-33-SUCCESS hudson-python-ostrich-32 hudson-python-ostrich-32-SUCCESS hudson-python-ostrich-31 hudson-python-ostrich-31-SUCCESS hudson-python-ostrich-30 hudson-python-ostrich-30-FAILURE hudson-python-ostrich-29 hudson-python-ostrich-29-SUCCESS hudson-python-ostrich-28 hudson-python-ostrich-28-SUCCESS hudson-python-ostrich-27 hudson-python-ostrich-27-SUCCESS hudson-python-ostrich-26 hudson-python-ostrich-26-SUCCESS hudson-ostrich-25 hudson-ostrich-24 hudson-ostrich-24-SUCCESS hudson-ostrich-23-FAILURE hudson-ostrich-22 hudson-ostrich-22-FAILURE hudson-ostrich-21 hudson-ostrich-21-SUCCESS hudson-ostrich-20 hudson-ostrich-20-SUCCESS hudson-ostrich-19-FAILURE hudson-ostrich-18-FAILURE hudson-ostrich-17-FAILURE hudson-ostrich-16-FAILURE hudson-ostrich-15 hudson-ostrich-15-SUCCESS hudson-ostrich-14 hudson-ostrich-14-FAILURE hudson-ostrich-13-FAILURE hudson-ostrich-12-FAILURE hudson-ostrich-11-FAILURE hudson-ostrich-10-FAILURE hudson-ostrich-9-FAILURE hudson-ostrich-8-FAILURE hudson-ostrich-7 hudson-ostrich-7-FAILURE hudson-ostrich-6-FAILURE hudson-ostrich-5-FAILURE hudson-ostrich-4-FAILURE debian/0.3.3-sg41 debian/0.3.2-sg40 debian/0.3.1-sg38 debian/0.3.1-sg37 debian/0.3.1-sg36 debian/0.3.1-sg33 debian/0.3.0-sg32 debian/0.2.7-sg31 debian/0.2.7-sg30 debian/0.2.7-sg29 debian/0.2.6-sg28 debian/0.2.5-sg27 debian/0.2.3-sg26 debian/0.2.3-sg25 debian/0.2.3-sg24 debian/0.2.3-sg22 debian/0.2.3-sg21 debian/0.2.3-sg20 debian/0.2.3-sg19 debian/0.2.3-sg18 debian/0.2.3-sg15 debian/0.2.3-sg14 debian/0.2.3-sg7 0.3.3 0.3.2 0.3.1 0.3.0 0.2.7 0.2.6 0.2.5 0.2.4 0.2.3 0.2.2 0.2.1 0.2 0.1
Nothing to show
Pull request Compare This branch is 2 commits ahead, 11 commits behind simplegeo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



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:

      # 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:
      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:
      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.