Files
core/prometheus/filesystem.go
Jan Stabenow eb1cc37456 Add GoSRT & improvements (repo-merge)
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>
2022-06-23 22:13:58 +02:00

62 lines
1.7 KiB
Go

package prometheus
import (
"github.com/datarhei/core/v16/monitor/metric"
"github.com/prometheus/client_golang/prometheus"
)
type filesystemCollector struct {
core string
collector metric.Reader
fsLimitDesc *prometheus.Desc
fsUsageDesc *prometheus.Desc
fsFilesDesc *prometheus.Desc
}
func NewFilesystemCollector(core string, c metric.Reader) prometheus.Collector {
return &filesystemCollector{
core: core,
collector: c,
fsLimitDesc: prometheus.NewDesc(
"filesystem_limit_bytes",
"filesystem_limit_bytes",
[]string{"core", "name"}, nil),
fsUsageDesc: prometheus.NewDesc(
"filesystem_usage_bytes",
"filesystem_usage_bytes",
[]string{"core", "name"}, nil),
fsFilesDesc: prometheus.NewDesc(
"filesystem_files",
"filesystem_files",
[]string{"core", "name"}, nil),
}
}
func (c *filesystemCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.fsLimitDesc
ch <- c.fsUsageDesc
ch <- c.fsFilesDesc
}
func (c *filesystemCollector) Collect(ch chan<- prometheus.Metric) {
metrics := c.collector.Collect([]metric.Pattern{
metric.NewPattern("filesystem_limit"),
metric.NewPattern("filesystem_usage"),
metric.NewPattern("filesystem_files"),
})
for _, m := range metrics.Values("filesystem_limit") {
ch <- prometheus.MustNewConstMetric(c.fsLimitDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
}
for _, m := range metrics.Values("filesystem_usage") {
ch <- prometheus.MustNewConstMetric(c.fsUsageDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
}
for _, m := range metrics.Values("filesystem_files") {
ch <- prometheus.MustNewConstMetric(c.fsFilesDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
}
}