ssh_crawler/stat/uptime.go
insanity 87ae90959a ing
2017-10-24 18:30:22 +09:00

32 lines
480 B
Go

package stat
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()
}