stats

package module
v0.0.0-...-65f813a Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: MIT Imports: 4 Imported by: 0

README

go-stats

Simple Go package for collecting runtime statistics with optional plugins.

Installation

go get github.com/alexraskin/go-stats

Usage

package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	"github.com/alexraskin/go-stats"
)

func main() {
	http.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
		stats, err := stats.NewStats()
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		json.NewEncoder(w).Encode(stats)
	})

	fmt.Println("Server started at :8080")
	http.ListenAndServe(":8080", nil)
}

Plugins

The go-stats package supports optional plugins. To create a plugin, implement the stats.Plugin interface:

package myplugin

import "github.com/alexraskin/go-stats"

type MyPlugin struct{}

func (p *MyPlugin) Name() string {
	return "myplugin"
}

func (p *MyPlugin) Metrics() (map[string]any, error) {
	return map[string]any{
		"metric1": 100,
		"metric2": 200,
	}, nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStats

func NewStats(plugins ...Plugin) (map[string]any, error)

Types

type Plugin

type Plugin interface {
	Name() string
	Metrics() (map[string]any, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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