ssh_crawler/stat/mem.go

66 lines
1.3 KiB
Go
Raw Normal View History

2017-10-23 05:31:04 +00:00
package stat
import (
2017-10-23 09:08:19 +00:00
"bufio"
2017-10-23 05:31:04 +00:00
"io"
"strings"
)
2017-10-23 06:59:38 +00:00
type MemStat struct {
2017-10-23 05:31:04 +00:00
}
2017-11-09 09:04:07 +00:00
//func (mem MemStat) Command() string {
// return "cat /proc/meminfo"
//}
2017-10-23 05:31:04 +00:00
2017-11-09 09:04:07 +00:00
func (mem MemStat) Read(r io.Reader) (map[string]string, error) {
2017-10-23 05:31:04 +00:00
var (
2017-10-24 07:09:17 +00:00
stats = map[string]string{}
2017-10-23 05:31:04 +00:00
scanner = bufio.NewScanner(r)
)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Fields(line)
key := parts[0][:len(parts[0])-1]
2017-10-24 07:09:17 +00:00
stats[key] = parts[1]
}
2017-11-09 09:04:07 +00:00
//res, err := mem.parse(keys, stats)
//if err != nil {
// return nil, err
//}
2017-10-23 05:31:04 +00:00
2017-11-09 09:04:07 +00:00
return stats, scanner.Err()
2017-10-23 05:31:04 +00:00
}
2017-11-09 09:04:07 +00:00
//
//func (mem MemStat) parse(keys []string, data map[string]string) (map[string]string, error) {
// resMap := make(map[string]string)
//
// for _, key := range keys {
// switch key {
// case "mem.usage.total":
// resMap[key] = data["MemTotal"]
// case "mem.usage.free":
// resMap[key] = data["MemFree"]
// case "mem.usage.available":
// resMap[key] = data["MemAvailable"]
// case "mem.usage.buffers":
// resMap[key] = data["Buffers"]
// case "mem.usage.cached":
// resMap[key] = data["Cached"]
// case "mem.swap.usage.total":
// resMap[key] = data["SwapTotal"]
// case "mem.swap.usage.free":
// resMap[key] = data["SwapFree"]
// case "mem.swap.usage.cached":
// resMap[key] = data["SwapCached"]
// default:
//
// }
// }
//
// return resMap, nil
//}