reporter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 9 Imported by: 0

README

reporter

Package reporter exposes runtime/metrics over HTTP in a format that gcscope attach can consume.

Use it when you want to connect gcscope to an already running service (attach mode). In contrast, gcscope run does not require any code changes in your application.

Default endpoint: GET /gcscope/metrics.

Quickstart

rep.Path() returns the URL path to mount the endpoint (default: /gcscope/metrics).

rep.Handler() returns an http.Handler that serves a JSON payload with runtime/metrics samples.

net/http

If you already have an HTTP server, register the handler in your http.ServeMux:

package main

import (
	"log"
	"net/http"

	"github.com/timur-developer/gcscope/pkg/reporter"
)

func main() {
	rep := reporter.New()

	mux := http.NewServeMux()
	
	mux.Handle(rep.Path(), rep.Handler())

	log.Fatal(http.ListenAndServe(":8080", mux))
}

Attach:

gcscope attach http://127.0.0.1:8080/gcscope/metrics
chi

The same handler can be mounted into chi router:

package main

import (
	"log"
	"net/http"

	"github.com/go-chi/chi/v5"

	"github.com/timur-developer/gcscope/pkg/reporter"
)

func main() {
	rep := reporter.New()

	r := chi.NewRouter()
	
	r.Handle(rep.Path(), rep.Handler())

	log.Fatal(http.ListenAndServe(":8080", r))
}

Custom Path

rep := reporter.New(reporter.WithPath("/debug/gcscope/metrics"))

Documentation

Index

Constants

View Source
const DefaultPath = "/gcscope/metrics"

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Reporter)

func WithPath

func WithPath(path string) Option

type Reporter

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

func New

func New(opts ...Option) *Reporter

func (*Reporter) Handler

func (r *Reporter) Handler() http.Handler

func (*Reporter) Path

func (r *Reporter) Path() string

func (*Reporter) Start

func (r *Reporter) Start(addr string) error

Start starts an HTTP server on addr (for example ":8080") and serves the metrics endpoint. If you already have an HTTP server, prefer Handler() and register it into your mux.

func (*Reporter) Stop

func (r *Reporter) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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