gosh: github.com/osamingo/gosh Index | Examples | Files

package gosh

import "github.com/osamingo/gosh"

Index

Examples

Package Files

gosh.go

func NewStatisticsHandler Uses

func NewStatisticsHandler() http.Handler

NewStatisticsHandler returns new StatisticsHandler.

Code:

const path = "/healthz"

mux := http.NewServeMux()
mux.Handle(path, gosh.NewStatisticsHandler())

srv := httptest.NewServer(mux)
defer srv.Close()

resp, err := http.Get(srv.URL + path)
if err != nil {
    log.Fatalln(err)
}
defer func() {
    if err := resp.Body.Close(); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}()

if resp.StatusCode != http.StatusOK {
    fmt.Println("unexpect status code:", resp.StatusCode)
    os.Exit(1)
}

var s gosh.Statistics
if err := json.NewDecoder(resp.Body).Decode(&s); err != nil {
    fmt.Println(err)
    os.Exit(1)
}

fmt.Printf("status_code: %d, has_gorutine: %t", resp.StatusCode, s.GoroutineNum > 0)

Output:

status_code: 200, has_gorutine: true

type Statistics Uses

type Statistics struct {
    Timestamp        int64     `json:"timestamp"`
    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"`
    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"`
    StackInuse       uint64    `json:"stack_inuse"`
    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"`
    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"`
}

A Statistics has runtime information.

type StatisticsHandler Uses

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

A StatisticsHandler provides runtime information handler.

func (*StatisticsHandler) MeasureRuntime Uses

func (sh *StatisticsHandler) MeasureRuntime() Statistics

MeasureRuntime accesses runtime information.

func (*StatisticsHandler) ServeHTTP Uses

func (sh *StatisticsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)

ServeHTTP implements http.Handler interface.

Package gosh imports 5 packages (graph). Updated 2019-09-11. Refresh now. Tools for package owners.