mirror of
https://github.com/datarhei/core.git
synced 2025-09-27 04:16:25 +08:00

Commits (Ingo Oppermann): - Add experimental SRT connection stats and logs - Hide /config/reload endpoint in reade-only mode - Add SRT server - Create v16 in go.mod - Fix data races, tests, lint, and update dependencies - Add trailing slash for routed directories (datarhei/restreamer#340) - Allow relative URLs in content in static routes Co-Authored-By: Ingo Oppermann <57445+ioppermann@users.noreply.github.com>
40 lines
899 B
Go
40 lines
899 B
Go
package prometheus
|
|
|
|
import (
|
|
"github.com/datarhei/core/v16/monitor/metric"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
type uptimeCollector struct {
|
|
core string
|
|
collector metric.Reader
|
|
|
|
uptimeDesc *prometheus.Desc
|
|
}
|
|
|
|
func NewUptimeCollector(core string, c metric.Reader) prometheus.Collector {
|
|
return &uptimeCollector{
|
|
core: core,
|
|
collector: c,
|
|
uptimeDesc: prometheus.NewDesc(
|
|
"uptime_seconds",
|
|
"Number of seconds the core is up",
|
|
[]string{"core"}, nil),
|
|
}
|
|
}
|
|
|
|
func (c *uptimeCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
ch <- c.uptimeDesc
|
|
}
|
|
|
|
func (c *uptimeCollector) Collect(ch chan<- prometheus.Metric) {
|
|
metrics := c.collector.Collect([]metric.Pattern{
|
|
metric.NewPattern("uptime_uptime"),
|
|
})
|
|
|
|
for _, m := range metrics.Values("uptime_uptime") {
|
|
ch <- prometheus.MustNewConstMetric(c.uptimeDesc, prometheus.CounterValue, m.Val(), c.core)
|
|
}
|
|
}
|