Documentation
¶
Index ¶
- Constants
- type Config
- type HistogramSource
- type Manager
- func (m *Manager) AdminHTTPHandler() http.HandlerFunc
- func (m *Manager) CleanupOldData() error
- func (m *Manager) GetAllCounters() map[string]int64
- func (m *Manager) GetCounterValue(key string) int64
- func (m *Manager) GetDailyUserCount(date string) int64
- func (m *Manager) GetTodayUserCount() int64
- func (m *Manager) HTTPHandler() http.HandlerFunc
- func (m *Manager) Increment(key string)
- func (m *Manager) IncrementBy(key string, n int64)
- func (m *Manager) IncrementDaily(key string)
- func (m *Manager) IncrementDailyBy(key string, n int64)
- func (m *Manager) SetHistogramSource(src HistogramSource)
- func (m *Manager) Shutdown()
- func (m *Manager) TrackDailyUser(userID string)
- func (m *Manager) WritePrometheus(buf *bytes.Buffer)
- type ToolBucket
- type ToolHistogramSnapshot
Constants ¶
const ( DefaultServiceName = "kite-mcp" DefaultHistoricalDays = 7 DefaultCleanupRetentionDays = 30 DefaultCleanupHour = 3 // 3 AM DefaultCleanupDay = 6 // Saturday (0=Sunday, 6=Saturday) PrometheusContentType = "text/plain; version=0.0.4; charset=utf-8" AdminPathPrefix = "/admin/" MetricsPathSuffix = "/metrics" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ServiceName string // defaults to DefaultServiceName
AdminSecretPath string // required for admin endpoint, empty = disabled
HistoricalDays int // defaults to DefaultHistoricalDays
CleanupRetentionDays int // defaults to DefaultCleanupRetentionDays
AutoCleanup bool // defaults to true
}
Config holds configuration for creating a metrics manager
type HistogramSource ¶
type HistogramSource func() ([]ToolHistogramSnapshot, error)
HistogramSource is invoked at scrape time to produce the per-tool latency histogram snapshots. Returning a non-nil error suppresses histogram emission for the scrape (counters and other metrics still emit). Nil source = no histograms emitted (back-compat default).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles metrics collection and export
func (*Manager) AdminHTTPHandler ¶
func (m *Manager) AdminHTTPHandler() http.HandlerFunc
AdminHTTPHandler returns an HTTP handler with admin path protection
func (*Manager) CleanupOldData ¶
CleanupOldData removes user data older than the configured retention period
func (*Manager) GetAllCounters ¶
GetAllCounters returns a snapshot of all counter values.
func (*Manager) GetCounterValue ¶
GetCounterValue returns the current value of a counter
func (*Manager) GetDailyUserCount ¶
GetDailyUserCount returns unique user count for a specific date
func (*Manager) GetTodayUserCount ¶
GetTodayUserCount returns today's unique user count
func (*Manager) HTTPHandler ¶
func (m *Manager) HTTPHandler() http.HandlerFunc
HTTPHandler returns an HTTP handler for the metrics endpoint
func (*Manager) IncrementBy ¶
IncrementBy atomically increments a counter by n
func (*Manager) IncrementDaily ¶
IncrementDaily atomically increments a daily counter for today
func (*Manager) IncrementDailyBy ¶
IncrementDailyBy atomically increments a daily counter by n for today
func (*Manager) SetHistogramSource ¶
func (m *Manager) SetHistogramSource(src HistogramSource)
SetHistogramSource registers (or replaces, or clears with nil) the histogram source. Safe to call concurrently with WritePrometheus — the source pointer is read once per scrape.
func (*Manager) TrackDailyUser ¶
TrackDailyUser tracks a unique user login for today
func (*Manager) WritePrometheus ¶
WritePrometheus writes all metrics in Prometheus format
type ToolBucket ¶
ToolBucket is a single Prometheus-style cumulative bucket. Mirrors kc/audit.ToolHistogramBucket but lives in this package so the metrics surface does not import kc/audit (would invert the layer graph). The wire-up site (app/wire.go) bridges the two shapes via a small adapter closure.
type ToolHistogramSnapshot ¶
type ToolHistogramSnapshot struct {
ToolName string
CallCount int
SumMs float64
Buckets []ToolBucket
}
ToolHistogramSnapshot is the histogram-source row for a single tool. CallCount equals the +Inf bucket; SumMs is the sum of all duration_ms values in the window. Buckets must be cumulative non-decreasing per Prometheus convention.