3 Creating and updating counters

To collect data using a counter you must first create the counter from the probe's constructor using the create_counter method in AccountingDataCollection:

create_counter(counter_id, avgtype)

The first parameter is the name of the counter. The second parameter specifies the type of average to compute for the counter; Counters can store not just the value of the counter throughout time, but also a running average. There are three types of averages that can be specified through the avgtype

AccountingDataCollection.AVERAGE_NONE:
Don't compute an average
AccountingDataCollection.AVERAGE_NORMAL:
For each entry, compute the average of all the values including and preceding that entry.
AccountingDataCollection.AVERAGE_TIMEWEIGHTED:
For each entry, compute the average of all the values including and preceding that entry, weighing the average according to the time between each entry.

All counters are initialized to zero.

The counter can be updated using one of the following three methods:

incr_counter(counter_id, lease_id):
decr_counter(counter_id, lease_id):
append_to_counter(counter_id, value, lease_id):

All three methods receive the name of the counter (counter_id) and, optionally, the identifier of the lease that caused the update. incr_counter and decr_counter increment or decrement the counter, respectively, while append_to_counter changes the counter's value to the value specified by the value parameter.

Borja Sotomayor 2009-12-17