Commit 0627f256 authored by sqozz's avatar sqozz
Browse files

Add more stats

parent 95b564a6
......@@ -4,7 +4,7 @@ import json
import logging
from pprint import pprint
from websocket import create_connection
from prometheus_client import Counter, Summary, start_http_server
from prometheus_client import Counter, Gauge, Summary, start_http_server
from prometheus_client.core import CounterMetricFamily, REGISTRY
import time
......@@ -19,19 +19,19 @@ MESSAGES = { "GameInfo" : 0x00,
class BotDeathCollector(object):
def collect(self):
c = CounterMetricFamily("deaths", "Deaths of each player", labels=["name", "bot_rev"])
c = CounterMetricFamily("deaths", "Deaths of each player", labels=["name", "rev"])
for user in game.users.users:
user = game.users.users.get(user)
c.add_metric([user.name, user.current_rev], user.deaths)
c.add_metric([user.name, str(user.current_rev)], user.deaths)
yield c
class BotKillCollector(object):
def collect(self):
c = CounterMetricFamily("kills", "Kills of each player", labels=["name", "bot_rev"])
c = CounterMetricFamily("kills", "Kills of each player", labels=["name", "rev"])
for user in game.users.users:
user = game.users.users.get(user)
c.add_metric([user.name, user.current_rev], user.kills)
c.add_metric([user.name, str(user.current_rev)], user.kills)
yield c
......@@ -102,9 +102,8 @@ class Game():
user = self.users.get_user(bot.get("db_id"))
#print("{}({}): respawn".format(user.name, user.db_id))
elif typ == MESSAGES["GameInfo"]:
pdb.set_trace()
game.x = 0
game.y = 0
game.x = js.get("world_size_c")
game.y = js.get("world_size_y")
elif typ == MESSAGES["BotKill"]:
try:
victim = self.users.get_user_by_rev(js.get("victim_id"))
......@@ -124,8 +123,6 @@ class Game():
msg_data = js.get("data")
for rev in msg_data:
user = self.users.get_user_by_rev(rev)
print(user)
pdb.set_trace()
pass
elif typ == MESSAGES["WorldUpdate"]:
bots = js.get("bots")
......@@ -163,8 +160,6 @@ class BotUser():
@deaths.setter
def deaths(self, deaths):
self.__deaths = deaths
if self.__deaths % 2 == 0:
print("{} was already killed {} times".format(self.name, self.__deaths))
self.revs.get(self.current_rev).deaths += 1
def parse(self, data):
......@@ -184,7 +179,8 @@ class BotUser():
if self.current_rev != data.get("id"):
self.current_rev = data.get("id")
else:
print("{} new code-version".format(self.name))
#print("{} new code-version".format(self.name))
pass
self.revs.update({ self.current_rev : BotRevision(data) })
......@@ -205,8 +201,10 @@ class BotRevision():
class UserList():
def __init__(self):
self.users = {}
self.__usercount = Gauge('Users', 'Total count of active players')
def update_by_db(self, db_id, data):
self.__usercount.set(len(self.users))
if data.get("db_id") in self.users.keys():
self.users.get(data.get("db_id")).update(data)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment