To collect per-lease data, you first have to specify the new type of data (or ``stat'') you will be collecting in your probe's constructor. This is done using the
create_lease_stat method in AccountingDataCollection (which is stored in an accounting attribute in all probes). For example, let's assume you want to keep track of an admittedly silly statistic: whether the lease's identifier is odd or even. You could create a stat called Odd or even?:
from haizea.core.accounting import AccountingProbe class MyProbe(AccountingProbe): def __init__(self, accounting): AccountingProbe.__init__(self, accounting) self.accounting.create_lease_stat("Odd or even?")
To set the value of this stat, you must use the
set_lease_stat method in AccountingDataCollection. For this stat, it would make sense to call this method from the at_lease_request method in the probe:
def at_lease_request(self, lease): if lease.id \% 2 == 1: value = "odd" else: value = "even" self.accounting.set_lease_stat("Odd or even?", lease.id, value)
If you run Haizea with this probe, and then use haizea-convert-data to print the per-lease data collected by the probes, there will be an additional column titled Odd or even? in the generated CSV file.
Borja Sotomayor 2009-12-17