stats_api

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2016 License: Apache-2.0 Imports: 7 Imported by: 87

README

golang-stats-api-handler

Golang cpu, memory, gc, etc information api handler.

Install

go get github.com/fukata/golang-stats-api-handler

Example

import (
    "net/http"
    "log"
    "github.com/fukata/golang-stats-api-handler"
)
func main() {
    http.HandleFunc("/api/stats", stats_api.Handler)
    log.Fatal( http.ListenAndServe(":8080", nil) )
}

Response

$ curl -i http://localhost:8080/api/stats/
HTTP/1.1 200 OK
Content-Length: 712
Content-Type: application/json
Date: Sun, 23 Aug 2015 16:52:13 GMT

{
    "time": 1440348733548339479,
    "go_version": "go1.5",
    "go_os": "darwin",
    "go_arch": "amd64",
    "cpu_num": 8,
    "goroutine_num": 24,
    "gomaxprocs": 8,
    "cgo_call_num": 9,
    "memory_alloc": 3974536,
    "memory_total_alloc": 12857888,
    "memory_sys": 12871928,
    "memory_lookups": 52,
    "memory_mallocs": 144922,
    "memory_frees": 118936,
    "memory_stack": 688128,
    "heap_alloc": 3974536,
    "heap_sys": 8028160,
    "heap_idle": 2170880,
    "heap_inuse": 5857280,
    "heap_released": 0,
    "heap_objects": 25986,
    "gc_next": 4833706,
    "gc_last": 1440348732827834419,
    "gc_num": 4,
    "gc_per_second": 0,
    "gc_pause_per_second": 0,
    "gc_pause": [
        0.196828,
        2.027442,
        0.181887,
        0.312866
    ]
}
Key Value
time unix timestamp as nano-seconds
go_version runtime.Version()
go_os runtime.GOOS
go_arch runtime.GOARCH
cpu_num number of CPUs
goroutine_num number of goroutines
gomaxprocs runtime.GOMAXRPOCS(0)
cgo_call_num runtime.NumCgoCall()
memory_alloc bytes allocated and not yet freed
memory_total_alloc bytes allocated (even if freed)
memory_sys bytes obtained from system
memory_lookups number of pointer lookups
memory_mallocs number of mallocs
memory_frees number of frees
memory_stack bytes used by stack allocator
heap_alloc bytes allocated and not yet freed (same as memory_alloc above)
heap_sys bytes obtained from system (not same as memory_sys)
heap_idle bytes in idle spans
heap_inuse bytes in non-idle span
heap_released bytes released to the OS
heap_objects total number of allocated objects
gc_next next collection will happen when HeapAlloc ≥ this amount
gc_last end time of last collection
gc_num number of GC-run
gc_per_second number of GC-run per second
gc_pause_per_second pause duration by GC per seconds
gc_pause pause durations by GC

Plugins

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(w http.ResponseWriter, r *http.Request)

Handler returns activity status of Go.

func NewLineTermDisabled

func NewLineTermDisabled()

NewLineTermDisabled disable termination with newline for response body.

func NewLineTermEnabled

func NewLineTermEnabled()

NewLineTermEnabled enable termination with newline for response body.

func PrettyPrintDisabled

func PrettyPrintDisabled()

PrettyPrintDisabled disable pritty-print for response body.

func PrettyPrintEnabled

func PrettyPrintEnabled()

PrettyPrintEnabled enable pretty-print for response body.

Types

type Stats

type Stats struct {
	Time int64 `json:"time"`
	// runtime
	GoVersion    string `json:"go_version"`
	GoOs         string `json:"go_os"`
	GoArch       string `json:"go_arch"`
	CpuNum       int    `json:"cpu_num"`
	GoroutineNum int    `json:"goroutine_num"`
	Gomaxprocs   int    `json:"gomaxprocs"`
	CgoCallNum   int64  `json:"cgo_call_num"`
	// memory
	MemoryAlloc      uint64 `json:"memory_alloc"`
	MemoryTotalAlloc uint64 `json:"memory_total_alloc"`
	MemorySys        uint64 `json:"memory_sys"`
	MemoryLookups    uint64 `json:"memory_lookups"`
	MemoryMallocs    uint64 `json:"memory_mallocs"`
	MemoryFrees      uint64 `json:"memory_frees"`
	// stack
	StackInUse uint64 `json:"memory_stack"`
	// heap
	HeapAlloc    uint64 `json:"heap_alloc"`
	HeapSys      uint64 `json:"heap_sys"`
	HeapIdle     uint64 `json:"heap_idle"`
	HeapInuse    uint64 `json:"heap_inuse"`
	HeapReleased uint64 `json:"heap_released"`
	HeapObjects  uint64 `json:"heap_objects"`
	// garbage collection
	GcNext           uint64    `json:"gc_next"`
	GcLast           uint64    `json:"gc_last"`
	GcNum            uint32    `json:"gc_num"`
	GcPerSecond      float64   `json:"gc_per_second"`
	GcPausePerSecond float64   `json:"gc_pause_per_second"`
	GcPause          []float64 `json:"gc_pause"`
}

Stats represents activity status of Go.

func GetStats

func GetStats() *Stats

Jump to

Keyboard shortcuts

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