Categorygithub.com/bar-counter/monitor
modulepackage
1.3.0
Repository: https://github.com/bar-counter/monitor.git
Documentation: pkg.go.dev

# README

golang-full TravisBuildStatus GoDoc GoReportCard codecov

for what

  • this project used to gin api server status monitor

support check

  • health
  • Hardware
    • disk
    • cpu
    • ram
  • debug
    • run vars
    • pprof

dependInfo

liburlversion
ginhttps://github.com/gin-gonic/ginv1.6.3
gopsutilhttps://github.com/shirou/gopsutilv2.20.9+incompatible
go-olehttps://github.com/go-ole/go-olev1.2.5

demo

make init
make dep
# ensure right then
make dev
# and open url
# health http://127.0.0.1:38000/status/health
# pprof http://127.0.0.1:38000/debug/pprof/

use middleware lib

import

# go get
go get -v github.com/bar-counter/monitor

# go mod find out verison
go list -m -versions github.com/bar-counter/monitor
# all use awk to get script
echo "go mod edit -require=$(go list -m -versions github.com/bar-counter/monitor | awk '{print $1 "@" $NF}')"
# then use your want verison like v1.1.0
GO111MODULE=on go mod edit -require=github.com/bar-counter/[email protected]
GO111MODULE=on go mod vendor

# dep go 1.7 -> 1.11
dep ensure --add github.com/bar-counter/[email protected]
dep ensure -v

gin server status

import (
	"github.com/bar-counter/monitor"
)

	r := gin.Default()
	monitorCfg := &monitor.Cfg{
		Status: true,
		//StatusPrefix: "/status",
		StatusHardware: true,
		//StatusHardwarePrefix: "/hardware",
	}
	err := monitor.Register(r, monitorCfg)
	if err != nil {
		fmt.Printf("monitor register err %v\n", err)
		return
	}
	r.Run(":38000")

and you can use to get status of server

curl 'http://127.0.0.1:38000/status/health' \
  -X GET

curl 'http://127.0.0.1:38000/status/hardware/disk' \
  -X GET

curl 'http://127.0.0.1:38000/status/hardware/ram' \
  -X GET

curl 'http://127.0.0.1:38000/status/hardware/cpu' \
  -X GET

StatusPrefix default is /status you can change by your self StatusHardwarePrefix default is /hardware

gin server debug

vars

import (
	"github.com/bar-counter/monitor"
)

	r := gin.Default()
	monitorCfg := &monitor.Cfg{
		Debug: true,
		//DebugPrefix: "/debug",
		DebugMiddleware: gin.BasicAuth(gin.Accounts{
			"admin": "admin",
			"user":  "user",
		}),
	}
	err := monitor.Register(r, monitorCfg)
	if err != nil {
		fmt.Printf("monitor register err %v\n", err)
		return
	}
	r.Run(":38000")
curl 'http://127.0.0.1:38000/debug/vars' \
-X GET

DebugPrefix default is /debug

{
    "cgo": 6,
    "cmdline": [
        "/private/var/folders/3t/q6knzmrs09b0m5px2dljnpnr0000gn/T/___go_build_main_go__1_"
    ],
    "gc_pause": 0,
    "go_version": "go1.11.4",
    "goroutine": 3,
    "memstats": {
    },
    "os": "darwin",
    "os_cores": 8,
    "run_time": "8.211807521s"
}
itemdocdesc
cgogo doc runtime.NumCgoCall
cmdlineserver run cmd
coresgo doc runtime.NumCPU
gc_pausecount last gc time
goroutinego doc runtime.NumGoroutine
memstatsgo doc runtime.MemStats
osgo doc runtime.GOOS
os_coresgo doc runtime.NumCPU
run_timecount server run time

more info see go doc expvar

DebugMiddleware can use BasicAuth or other Middleware

pprof

import (
	"github.com/bar-counter/monitor"
)

	r := gin.Default()
	monitorCfg := &monitor.Cfg{
		Status: true,
		//StatusPrefix: "/status",
		StatusHardware: true,
		//StatusHardwarePrefix: "/hardware",
		Debug: true,
		//DebugPrefix: "/debug",
		DebugMiddleware: gin.BasicAuth(gin.Accounts{
			"admin": "admin",
			"user":  "user",
		}),
		PProf: true,
		//PProfPrefix: "/pprof",
	}
	err := monitor.Register(r, monitorCfg)
	if err != nil {
		fmt.Printf("monitor register err %v\n", err)
		return
	}
	r.Run(":38000")

then see at http://127.0.0.1:38000/debug/pprof/ or use cli to

# cpu
go tool pprof http://localhost:38000/debug/pprof/profile
# mem
go tool pprof http://localhost:38000/debug/pprof/heap
# block
go tool pprof http://localhost:38000/debug/pprof/block

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author
DefaultPrefix url prefix of /debug/pprof.
DefaultVarsPrefix url prefix of /status/hardware.
No description provided by the author
DefaultVarsPrefix url prefix of /debug/vars.

# Variables

No description provided by the author

# Structs

No description provided by the author