happyDomain/internal/storage/stats_provider.go
Pierre-Olivier Mercier cbd03c5d2b Add storage stats Prometheus collector for business entity counts
Expose four live gauges queried at each scrape via a custom Collector:
- happydomain_registered_users_total
- happydomain_domains_total
- happydomain_zones_total
- happydomain_providers_total
2026-04-15 19:44:18 +07:00

40 lines
1.8 KiB
Go

// This file is part of the happyDomain (R) project.
// Copyright (c) 2020-2026 happyDomain
// Authors: Pierre-Olivier Mercier, et al.
//
// This program is offered under a commercial and under the AGPL license.
// For commercial licensing, contact us at <contact@happydomain.org>.
//
// For AGPL licensing:
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package storage
// StatsProvider implements metrics.StatsProvider using a Storage. It delegates
// to the storage backend's native Count* methods so each Prometheus scrape
// runs at most one cheap key-prefix scan per entity instead of decoding every
// record.
type StatsProvider struct {
store Storage
}
// NewStatsProvider creates a StatsProvider backed by the given Storage.
func NewStatsProvider(s Storage) *StatsProvider {
return &StatsProvider{store: s}
}
func (p *StatsProvider) CountUsers() (int, error) { return p.store.CountUsers() }
func (p *StatsProvider) CountDomains() (int, error) { return p.store.CountDomains() }
func (p *StatsProvider) CountZones() (int, error) { return p.store.CountZones() }
func (p *StatsProvider) CountProviders() (int, error) { return p.store.CountProviders() }