srm

package module
v0.0.0-...-248c7a1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 7 Imported by: 0

README

srm

system resource monitor

SRMConfig

type SRMConfig struct {
	ListenAddr		string              // 监听地址,被动查询当前系统资源占用信息
	ReportAddr		string              // 主动上报地址
	ReportInterval	int64               // 主动上报时间间隔,单位秒
}

主动上报

按设定的时间间隔POST系统资源占用信息

{
	"cpu_usage": 17, // CPU使用率
	"mem_usage": 48, // 内存使用率
	"total_memory": 16310, // 总内存,单位MB
	"free_memory": 8576, // 空闲内存,单位MB
	"timestamp": 1655262283, // 时间戳
	"custom": {
		"data_1": "11111", // 自定义数据
		"data_2": "22222" // 自定义数据
	}
}

查询接口

GET http://xxx.xxx.xxx.xxx/info

{
	"cpu_usage": 17, // CPU使用率
	"mem_usage": 48, // 内存使用率
	"total_memory": 16310, // 总内存,单位MB
	"free_memory": 8576, // 空闲内存,单位MB
	"timestamp": 1655262283, // 时间戳
	"custom": {
		"data_1": "11111", // 自定义数据
		"data_2": "22222" // 自定义数据
	}
}

调用示例

srmobj := srm.NewSystemResourceMonitor(srm.SRMConfig{
			ListenAddr: ":10008",
			ReportAddr: "http://192.168.9.43:20008/test",
			ReportInterval: 10,
		})

srmobj.OnCollectInfo = nil
srmobj.OnReportResult = nil
srmobj.Run()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectInfoCallback

type CollectInfoCallback func(*SystemInfo)

type ReportResultCallback

type ReportResultCallback func([]byte, error)

type SRMConfig

type SRMConfig struct {
	ListenAddr     string
	ReportAddr     string
	ReportInterval int64
}

type SystemInfo

type SystemInfo struct {
	CpuUsage    int64       `json:"cpu_usage"`
	MemUsage    int64       `json:"mem_usage"`
	TotalMemory int64       `json:"total_memory"`
	FreeMemory  int64       `json:"free_memory"`
	Timestamp   int64       `json:"timestamp"`
	Custom      interface{} `json:"custom"`
}

type SystemResourceMonitor

type SystemResourceMonitor struct {
	OnCollectInfo  CollectInfoCallback
	OnReportResult ReportResultCallback
	// contains filtered or unexported fields
}

func NewSystemResourceMonitor

func NewSystemResourceMonitor(config SRMConfig) *SystemResourceMonitor

func (*SystemResourceMonitor) Run

func (s *SystemResourceMonitor) Run()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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