ssh_crawler/stat/uptime.go

32 lines
480 B
Go
Raw Normal View History

2017-10-24 07:09:17 +00:00
package stat
2017-10-24 09:30:22 +00:00
import (
"io"
"bufio"
"strings"
)
type Uptime struct {
}
func (upt Uptime) Command() string {
return "uptime -s"
}
func (upt Uptime) Read(r io.Reader) (*map[string]string, error) {
var (
scanner = bufio.NewScanner(r)
resMap = make(map[string]string)
)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Fields(line)
resMap["system.uptime.date"] = parts[0]
resMap["system.uptime.time"]= parts[1]
}
return &resMap, scanner.Err()
}