pprofrec

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 13 Imported by: 0

README

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
	}
}

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stream

func Stream(opts StreamOpts) func(w http.ResponseWriter, r *http.Request)

Stream streams runtime metrics at a given frequency as a html table.

func Window

func Window(ctx context.Context, opts WindowOpts) func(w http.ResponseWriter, r *http.Request)

Window records runtime metrics at a given frequency within a given window and responds with a html table that lists the recorded metrics.

Types

type StreamOpts

type StreamOpts struct {
	// Frequency defines at what frequency metrics are recorded and streamed.
	Frequency time.Duration
}

StreamOpts configures the Stream handler.

type WindowOpts

type WindowOpts struct {
	// Window defines a window within metrics are stored.
	Window time.Duration
	// Frequency defines at what frequency metrics are recorded.
	Frequency time.Duration
}

WindowOpts configures the Window handler.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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