Skip to content

ppwfx/pprofrec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go Report Card

pprofrec

Provides a single pane of glass across all runtime metrics. pprofrec records pprof lookups, runtime.MemStats and gopsutil metrics, and exposes them via http endpoints to inspect and troubleshoot an application in an idiomatic, fast and boring way.

Demo

  • Scroll on the x-axis to see more features and on the y-axis to see more data points.

usage

Record runtime metrics at a given frequency within a given window.

windowOpts := pprofrec.WindowOpts{
    Window:    120 * time.Second,
    Frequency: 1 * time.Second,
}
mux.HandleFunc("/debug/pprof/window", pprofrec.Window(ctx, windowOpts))

Stream runtime metrics at a given frequency.

streamOpts := pprofrec.StreamOpts{
    Frequency: 500 * time.Millisecond,
}
mux.HandleFunc("/debug/pprof/stream", pprofrec.Stream(streamOpts))

Full example

package main

import (
	"context"
	"log"
	"net/http"
	"time"

	"github.com/ppwfx/pprofrec"
)

func main() {
	mux := http.NewServeMux()

	ctx := context.Background()

	windowOpts := pprofrec.WindowOpts{
		Window:    120 * time.Second,
		Frequency: 1 * time.Second,
	}
	mux.HandleFunc("/debug/pprof/window", pprofrec.Window(ctx, windowOpts))

	streamOpts := pprofrec.StreamOpts{
		Frequency: 500 * time.Millisecond,
	}
	mux.HandleFunc("/debug/pprof/stream", pprofrec.Stream(streamOpts))

	srv := &http.Server{
		Addr:         ":8080",
		WriteTimeout: 15 * time.Minute,
		Handler:      mux,
	}

	log.Printf("listens on: %v", srv.Addr)

	err := srv.ListenAndServe()
	if err != nil {
		log.Fatalf("failed to listen: %v", err)

		return
	}
}

About

Provides a single pane of glass across all runtime metrics to help understand the runtime behavior of a golang application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages