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>
52 lines
1014 B
Go
52 lines
1014 B
Go
package monitor
|
|
|
|
import (
|
|
"github.com/datarhei/core/v16/monitor/metric"
|
|
"github.com/datarhei/core/v16/psutil"
|
|
)
|
|
|
|
type diskCollector struct {
|
|
path string
|
|
|
|
totalDescr *metric.Description
|
|
usageDescr *metric.Description
|
|
}
|
|
|
|
func NewDiskCollector(path string) metric.Collector {
|
|
c := &diskCollector{
|
|
path: path,
|
|
}
|
|
|
|
c.totalDescr = metric.NewDesc("disk_total", "", []string{"path"})
|
|
c.usageDescr = metric.NewDesc("disk_usage", "", []string{"path"})
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *diskCollector) Prefix() string {
|
|
return "disk"
|
|
}
|
|
|
|
func (c *diskCollector) Describe() []*metric.Description {
|
|
return []*metric.Description{
|
|
c.totalDescr,
|
|
c.usageDescr,
|
|
}
|
|
}
|
|
|
|
func (c *diskCollector) Collect() metric.Metrics {
|
|
metrics := metric.NewMetrics()
|
|
|
|
stat, err := psutil.DiskUsage(c.path)
|
|
if err != nil {
|
|
return metrics
|
|
}
|
|
|
|
metrics.Add(metric.NewValue(c.totalDescr, float64(stat.Total), c.path))
|
|
metrics.Add(metric.NewValue(c.usageDescr, float64(stat.Used), c.path))
|
|
|
|
return metrics
|
|
}
|
|
|
|
func (c *diskCollector) Stop() {}
|