1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

Add Prometheus exporter

This commit is contained in:
Frédéric Guillot 2020-09-27 16:01:06 -07:00 committed by Frédéric Guillot
parent 16b7b3bc3e
commit c394a61a4e
61 changed files with 809 additions and 96 deletions

View file

@ -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)