package crawler import ( "git.loafle.net/overflow/ssh_crawler/ssh" "git.loafle.net/overflow/ssh_crawler/stat" "bytes" ) type Crawler struct { sshCli *ssh.SSHClient } func New(ip, port, user, pw string) (*Crawler, error) { c := &Crawler{} err := c.connectSSH(ip, port, user, pw) if err != nil { return nil, err } return c, nil } func (c *Crawler) connectSSH(ip, port, user, pw string) error { client, err := ssh.New(ip, port, user, pw) if err != nil { return err } c.sshCli = client return nil } func (c *Crawler) CPUStat()([]stat.CPUStat, error) { cpu := &stat.CPUStat{} b, err := c.sshCli.RunCommand(cpu.Command()) if err != nil { return nil, err } return cpu.Parse(bytes.NewReader(b)) } func (c *Crawler) MEMStat()(map[string]string, error) { mem := &stat.MEMStat{} b, err := c.sshCli.RunCommand(mem.Command()) if err != nil { return nil, err } return mem.Parse(bytes.NewReader(b)) } func (c *Crawler) DiskIOStat()([]stat.DiskIOStat, error) { diskio := &stat.DiskIOStat{} b, err := c.sshCli.RunCommand(diskio.Command()) if err != nil { return nil, err } return diskio.Parse(bytes.NewReader(b)) } func (c *Crawler) DiskFreeStat()([]stat.DiskFreeStat, error) { diskFree := &stat.DiskFreeStat{} b, err := c.sshCli.RunCommand(diskFree.Command()) if err != nil { return nil, err } return diskFree.Parse(bytes.NewReader(b)) } func (c *Crawler) LoadAvgStat()(stat.LoadAvg, error) { load := &stat.LoadAvg{} b, err := c.sshCli.RunCommand(load.Command()) if err != nil { return stat.LoadAvg{}, err } return load.Parse(bytes.NewReader(b)) } func (c *Crawler) NetworkStat() ([]stat.NetDevStat, error) { net := &stat.NetDevStat{} b, err := c.sshCli.RunCommand(net.Command()) if err != nil { return nil, err } return net.Parse(bytes.NewReader(b)) }