ing
This commit is contained in:
parent
3134350172
commit
87ae90959a
|
@ -140,3 +140,18 @@ func (c *Crawler) ProcessStat(ch chan interface{}) {
|
|||
ch <- res
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *Crawler) Uptime(ch chan interface{}) {
|
||||
go func() {
|
||||
upt := &stat.Uptime{}
|
||||
b, err := c.sshCli.RunCommand(upt.Command())
|
||||
if err != nil {
|
||||
ch <- err
|
||||
}
|
||||
res, err := upt.Read(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
ch <- err
|
||||
}
|
||||
ch <- res
|
||||
}()
|
||||
}
|
||||
|
|
6
main.go
6
main.go
|
@ -125,8 +125,12 @@ func main() {
|
|||
cr.LoadAvgStat(loadCh)
|
||||
print(<-loadCh)
|
||||
|
||||
//Uptime
|
||||
uptCh := make(chan interface{})
|
||||
cr.Uptime(uptCh)
|
||||
print(<-uptCh)
|
||||
|
||||
//Process
|
||||
//Process (It doesn't to be a Map. will be displayed by a list)
|
||||
psCh := make(chan interface{})
|
||||
cr.ProcessStat(psCh)
|
||||
print(<-psCh)
|
||||
|
|
|
@ -1 +1,31 @@
|
|||
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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user