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() {
|
|
|
|
|
2017-10-26 02:38:04 +00:00
|
|
|
const ip = "192.168.1.15"
|
2017-10-20 06:10:30 +00:00
|
|
|
const port = "22"
|
2017-10-26 02:38:04 +00:00
|
|
|
const user = "administrator"
|
2017-10-20 06:10:30 +00:00
|
|
|
const pw = "!@#$qwer1234"
|
2017-10-26 02:38:04 +00:00
|
|
|
const keyFilePath = "" ///home/insanity/.ssh/id_rsa
|
2017-10-20 06:10:30 +00:00
|
|
|
|
2017-10-25 08:37:32 +00:00
|
|
|
cr, err := crawler.New(ip, port, user, pw, keyFilePath)
|
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)
|
|
|
|
|
2017-10-25 08:37:32 +00:00
|
|
|
|
2017-10-24 09:23:56 +00:00
|
|
|
//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",
|
2017-10-25 08:37:32 +00:00
|
|
|
"disk[1].io.merged_readcnt",
|
|
|
|
"disk[1].io.readbytes",
|
|
|
|
"disk[1].io.readtime",
|
2017-10-24 09:23:56 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2017-10-26 02:38:04 +00:00
|
|
|
//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)
|
|
|
|
|
|
|
|
|
2017-10-24 09:23:56 +00:00
|
|
|
|
|
|
|
//Network
|
|
|
|
netKeys := []string {
|
2017-10-25 08:37:32 +00:00
|
|
|
"net[0].transfer.iface",
|
|
|
|
"net[0].transfer.recv_byte",
|
|
|
|
"net[0].transfer.recv_packet",
|
|
|
|
"net[0].transfer.recv_err",
|
|
|
|
"net[0].transfer.recv_drop",
|
|
|
|
"net[0].transfer.recv_fifo",
|
|
|
|
"net[0].transfer.recv_frame",
|
|
|
|
"net[0].transfer.recv_compressed",
|
|
|
|
"net[0].transfer.recv_multicast",
|
|
|
|
"net[0].transfer.send_byte",
|
|
|
|
"net[0].transfer.send_packet",
|
|
|
|
"net[0].transfer.send_err",
|
|
|
|
"net[0].transfer.send_drop",
|
|
|
|
"net[0].transfer.send_fifo",
|
|
|
|
"net[0].transfer.send_frame",
|
|
|
|
"net[0].transfer.send_compressed",
|
|
|
|
"net[0].transfer.send_multicast",
|
2017-10-24 09:23:56 +00:00
|
|
|
|
|
|
|
"net[1].transfer.recv_packet",
|
2017-10-25 08:37:32 +00:00
|
|
|
"net[1].transfer.send_compressed",
|
|
|
|
"net[1].transfer.send_packet",
|
2017-10-24 09:23:56 +00:00
|
|
|
}
|
|
|
|
netCh := make(chan interface{})
|
|
|
|
cr.NetworkStat(netCh, netKeys)
|
|
|
|
print(<-netCh)
|
|
|
|
|
|
|
|
|
|
|
|
//Load Avg.
|
|
|
|
loadCh := make(chan interface{})
|
|
|
|
cr.LoadAvgStat(loadCh)
|
|
|
|
print(<-loadCh)
|
|
|
|
|
2017-10-24 09:30:22 +00:00
|
|
|
//Uptime
|
|
|
|
uptCh := make(chan interface{})
|
|
|
|
cr.Uptime(uptCh)
|
|
|
|
print(<-uptCh)
|
2017-10-24 09:23:56 +00:00
|
|
|
|
2017-10-24 09:30:22 +00:00
|
|
|
//Process (It doesn't to be a Map. will be displayed by a list)
|
2017-10-24 09:23:56 +00:00
|
|
|
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
|
|
|
}
|
2017-10-25 08:37:32 +00:00
|
|
|
|