feat(collectors) basic implementation of boring collectors; sender via http(s) to hard coded api route
This commit is contained in:
41
internal/collectors/uptime/uptime.go
Normal file
41
internal/collectors/uptime/uptime.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package uptime
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"bugs.watch/agent/internal/aggregate"
|
||||
)
|
||||
|
||||
type Collector struct{}
|
||||
|
||||
func New() *Collector {
|
||||
return &Collector{}
|
||||
}
|
||||
|
||||
func (c *Collector) Name() string {
|
||||
return "uptime"
|
||||
}
|
||||
|
||||
// Collect reads /proc/uptime and stores the latest uptime in seconds.
|
||||
// Failure is silently ignored by design.
|
||||
func (c *Collector) Collect(window *aggregate.Window) {
|
||||
data, err := os.ReadFile("/proc/uptime")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Format: "<uptime_seconds> <idle_seconds>"
|
||||
fields := strings.Fields(string(data))
|
||||
if len(fields) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
seconds, err := strconv.ParseFloat(fields[0], 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
window.SetUptime(uint64(seconds))
|
||||
}
|
||||
Reference in New Issue
Block a user