From 89a9e5554cbb884b9c0d30cee49beda3bc702a91 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Wed, 6 Nov 2019 08:58:08 -0800 Subject: [PATCH] sheetsync: Record counts of rows in the DB, segmented by various columns This lets us view a number of useful graphs in dashboards, eg. rows by state, errored rows, rows by day, rows by category, meltdowns per day, fraction of events that are poster moments by category. Sheetsync was the natural place to do this since it was already periodically scanning the entire events table. --- monitoring/dashboards/overview.jsonnet | 8 ++++++-- sheetsync/sheetsync/main.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/monitoring/dashboards/overview.jsonnet b/monitoring/dashboards/overview.jsonnet index 223a0ba..5f25f51 100644 --- a/monitoring/dashboards/overview.jsonnet +++ b/monitoring/dashboards/overview.jsonnet @@ -151,8 +151,12 @@ grafana.dashboard({ { name: "Database events by state", axis: {min: 0, label: "events"}, - tooltip: "Not implemented", // TODO - expressions: {"Not implemented": "0"}, + stack: true, + expressions: { + "{{state}}": ||| + sum(event_counts) by (state) + |||, + }, }, ], ], diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 725e626..0466ac1 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -3,6 +3,7 @@ import json import logging import signal import uuid +from collections import defaultdict import argh import gevent.backdoor @@ -41,6 +42,12 @@ rows_changed = prom.Counter( ['type', 'worksheet'], ) +event_counts = prom.Gauge( + 'event_counts', + 'Number of rows in the database', + ['sheet_name', 'category', 'poster_moment', 'state', 'errored'], +) + class SheetSync(object): # Time between syncs @@ -190,8 +197,12 @@ class SheetSync(object): """Return the entire events table as a map {id: event namedtuple}""" result = query(self.conn, "SELECT * FROM events") by_id = {} + counts = defaultdict(lambda: 0) for row in result.fetchall(): by_id[row.id] = row + counts[row.sheet_name, row.category, str(row.poster_moment), row.state, str(bool(row.error))] += 1 + for labels, count in counts.items(): + event_counts.labels(*labels).set(count) return by_id def parse_row(self, row):