performance

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 11 Imported by: 4

README

go-performance

performance of application, include cpu, memory usage, and etc.

// UpdateCPUUsage 需要定时调用更新CPU使用率
performance.UpdateCPUUsage(context.Background())
// 获取当前CPU与内存使用
performance.CurrentCPUMemory(context.Background())

httpServerConnStats := performance.NewHttpServerConnStats()
http.Server{
    ConnState: httpServerConnStats.ConnState
}

ioCounters, err := performance.IOCounters(context.Background())

connsStat, err := performance.Connections(context.Background())

ctxSwitchesStat, err := performance.NumCtxSwitches(context.Background())

count, err := performance.NumFds(context.Background())

pageFaultsStat, err := performance.PageFaults(context.Background())

openFilesStat, err := performance.OpenFiles(context.Background())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConcurrency

func NewConcurrency() *concurrency

NewConcurrency create a new concurrency

func NewHttpServerConnStats

func NewHttpServerConnStats() *httpServerConnStats

NewHttpServerConnStats create a new http server conn stats

func UpdateCPUUsage

func UpdateCPUUsage(ctx context.Context) error

UpdateCPUUsage 更新cpu使用率

Types

type CPUMemory

type CPUMemory struct {
	GoMaxProcs   int   `json:"goMaxProcs"`
	ThreadCount  int32 `json:"threadCount"`
	RoutineCount int   `json:"routineCount"`

	CPUUser      int    `json:"cpuUser"`
	CPUSystem    int    `json:"cpuSystem"`
	CPUIdle      int    `json:"cpuIdle"`
	CPUNice      int    `json:"cpuNice"`
	CPUIowait    int    `json:"cpuIowait"`
	CPUIrq       int    `json:"cpuIrq"`
	CPUSoftirq   int    `json:"cpuSoftirq"`
	CPUSteal     int    `json:"cpuSteal"`
	CPUGuest     int    `json:"cpuGuest"`
	CPUGuestNice int    `json:"cpuGuestNice"`
	CPUUsage     int32  `json:"cpuUsage"`
	CPUBusy      string `json:"cpuBusy"`

	MemAlloc      int    `json:"memAlloc"`
	MemTotalAlloc int    `json:"memTotalAlloc"`
	MemSys        int    `json:"memSys"`
	MemLookups    uint64 `json:"memLookups"`
	MemMallocs    uint64 `json:"memMallocs"`
	MemFrees      uint64 `json:"memFrees"`

	MemHeapAlloc    int    `json:"memHeapAlloc"`
	MemHeapSys      int    `json:"memHeapSys"`
	MemHeapIdle     int    `json:"memHeapIdle"`
	MemHeapInuse    int    `json:"memHeapInuse"`
	MemHeapReleased int    `json:"memHeapReleased"`
	MemHeapObjects  uint64 `json:"memHeapObjects"`

	MemStackInuse int `json:"memStackInuse"`
	MemStackSys   int `json:"memStackSys"`

	MemMSpanInuse  int `json:"memMSpanInuse"`
	MemMSpanSys    int `json:"memMSpanSys"`
	MemMCacheInuse int `json:"memMCacheInuse"`
	MemMCacheSys   int `json:"memMCacheSys"`
	MemBuckHashSys int `json:"memBuckHashSys"`

	MemGCSys    int `json:"memGCSys"`
	MemOtherSys int `json:"memOtherSys"`

	LastGC        time.Time     `json:"lastGC"`
	NumGC         uint32        `json:"numGC"`
	NumForcedGC   uint32        `json:"numForcedGC"`
	RecentPause   string        `json:"recentPause"`
	RecentPauseNs time.Duration `json:"recentPauseNs"`
	PauseTotal    string        `json:"pauseTotal"`
	PauseTotalNs  time.Duration `json:"pauseTotalNs"`
	PauseNs       [256]uint64   `json:"pauseNs"`

	// 各指标收集耗时
	// 内存指标
	MemStatsTook time.Duration
	// 线程指标
	ThreadCountStatsTook time.Duration
	// CPU使用
	CPUTimeStatsTook time.Duration
}

CPUMemory 应用CPU与Memory相关指标

func CurrentCPUMemory

func CurrentCPUMemory(ctx context.Context) CPUMemory

CurrentCPUMemory 获取当前应用性能指标

type ConnStats

type ConnStats struct {
	ConnProcessing     int32 `json:"connProcessing"`
	ConnProcessedCount int64 `json:"connProcessedCount"`
	ConnAlive          int32 `json:"connAlive"`
	ConnCreatedCount   int64 `json:"connCreatedCount"`
}

ConnStats conn stats

type ConnectionStat added in v0.5.0

type ConnectionStat struct {
	Connections []pnet.ConnectionStat `json:"connections"`
	Took        time.Duration         `json:"took"`
}

func Connections added in v0.3.0

func Connections(ctx context.Context) (*ConnectionStat, error)

Connections returns the connections stats

type ConnectionsCount added in v0.3.0

type ConnectionsCount struct {
	Status     map[string]int `json:"status"`
	RemoteAddr map[string]int `json:"remoteAddr"`
	Count      int            `json:"count"`
	Took       time.Duration  `json:"took"`
}

func ConnectionsStat added in v0.3.0

func ConnectionsStat(ctx context.Context) (*ConnectionsCount, error)

ConnectionsStat return the count of connections stats

type IOCountersStat added in v0.5.0

type IOCountersStat struct {
	process.IOCountersStat
	Took time.Duration `json:"took"`
}

func IOCounters added in v0.3.0

func IOCounters(ctx context.Context) (*IOCountersStat, error)

IOCounters returns the conters stats info

type NumCtxSwitchesStat added in v0.5.0

type NumCtxSwitchesStat struct {
	process.NumCtxSwitchesStat
	Took time.Duration `json:"took"`
}

func NumCtxSwitches added in v0.3.0

func NumCtxSwitches(ctx context.Context) (*NumCtxSwitchesStat, error)

NumCtxSwitches returns the switch stats of process

type NumFdsStat added in v0.5.0

type NumFdsStat struct {
	Fds  int32         `json:"fds"`
	Took time.Duration `json:"took"`
}

func NumFds added in v0.3.0

func NumFds(ctx context.Context) (*NumFdsStat, error)

NumFds returns the count of fd

type OpenFilesStat added in v0.5.0

type OpenFilesStat struct {
	OpenFiles []process.OpenFilesStat `json:"openFiles"`
	Took      time.Duration           `json:"took"`
}

func OpenFiles added in v0.3.0

func OpenFiles(ctx context.Context) (*OpenFilesStat, error)

OpenFiles returns open file stats

type PageFaultsStat added in v0.5.0

type PageFaultsStat struct {
	process.PageFaultsStat
	Took time.Duration `json:"took"`
}

func PageFaults added in v0.3.0

func PageFaults(ctx context.Context) (*PageFaultsStat, error)

PageFaults returns page fault stats

type Performance added in v1.1.0

type Performance struct {
	CPUMemory
	IOCountersStat     *IOCountersStat     `json:"ioCountersStat"`
	ConnStat           *ConnectionsCount   `json:"connStat"`
	NumCtxSwitchesStat *NumCtxSwitchesStat `json:"numCtxSwitchesStat"`
	PageFaultsStat     *PageFaultsStat     `json:"pageFaultsStat"`
	NumFdsStat         *NumFdsStat         `json:"numFdsStat"`
	OpenFilesStats     *OpenFilesStat      `json:"openFilesStats"`
}

func GetPerformance added in v1.1.0

func GetPerformance(ctx context.Context) *Performance

GetPerformance 获取应用性能指标

func (*Performance) ToMap added in v1.1.0

func (perf *Performance) ToMap(prevPerf *Performance) map[string]interface{}

Jump to

Keyboard shortcuts

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