def collect(self): """Collect any new statistics available since the last time :meth:`collect` was executed.""" connection = DjangoBrokerConnection() consumer = StatsConsumer(connection=connection) it = consumer.iterqueue(infinite=False) for message in it: stats_entry = message.decode() stat_type = stats_entry["type"] if stat_type in self.allowed_types: # Decode keys to unicode for use as kwargs. data = dict((key.encode("utf-8"), value) for key, value in stats_entry["data"].items()) handler = getattr(self, stat_type) handler(**data)