Add food metric

This commit is contained in:
sqozz 2018-05-11 23:08:18 +02:00
parent d9308e8753
commit 5e02c4d320

View file

@ -55,6 +55,36 @@ class BotMassGaugeCollector(object):
yield c yield c
class BotFoodCarrionCollector(object):
def collect(self):
c = CounterMetricFamily("carrion_food", "Carrion food consumed", labels=["name", "snake_id", "code_id"])
for user in game.users.users:
user = game.users.users.get(user)
rev = user.revs.get(user.current_rev)
c.add_metric([user.name, str(user.current_worm), str(user.current_rev)], rev.carrion_food_consumed)
yield c
class BotFoodNaturalCollector(object):
def collect(self):
c = CounterMetricFamily("natural_food", "Natural food consumed", labels=["name", "snake_id", "code_id"])
for user in game.users.users:
user = game.users.users.get(user)
rev = user.revs.get(user.current_rev)
c.add_metric([user.name, str(user.current_worm), str(user.current_rev)], rev.natural_food_consumed)
yield c
class BotFoodHuntedCollector(object):
def collect(self):
c = CounterMetricFamily("hunted_food", "Hunted food consumed", labels=["name", "snake_id", "code_id"])
for user in game.users.users:
user = game.users.users.get(user)
rev = user.revs.get(user.current_rev)
c.add_metric([user.name, str(user.current_worm), str(user.current_rev)], rev.hunted_food_consumed)
yield c
def main(): def main():
global game global game
game = Game() game = Game()
@ -73,6 +103,9 @@ def main():
REGISTRY.register(BotKillCollector()) REGISTRY.register(BotKillCollector())
REGISTRY.register(BotRevisionCountCollector()) REGISTRY.register(BotRevisionCountCollector())
REGISTRY.register(BotMassGaugeCollector()) REGISTRY.register(BotMassGaugeCollector())
REGISTRY.register(BotFoodCarrionCollector())
REGISTRY.register(BotFoodNaturalCollector())
REGISTRY.register(BotFoodHuntedCollector())
start_http_server(9000) start_http_server(9000)
logger.info("Start prometheus scrape endpoint") logger.info("Start prometheus scrape endpoint")