Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStatisticsHandler ¶
NewStatisticsHandler returns new StatisticsHandler.
Example ¶
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httptest"
"os"
"github.com/osamingo/gosh"
)
func main() {
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
Types ¶
type Statistics ¶
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 ¶
type StatisticsHandler struct {
// contains filtered or unexported fields
}
A StatisticsHandler provides runtime information handler.
func (*StatisticsHandler) MeasureRuntime ¶
func (sh *StatisticsHandler) MeasureRuntime() Statistics
MeasureRuntime accesses runtime information.
func (*StatisticsHandler) ServeHTTP ¶
func (sh *StatisticsHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)
ServeHTTP implements http.Handler interface.
Click to show internal directories.
Click to hide internal directories.