sshproc

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 15 Imported by: 1

README

go-sshproc

GoDoc

About

This library is adds the functionality to get performance information from procfs to go-sshlib. Use an sftp client to obtain performance information by retrieving information such as /proc. For this reason, the ssh connection destination must be a UNIX-like OS such as Linux.

Some of the references and code have been changed in order to have almost the same usability as goprocinfo.

Usage

See GoDoc reference.

Example

// Copyright(c) 2024 Blacknon. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

package main

import (
    "fmt"
    "os"

    "github.com/blacknon/go-sshlib"
    "github.com/blacknon/go-sshproc"

    "golang.org/x/crypto/ssh"
)

var (
    host     = "server1.example.com"
    port     = "22"
    user     = "user"
    key      = "~/.ssh/id_rsa"
    password = ""
)

func main() {
    // Create sshlib.Connect
    con := &sshlib.Connect{}

    // Create ssh.AuthMethod
    authMethod, _ := sshlib.CreateAuthMethodPublicKey(key, password)

    // Connect ssh server
    con.HostKeyCallback = ssh.InsecureIgnoreHostKey()

    err := con.CreateClient(host, port, user, []ssh.AuthMethod{authMethod})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

 // Create sshproc
    proc := &sshproc.ConnectWithProc{Connect: con}
    err = proc.CreateSftpClient()
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    defer proc.CloseSftpClient()

    fmt.Println("")
    fmt.Println("Read CPUInfo")
    cpuinfo, err := proc.ReadCPUInfo("/proc/cpuinfo")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    fmt.Println(cpuinfo.NumCPU())
    fmt.Println(cpuinfo.NumCore())
    fmt.Println(cpuinfo.NumPhysicalCPU())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectWithProc

type ConnectWithProc struct {
	*sshlib.Connect
	// contains filtered or unexported fields
}

func (*ConnectWithProc) CheckSftpClient

func (c *ConnectWithProc) CheckSftpClient() bool

func (*ConnectWithProc) CloseSftpClient

func (c *ConnectWithProc) CloseSftpClient() error

func (*ConnectWithProc) CreateSftpClient

func (c *ConnectWithProc) CreateSftpClient() error

func (*ConnectWithProc) ListInPID

func (p *ConnectWithProc) ListInPID(path string) ([]uint64, error)

In ListPID, the pid is obtained by looping the specified number, but since this is slow to handle via ssh. It be handled by extracting the path that only has numbers under `/proc`.

func (*ConnectWithProc) ListPID

func (p *ConnectWithProc) ListPID(path string, max uint64) ([]uint64, error)

func (*ConnectWithProc) NetIPv4Decoder

func (p *ConnectWithProc) NetIPv4Decoder(s string) (string, error)

NetIPv4Decoder decodes an IPv4 address with port from a given hex string NOTE: This function match NetIPDecoder type

func (*ConnectWithProc) NetIPv6Decoder

func (p *ConnectWithProc) NetIPv6Decoder(s string) (string, error)

NetIPv6Decoder decodes an IPv6 address with port from a given hex string NOTE: This function match NetIPDecoder type

func (*ConnectWithProc) ReadCPUInfo

func (p *ConnectWithProc) ReadCPUInfo(path string) (*proc.CPUInfo, error)

func (*ConnectWithProc) ReadData

func (p *ConnectWithProc) ReadData(path string) (string, error)

func (*ConnectWithProc) ReadDisk

func (p *ConnectWithProc) ReadDisk(path string) (*proc.Disk, error)

func (*ConnectWithProc) ReadDiskStats

func (p *ConnectWithProc) ReadDiskStats(path string) ([]proc.DiskStat, error)

ReadDiskStats reads and parses the file.

Note: * Assumes a well formed file and will panic if it isn't.

func (*ConnectWithProc) ReadFibTrie

func (p *ConnectWithProc) ReadFibTrie(procFibTriePath string, procRoutePath string) (data []IPv4, err error)

func (*ConnectWithProc) ReadIfInet6

func (p *ConnectWithProc) ReadIfInet6(path string) (data []IPv6, err error)

func (*ConnectWithProc) ReadInterrupts

func (p *ConnectWithProc) ReadInterrupts(path string) (*proc.Interrupts, error)

func (*ConnectWithProc) ReadLoadAvg

func (p *ConnectWithProc) ReadLoadAvg(path string) (*proc.LoadAvg, error)

func (*ConnectWithProc) ReadMaxPID

func (p *ConnectWithProc) ReadMaxPID(path string) (uint64, error)

func (*ConnectWithProc) ReadMemInfo

func (p *ConnectWithProc) ReadMemInfo(path string) (*proc.MemInfo, error)

func (*ConnectWithProc) ReadMounts

func (p *ConnectWithProc) ReadMounts(path string) (*proc.Mounts, error)

func (*ConnectWithProc) ReadNetStat

func (p *ConnectWithProc) ReadNetStat(path string) (*proc.NetStat, error)

func (*ConnectWithProc) ReadNetTCPSockets

func (p *ConnectWithProc) ReadNetTCPSockets(path string, ip proc.NetIPDecoder) (*proc.NetTCPSockets, error)

func (*ConnectWithProc) ReadNetUDPSockets

func (p *ConnectWithProc) ReadNetUDPSockets(path string, ip proc.NetIPDecoder) (*proc.NetUDPSockets, error)

func (*ConnectWithProc) ReadNetUnixDomainSockets

func (p *ConnectWithProc) ReadNetUnixDomainSockets(fpath string) (*proc.NetUnixDomainSockets, error)

func (*ConnectWithProc) ReadNetworkStat

func (p *ConnectWithProc) ReadNetworkStat(path string) ([]proc.NetworkStat, error)

func (*ConnectWithProc) ReadProcess

func (p *ConnectWithProc) ReadProcess(pid uint64, path string) (*proc.Process, error)

func (*ConnectWithProc) ReadProcessCmdline

func (p *ConnectWithProc) ReadProcessCmdline(path string) (string, error)

func (*ConnectWithProc) ReadProcessIO

func (p *ConnectWithProc) ReadProcessIO(path string) (*proc.ProcessIO, error)

func (*ConnectWithProc) ReadProcessPassPermission

func (p *ConnectWithProc) ReadProcessPassPermission(pid uint64, path string) (*proc.Process, error)

func (*ConnectWithProc) ReadProcessSchedStat

func (p *ConnectWithProc) ReadProcessSchedStat(path string) (*proc.ProcessSchedStat, error)

func (*ConnectWithProc) ReadProcessStat

func (p *ConnectWithProc) ReadProcessStat(path string) (*proc.ProcessStat, error)

func (*ConnectWithProc) ReadProcessStatm

func (p *ConnectWithProc) ReadProcessStatm(path string) (*proc.ProcessStatm, error)

func (*ConnectWithProc) ReadProcessStatus

func (p *ConnectWithProc) ReadProcessStatus(path string) (*proc.ProcessStatus, error)

func (*ConnectWithProc) ReadSnmp

func (p *ConnectWithProc) ReadSnmp(path string) (*proc.Snmp, error)

func (*ConnectWithProc) ReadSockStat

func (p *ConnectWithProc) ReadSockStat(path string) (*proc.SockStat, error)

func (*ConnectWithProc) ReadStat

func (p *ConnectWithProc) ReadStat(path string) (*proc.Stat, error)

func (*ConnectWithProc) ReadUptime

func (p *ConnectWithProc) ReadUptime(path string) (*proc.Uptime, error)

func (*ConnectWithProc) ReadVMStat

func (p *ConnectWithProc) ReadVMStat(path string) (*proc.VMStat, error)

type IPv4

type IPv4 struct {
	Interface string
	IPAddress net.IP
	Netmask   net.IPMask
}

type IPv6

type IPv6 struct {
	Interface string
	IPAddress net.IP
	Prefix    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL