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:
parent
16b7b3bc3e
commit
c394a61a4e
61 changed files with 809 additions and 96 deletions
|
@ -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)
|
||||
|
|
|
@ -76,6 +76,37 @@ func (s *Storage) AnotherFeedURLExists(userID, feedID int64, feedURL string) boo
|
|||
return result
|
||||
}
|
||||
|
||||
// CountAllFeeds returns the number of feeds in the database.
|
||||
func (s *Storage) CountAllFeeds() map[string]int64 {
|
||||
rows, err := s.db.Query(`SELECT disabled, count(*) FROM feeds GROUP BY disabled`)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
results := make(map[string]int64)
|
||||
results["enabled"] = 0
|
||||
results["disabled"] = 0
|
||||
|
||||
for rows.Next() {
|
||||
var disabled bool
|
||||
var count int64
|
||||
|
||||
if err := rows.Scan(&disabled, &count); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if disabled {
|
||||
results["disabled"] = count
|
||||
} else {
|
||||
results["enabled"] = count
|
||||
}
|
||||
}
|
||||
|
||||
results["total"] = results["disabled"] + results["enabled"]
|
||||
return results
|
||||
}
|
||||
|
||||
// CountFeeds returns the number of feeds that belongs to the given user.
|
||||
func (s *Storage) CountFeeds(userID int64) int {
|
||||
var result int
|
||||
|
@ -87,9 +118,9 @@ func (s *Storage) CountFeeds(userID int64) int {
|
|||
return result
|
||||
}
|
||||
|
||||
// CountErrorFeeds returns the number of feeds with parse errors that belong to the given user.
|
||||
func (s *Storage) CountErrorFeeds(userID int64) int {
|
||||
query := `SELECT count(*) FROM feeds WHERE user_id=$1 AND parsing_error_count>=$2`
|
||||
// CountUserFeedsWithErrors returns the number of feeds with parsing errors that belong to the given user.
|
||||
func (s *Storage) CountUserFeedsWithErrors(userID int64) int {
|
||||
query := `SELECT count(*) FROM feeds WHERE user_id=$1 AND parsing_error_count >= $2`
|
||||
var result int
|
||||
err := s.db.QueryRow(query, userID, maxParsingError).Scan(&result)
|
||||
if err != nil {
|
||||
|
@ -99,6 +130,18 @@ func (s *Storage) CountErrorFeeds(userID int64) int {
|
|||
return result
|
||||
}
|
||||
|
||||
// CountAllFeedsWithErrors returns the number of feeds with parsing errors.
|
||||
func (s *Storage) CountAllFeedsWithErrors() int {
|
||||
query := `SELECT count(*) FROM feeds WHERE parsing_error_count >= $1`
|
||||
var result int
|
||||
err := s.db.QueryRow(query, maxParsingError).Scan(&result)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Feeds returns all feeds that belongs to the given user.
|
||||
func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
|
||||
return s.fetchFeeds(feedListQuery, "", userID)
|
||||
|
|
|
@ -16,6 +16,17 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// CountUsers returns the total number of users.
|
||||
func (s *Storage) CountUsers() int {
|
||||
var result int
|
||||
err := s.db.QueryRow(`SELECT count(*) FROM users`).Scan(&result)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// SetLastLogin updates the last login date of a user.
|
||||
func (s *Storage) SetLastLogin(userID int64) error {
|
||||
query := `UPDATE users SET last_login_at=now() WHERE id=$1`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue