Add mass metric
This commit is contained in:
parent
49f5a03530
commit
4e8575cbe1
30
schlafana.py
30
schlafana.py
|
@ -5,7 +5,7 @@ import logging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from websocket import create_connection
|
from websocket import create_connection
|
||||||
from prometheus_client import Counter, Gauge, Summary, start_http_server
|
from prometheus_client import Counter, Gauge, Summary, start_http_server
|
||||||
from prometheus_client.core import CounterMetricFamily, REGISTRY
|
from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily, REGISTRY
|
||||||
import time
|
import time
|
||||||
|
|
||||||
MESSAGES = { "GameInfo" : 0x00,
|
MESSAGES = { "GameInfo" : 0x00,
|
||||||
|
@ -44,6 +44,16 @@ class BotRevisionCountCollector(object):
|
||||||
yield c
|
yield c
|
||||||
|
|
||||||
|
|
||||||
|
class BotMassGaugeCollector(object):
|
||||||
|
def collect(self):
|
||||||
|
c = GaugeMetricFamily("mass", "Mass of each snake", 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.mass)
|
||||||
|
yield c
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global game
|
global game
|
||||||
game = Game()
|
game = Game()
|
||||||
|
@ -61,6 +71,7 @@ def main():
|
||||||
REGISTRY.register(BotDeathCollector())
|
REGISTRY.register(BotDeathCollector())
|
||||||
REGISTRY.register(BotKillCollector())
|
REGISTRY.register(BotKillCollector())
|
||||||
REGISTRY.register(BotRevisionCountCollector())
|
REGISTRY.register(BotRevisionCountCollector())
|
||||||
|
REGISTRY.register(BotMassGaugeCollector())
|
||||||
start_http_server(9000)
|
start_http_server(9000)
|
||||||
logger.info("Start prometheus scrape endpoint")
|
logger.info("Start prometheus scrape endpoint")
|
||||||
|
|
||||||
|
@ -177,14 +188,7 @@ class BotUser():
|
||||||
|
|
||||||
def update(self, data):
|
def update(self, data):
|
||||||
rev_id = data.get("db_id")
|
rev_id = data.get("db_id")
|
||||||
worm_id = data.get("id") #TODO: does this work?
|
worm_id = data.get("id")
|
||||||
if "data" in data.keys():
|
|
||||||
user = game.users.get_user_by_worm(worm_id)
|
|
||||||
current_rev = user.revs.get(user.current_rev)
|
|
||||||
current_rev.carrion_food_consumed = data.get("data").get("c")
|
|
||||||
current_rev.natural_food_consumed = data.get("data").get("n")
|
|
||||||
current_rev.hunted_food_consumed = data.get("data").get("h")
|
|
||||||
pdb.set_trace()
|
|
||||||
if rev_id in self.revs.keys(): # revision already known
|
if rev_id in self.revs.keys(): # revision already known
|
||||||
rev = self.revs.get(rev_id)
|
rev = self.revs.get(rev_id)
|
||||||
rev.update(data)
|
rev.update(data)
|
||||||
|
@ -212,8 +216,12 @@ class BotRevision():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update(self, data):
|
def update(self, data):
|
||||||
if "food" in data.keys():
|
if "data" in data.keys():
|
||||||
pdb.set_trace()
|
self.mass = data.get("data").get("m")
|
||||||
|
self.carrion_food_consumed = data.get("data").get("c")
|
||||||
|
self.natural_food_consumed = data.get("data").get("n")
|
||||||
|
self.hunted_food_consumed = data.get("data").get("h")
|
||||||
|
else:
|
||||||
self.current_worm = data.get("id")
|
self.current_worm = data.get("id")
|
||||||
self.rev_id = data.get("db_id")
|
self.rev_id = data.get("db_id")
|
||||||
self.mass = data.get("mass")
|
self.mass = data.get("mass")
|
||||||
|
|
Loading…
Reference in a new issue