diff options
author | 2020-09-27 16:01:06 -0700 | |
---|---|---|
committer | 2020-09-27 20:04:48 -0700 | |
commit | c394a61a4e1fe395191262ed1ccaf70b90a71484 (patch) | |
tree | ca3080c4eeb29f3a01d47676be9521334e0696cd /storage/entry.go | |
parent | 16b7b3bc3e4237abbacdf8695a685ca9a03dc5bb (diff) | |
download | v2-c394a61a4e1fe395191262ed1ccaf70b90a71484.tar.gz v2-c394a61a4e1fe395191262ed1ccaf70b90a71484.tar.zst v2-c394a61a4e1fe395191262ed1ccaf70b90a71484.zip |
Add Prometheus exporter
Diffstat (limited to 'storage/entry.go')
-rw-r--r-- | storage/entry.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/storage/entry.go b/storage/entry.go index 556f526c..e1a85af4 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -17,6 +17,34 @@ import ( "github.com/lib/pq" ) +// CountAllEntries returns the number of entries for each status in the database. +func (s *Storage) CountAllEntries() map[string]int64 { + rows, err := s.db.Query(`SELECT status, count(*) FROM entries GROUP BY status`) + if err != nil { + return nil + } + defer rows.Close() + + results := make(map[string]int64) + results["unread"] = 0 + results["read"] = 0 + results["removed"] = 0 + + for rows.Next() { + var status string + var count int64 + + if err := rows.Scan(&status, &count); err != nil { + continue + } + + results[status] = count + } + + results["total"] = results["unread"] + results["read"] + results["removed"] + return results +} + // CountUnreadEntries returns the number of unread entries. func (s *Storage) CountUnreadEntries(userID int64) int { builder := s.NewEntryQueryBuilder(userID) |