system

package module
v0.0.0-...-69e173b Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 24 Imported by: 0

README

system

A system api library based on golang, only use on linux;

Documentation

Index

Constants

View Source
const (
	DataScanPeriodOfMin = time.Duration(100) * time.Millisecond
)

Variables

This section is empty.

Functions

func BashCommand

func BashCommand(cmd string) ([]byte, error)

func BuildImageFromDockerfile

func BuildImageFromDockerfile(ctx context.Context, dockerfile string, name string, version string) error

dockerfile中ADD、COPY等命令中的src是相对与此执行程序所在目录的相对路径

func CPUArch

func CPUArch() (arch string)

CPUArch get CPU architecture type.

func CPUInfo

func CPUInfo() (map[string]CPU, error)

CPUInfo get CPU info.

func CPULoad

func CPULoad() (*load.AvgStat, error)

CPULoad get CPU load.

func CPULogicalCount

func CPULogicalCount() (int, error)

CPULogicalCount get CPU logical count.

func CPUNum

func CPUNum() (coreNum int)

CPUNum get the number of logical CPUs usable by the current process.

func CPUPhysicalCount

func CPUPhysicalCount() (int, error)

CPUPhysicalCount get CPU physical count.

func CPUTimesPer

func CPUTimesPer() ([]cpu.TimesStat, error)

CPUTimesTotal get CPU usage.

func CPUTimesTotal

func CPUTimesTotal() (cpu.TimesStat, error)

CPUTimesTotal get CPU usage.

func CPUUsagePer

func CPUUsagePer() ([]float64, error)

CPUUsagePer get CPU usage.

func CPUUsageTotal

func CPUUsageTotal() (float64, error)

CPUUsageTotal get CPU usage.

func Caller

func Caller(level int) (file string, line int, pkgName string, funcName string)

Caller returns information of the assigned level calling function. level = 0 - get Caller() itself info; level = 1 - get Caller()'s father info; level = 2 - get Caller()'s grandfather info;

func CommandAlwaysWithContext

func CommandAlwaysWithContext(ctx context.Context, outReader **bufio.Reader, exeName string, args ...string) error

func CommandOnceWithContext

func CommandOnceWithContext(ctx context.Context, exeName string, args ...string) ([]byte, error)

func ContainerUsage

func ContainerUsage(ctx context.Context) (<-chan ContainerState, error)

func CreateContainer

func CreateContainer(ctx context.Context, baseImage string, name string, arg ...string) (string, error)

func DebugServerMode

func DebugServerMode(port int)

DebugServerMode Turn on debugging information logging, and you can view the specific usage of program memory, coroutines, etc. in the link. Note you need at main package import _ "net/http/pprof". More, recommend you add import _ "github.com/mkevac/debugcharts" to see more char info.

func GetDockerVersion

func GetDockerVersion(ctx context.Context) (string, error)

docker version --format '{{.Server.Version}}'

func GetGoroutineID

func GetGoroutineID() int64

GetGoroutineID Get the coroutine ID (this method affects performance and is only used for debugging).

func GetNowGMTDatetime

func GetNowGMTDatetime() (string, error)

func GetOS

func GetOS() (os string)

GetOS get os type.

func GetPID

func GetPID() int

func GetPath

func GetPath() (string, error)

func LocalIP

func LocalIP() (string, error)

LocalIP get local PC IP.

func NetInfo

func NetInfo() ([]net.IOCountersStat, error)

NetInfo get net interface IO info.

func OutboundIP

func OutboundIP(server string) (string, error)

OutboundIP get local PC outbound IP.

func RemoveContainer

func RemoveContainer(ctx context.Context, id string) error

func RestartContainer

func RestartContainer(ctx context.Context, id string) error

func SecurityExitProcess

func SecurityExitProcess(exitFunc exitFunc)

SecurityExitProcess Listen for system signals, execute exitFunc to release program resources, and exit gracefully.

func SecurityExitProcessWithNotify

func SecurityExitProcessWithNotify(exitFunc exitFunc, cc chan string)

SecurityExitProcessWithNotify Listen for system signals and notify, execute exitFunc to release program resources, and exit gracefully.

func StartContainer

func StartContainer(ctx context.Context, id string) error

func StopContainer

func StopContainer(ctx context.Context, id string) error

func System

func System() (*host.InfoStat, error)

System get System info.

func TimeDataNow

func TimeDataNow() string

TimeDataNow The current date and time.

func TimeToTimestamp

func TimeToTimestamp(timeStr string, layout string) (int64, error)

TimeToTimestamp Convert a datetime string into a timestamp by layout. Layout see in go/src/time/format.go, eq:time.RFC3339Nano.

func TimestampMicNow

func TimestampMicNow() int64

TimestampMicNow Current timestamp, accurate to the micsecond.

func TimestampMilNow

func TimestampMilNow() int64

TimestampMilNow Current timestamp, accurate to the millisecond.

func TimestampNanoNow

func TimestampNanoNow() int64

TimestampNanoNow Current timestamp, accurate to nanosecond.

func TimestampNow

func TimestampNow() int64

TimestampNow Current timestamp, accurate to the second.

func TimestampToTime

func TimestampToTime(nanoSec int64) time.Time

TimestampToTime converts a timestamp nano to time.Time.

Types

type CPU

type CPU struct {
	ModeName string  `json:"modeName"`
	Mhz      float64 `json:"mhz"`
	CoreNum  int     `json:"coreNum"`
}

type ContainerInfo

type ContainerInfo struct {
	ID         string `json:"ID"`
	Image      string `json:"Image"`
	Command    string `json:"Command"`
	CreatedAt  string `json:"CreatedAt"`
	RunningFor string `json:"RunningFor"`
	Ports      string `json:"Ports"`
	State      string `json:"State"`
	Status     string `json:"Status"`
	Size       string `json:"Size"`
	Names      string `json:"Names"`
	Labels     string `json:"Labels"`
	Mounts     string `json:"Mounts"`
	Networks   string `json:"Networks"`
}

func ContainerAllList

func ContainerAllList(ctx context.Context) ([]ContainerInfo, error)

type ContainerState

type ContainerState struct {
	Id           string  `json:"id"`
	Name         string  `json:"name"`
	CpuPerc      float64 `json:"cpuPerc"`
	MemPerc      float64 `json:"memperc"`
	MemUsage     float64 `json:"memUsage"`
	MemUsageUnit string  `json:"memUsageUnit"`
	MemLimit     float64 `json:"memLimit"`
	MemLimitUnit string  `json:"memLimitUnit"`
}

type Disk

type Disk struct {
	Partitions []Partition
}

Disk info.

func DiskInfo

func DiskInfo() (Disk, error)

DiskInfo get disk info.

type Memory

type Memory struct {
	Total float64 `json:"total"`
	Free  float64 `json:"free"`
	Usage float64 `json:"usage"`
	Used  float64 `json:"used"`
}

Memory info.

func MemInfo

func MemInfo() (Memory, error)

MemInfo get memory info, per - GB.

type Partition

type Partition struct {
	Mountpoint string
	Total      uint64  // per - GB
	Free       uint64  // per - GB
	Usage      float64 // 100%
}

type PipeServer

type PipeServer struct {
	// contains filtered or unexported fields
}

func NewPipeServer

func NewPipeServer(file string, period time.Duration) *PipeServer

func (*PipeServer) Close

func (ps *PipeServer) Close()

func (*PipeServer) GetDataCh

func (ps *PipeServer) GetDataCh() <-chan []byte

func (*PipeServer) Start

func (ps *PipeServer) Start() error

type PrecessState

type PrecessState struct {
	Pid     int64   `json:"pid"`
	CpuPerc float64 `json:"cpuPerc"`
	MemPerc float64 `json:"memPerc"`
	VSZ     int64   `json:"vsz"`
	RSS     int64   `json:"rss"`
	State   string  `json:"state"`
	StartAt string  `json:"startAt"`
	Time    string  `json:"time"`
	Cmd     string  `json:"cmd"`
}

func GetProcessInfo

func GetProcessInfo(server string) (PrecessState, error)

Jump to

Keyboard shortcuts

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