ssh_crawler/main.go
insanity 87ae90959a ing
2017-10-24 18:30:22 +09:00

145 lines
2.9 KiB
Go

package main
import (
"fmt"
"git.loafle.net/overflow/ssh_crawler/crawler"
"encoding/json"
)
func main() {
const ip = "192.168.1.15"
const port = "22"
const user = "administrator"
const pw = "!@#$qwer1234"
cr, err := crawler.New(ip, port, user, pw)
if err != nil {
fmt.Println(err)
}
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",
"cpu.usage.gnice",
}
cpuCh := make(chan interface{})
cr.CPUStat(cpuCh, cpukeys)
print(<-cpuCh)
//Memory
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",
}
memCh := make(chan interface{})
cr.MemStat(memCh, memkeys)
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)
//Uptime
uptCh := make(chan interface{})
cr.Uptime(uptCh)
print(<-uptCh)
//Process (It doesn't to be a Map. will be displayed by a list)
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))
}