2017-10-20 06:10:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-10-23 05:31:04 +00:00
|
|
|
"git.loafle.net/overflow/ssh_crawler/crawler"
|
2017-10-24 09:23:56 +00:00
|
|
|
"encoding/json"
|
2017-10-20 06:10:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
const ip = "192.168.1.15"
|
|
|
|
const port = "22"
|
|
|
|
const user = "administrator"
|
|
|
|
const pw = "!@#$qwer1234"
|
|
|
|
|
2017-10-23 05:31:04 +00:00
|
|
|
cr, err := crawler.New(ip, port, user, pw)
|
2017-10-20 06:10:30 +00:00
|
|
|
if err != nil {
|
2017-10-23 05:31:04 +00:00
|
|
|
fmt.Println(err)
|
2017-10-20 06:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 07:09:17 +00:00
|
|
|
cpukeys := []string{
|
|
|
|
"cpu.usage.sum",
|
|
|
|
"cpu.usage.user",
|
|
|
|
"cpu.usage.system",
|
|
|
|
"cpu.usage.nice",
|
|
|
|
"cpu.usage.idle",
|
|
|
|
"cpu.usage.iowait",
|
|
|
|
"cpu.usage.irq",
|
|
|
|
"cpu.usage.softirq",
|
|
|
|
"cpu.usage.steal",
|
|
|
|
"cpu.usage.guest",
|
2017-10-24 09:23:56 +00:00
|
|
|
"cpu.usage.gnice",
|
2017-10-24 07:09:17 +00:00
|
|
|
}
|
2017-10-23 06:59:38 +00:00
|
|
|
cpuCh := make(chan interface{})
|
2017-10-24 07:09:17 +00:00
|
|
|
cr.CPUStat(cpuCh, cpukeys)
|
2017-10-24 09:23:56 +00:00
|
|
|
print(<-cpuCh)
|
2017-10-20 06:10:30 +00:00
|
|
|
|
2017-10-23 06:59:38 +00:00
|
|
|
//Memory
|
2017-10-24 07:09:17 +00:00
|
|
|
memkeys := []string {
|
|
|
|
"mem.usage.total",
|
|
|
|
"mem.usage.free",
|
|
|
|
"mem.usage.available",
|
|
|
|
"mem.usage.buffers",
|
|
|
|
"mem.usage.cached",
|
|
|
|
"mem.swap.usage.total",
|
|
|
|
"mem.swap.usage.free",
|
|
|
|
"mem.swap.usage.cached",
|
|
|
|
}
|
2017-10-23 06:59:38 +00:00
|
|
|
memCh := make(chan interface{})
|
2017-10-24 07:09:17 +00:00
|
|
|
cr.MemStat(memCh, memkeys)
|
2017-10-24 09:23:56 +00:00
|
|
|
print(<-memCh)
|
|
|
|
|
|
|
|
//Disk IO
|
|
|
|
ioKeys := []string {
|
|
|
|
"disk[0].io.device",
|
|
|
|
"disk[0].io.readcnt",
|
|
|
|
"disk[0].io.merged_readcnt",
|
|
|
|
"disk[0].io.readbytes",
|
|
|
|
"disk[0].io.readtime",
|
|
|
|
"disk[0].io.writecnt",
|
|
|
|
"disk[0].io.merged_writecnt",
|
|
|
|
"disk[0].io.writebytes",
|
|
|
|
"disk[0].io.writetime",
|
|
|
|
"disk[0].io.iotime",
|
|
|
|
"disk[0].io.weighted",
|
|
|
|
|
|
|
|
"disk[1].io.readcnt",
|
|
|
|
"disk[2].io.merged_readcnt",
|
|
|
|
"disk[3].io.readbytes",
|
|
|
|
"disk[4].io.readtime",
|
|
|
|
}
|
|
|
|
diskioCh := make(chan interface{})
|
|
|
|
cr.DiskIOStat(diskioCh, ioKeys)
|
|
|
|
print(<-diskioCh)
|
|
|
|
|
|
|
|
|
|
|
|
//Disk Free
|
|
|
|
diskFreekeys := []string {
|
|
|
|
"disk[0].usage.fs",
|
|
|
|
"disk[0].usage.used",
|
|
|
|
"disk[0].usage.available",
|
|
|
|
"disk[0].usage.usedperc",
|
|
|
|
"disk[0].usage.mounted",
|
|
|
|
|
|
|
|
"disk[1].usage.fs",
|
|
|
|
"disk[2].usage.fs",
|
|
|
|
}
|
|
|
|
diskFreeCh := make(chan interface{})
|
|
|
|
cr.DiskFreeStat(diskFreeCh, diskFreekeys)
|
|
|
|
print(<-diskFreeCh)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Network
|
|
|
|
netKeys := []string {
|
|
|
|
"net[14].transfer.iface",
|
|
|
|
"net[14].transfer.recv_byte",
|
|
|
|
"net[14].transfer.recv_packet",
|
|
|
|
"net[14].transfer.recv_err",
|
|
|
|
"net[14].transfer.recv_drop",
|
|
|
|
"net[14].transfer.recv_fifo",
|
|
|
|
"net[14].transfer.recv_frame",
|
|
|
|
"net[14].transfer.recv_compressed",
|
|
|
|
"net[14].transfer.recv_multicast",
|
|
|
|
"net[14].transfer.send_byte",
|
|
|
|
"net[14].transfer.send_packet",
|
|
|
|
"net[14].transfer.send_err",
|
|
|
|
"net[14].transfer.send_drop",
|
|
|
|
"net[14].transfer.send_fifo",
|
|
|
|
"net[14].transfer.send_frame",
|
|
|
|
"net[14].transfer.send_compressed",
|
|
|
|
"net[14].transfer.send_multicast",
|
|
|
|
|
|
|
|
"net[1].transfer.recv_packet",
|
|
|
|
"net[2].transfer.send_compressed",
|
|
|
|
"net[3].transfer.send_packet",
|
|
|
|
}
|
|
|
|
netCh := make(chan interface{})
|
|
|
|
cr.NetworkStat(netCh, netKeys)
|
|
|
|
print(<-netCh)
|
|
|
|
|
|
|
|
|
|
|
|
//Load Avg.
|
|
|
|
loadCh := make(chan interface{})
|
|
|
|
cr.LoadAvgStat(loadCh)
|
|
|
|
print(<-loadCh)
|
|
|
|
|
|
|
|
|
|
|
|
//Process
|
|
|
|
psCh := make(chan interface{})
|
|
|
|
cr.ProcessStat(psCh)
|
|
|
|
print(<-psCh)
|
|
|
|
}
|
|
|
|
|
|
|
|
func print(data interface{}) {
|
|
|
|
jsonData, err := json.Marshal(data)
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
fmt.Println(string(jsonData))
|
2017-10-23 09:08:19 +00:00
|
|
|
}
|