ing
This commit is contained in:
parent
d75e100746
commit
2d3723fb27
|
@ -97,6 +97,23 @@ func (c *Crawler) DiskFreeStat(ch chan interface{}, keys []string) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Crawler) DiskIFreeStat(ch chan interface{}, keys []string) {
|
||||||
|
go func() {
|
||||||
|
diskFree := &stat.DiskIFreeStat{}
|
||||||
|
b, err := c.sshCli.RunCommand(diskFree.Command())
|
||||||
|
if err != nil {
|
||||||
|
ch <- err
|
||||||
|
}
|
||||||
|
res, err := diskFree.Read(bytes.NewReader(b), keys)
|
||||||
|
if err != nil {
|
||||||
|
ch <- err
|
||||||
|
}
|
||||||
|
ch <- res
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Crawler) LoadAvgStat(ch chan interface{}) {
|
func (c *Crawler) LoadAvgStat(ch chan interface{}) {
|
||||||
go func() {
|
go func() {
|
||||||
load := &stat.LoadAvg{}
|
load := &stat.LoadAvg{}
|
||||||
|
|
22
main.go
22
main.go
|
@ -8,11 +8,11 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
const ip = "192.168.1.215"
|
const ip = "192.168.1.15"
|
||||||
const port = "22"
|
const port = "22"
|
||||||
const user = "snoop"
|
const user = "administrator"
|
||||||
const pw = "!@#$qwer1234"
|
const pw = "!@#$qwer1234"
|
||||||
const keyFilePath = "/home/insanity/.ssh/id_rsa"
|
const keyFilePath = "" ///home/insanity/.ssh/id_rsa
|
||||||
|
|
||||||
cr, err := crawler.New(ip, port, user, pw, keyFilePath)
|
cr, err := crawler.New(ip, port, user, pw, keyFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -92,6 +92,22 @@ func main() {
|
||||||
print(<-diskFreeCh)
|
print(<-diskFreeCh)
|
||||||
|
|
||||||
|
|
||||||
|
//Disk Inode Free
|
||||||
|
diskInodeKeys := []string {
|
||||||
|
"disk[0].inode.usage.fs",
|
||||||
|
"disk[0].inode.usage.used",
|
||||||
|
"disk[0].inode.usage.available",
|
||||||
|
"disk[0].inode.usage.usedperc",
|
||||||
|
"disk[0].inode.usage.mounted",
|
||||||
|
|
||||||
|
"disk[1].inode.usage.fs",
|
||||||
|
"disk[2].inode.usage.fs",
|
||||||
|
}
|
||||||
|
diskInodeFreeCh := make(chan interface{})
|
||||||
|
cr.DiskIFreeStat(diskInodeFreeCh, diskInodeKeys)
|
||||||
|
print(<-diskInodeFreeCh)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Network
|
//Network
|
||||||
netKeys := []string {
|
netKeys := []string {
|
||||||
|
|
78
stat/disk_ifree.go
Normal file
78
stat/disk_ifree.go
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
package stat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"strconv"
|
||||||
|
"git.loafle.net/overflow/ssh_crawler/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DiskIFreeStat struct {
|
||||||
|
Filesystem,
|
||||||
|
Size,
|
||||||
|
Used,
|
||||||
|
Free,
|
||||||
|
UsePerc,
|
||||||
|
MountedOn string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (diskFree DiskIFreeStat) Command() string {
|
||||||
|
return "df -ik"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (diskio DiskIFreeStat) Read(r io.Reader, keys []string) (*map[string]string, error) {
|
||||||
|
|
||||||
|
var scanner = bufio.NewScanner(r)
|
||||||
|
var stats = []DiskIFreeStat{}
|
||||||
|
|
||||||
|
scanner.Scan()
|
||||||
|
for scanner.Scan() {
|
||||||
|
parts := strings.Fields(scanner.Text())
|
||||||
|
stats = append(stats, DiskIFreeStat{
|
||||||
|
Filesystem: parts[0],
|
||||||
|
Size: parts[1],
|
||||||
|
Used: parts[2],
|
||||||
|
Free: parts[3],
|
||||||
|
UsePerc: removePercUnit(parts[4]),
|
||||||
|
MountedOn: parts[5],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := diskio.parse(keys, stats)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &res, scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (diskio DiskIFreeStat) parse(keys []string, data []DiskIFreeStat) (map[string]string, error) {
|
||||||
|
resMap := make(map[string]string)
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
t := strings.Split(key, ".")
|
||||||
|
suffix := t[len(t)-1]
|
||||||
|
ext := util.ExtractInBracket(key)
|
||||||
|
idx, _ := strconv.Atoi(ext)
|
||||||
|
|
||||||
|
switch suffix {
|
||||||
|
case "fs":
|
||||||
|
resMap[key] = data[idx].Filesystem
|
||||||
|
case "used":
|
||||||
|
resMap[key] = data[idx].Used
|
||||||
|
case "free":
|
||||||
|
resMap[key] = data[idx].Free
|
||||||
|
case "usedperc":
|
||||||
|
resMap[key] = data[idx].UsePerc
|
||||||
|
case "mounted":
|
||||||
|
resMap[key] = data[idx].MountedOn
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resMap, nil
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ func (diskio DiskIOStat) Read(r io.Reader, keys []string) (interface{}, error) {
|
||||||
return nil, fmt.Errorf("invalid line in %s: %s", "/proc/diskstats", scanner.Text())
|
return nil, fmt.Errorf("invalid line in %s: %s", "/proc/diskstats", scanner.Text())
|
||||||
}
|
}
|
||||||
deviceName := parts[2]
|
deviceName := parts[2]
|
||||||
if !strings.HasPrefix(deviceName, "sd") {
|
if strings.HasPrefix(deviceName, "loop") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stats = append(stats, DiskIOStat{
|
stats = append(stats, DiskIOStat{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user