metrics

package module
v0.0.0-...-1888415 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 7 Imported by: 2

README

Go metrics

library to capture go service metrics, abstracting protocol (http, gRPC) and details of timeseries db.

Go Report Card

Prometheus Setup

Expose prometheus /metrics endpoint in 9101 port

obs, err := metrics.Setup(
	    metrics.WithAddress(":9101"),
        metrics.WithServiceName("service-name")
    )
m := mux.NewRouter()
m.Use(mux.MiddlewareFunc(obs.Middleware))

# add required handlers ... 
err = http.ListenAndServe(addr, m)

Statsd / Influx Setup

Follow the instructions to send metrics to statsd server running at 8125 port, which is configured to publish to influxdb

	obs, err := metrics.Setup(
		metrics.WithAddress("localhost:8125"),
		metrics.WithServiceName(appCfg.Metrics.ServiceID),
		metrics.WithKind(common.Statsd),
	)

Metrics

http_latency_ms

  • captures latency of each request in milliseconds with tags service, method, path, status
  • In prometheus configured as Histogram and follow the instructions for more details on visulaization

http_requests

captures request status and count with tags service, method, path, status

  • In prometheus configured as Gauge

Visualization

Once integrated you can configure grafana to read from prometheus/influxdb datasource and create a dashboard to monitor your service.

service dashboard

Architecture

In order to decide which means to use, you've to be aware of Pull vs Poll architecture and what fits your need based on ecosystem.

pull vs poll

In k8s ecosystem prometheus is a standard and in vm ecosystem influx is used widely.

TODO

We'll support prometheus, influxdb and add open-telemetry for db transactions

  • Prometheus
  • Pprof
  • Statsd
  • Influx API
  • open-telemetry
  • gRPC interceptor
  • sql spans tracing

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &common.Config{
	Address:   ":9100",
	ServiceID: "go-service",
	Kind:      common.Prometheus,
}

Functions

This section is empty.

Types

type Observer

type Observer struct {
	common.Config
	// contains filtered or unexported fields
}

func Setup

func Setup(opts ...Option) (Observer, error)

func (Observer) Middleware

func (o Observer) Middleware(next http.Handler) http.Handler

type Option

type Option func(c *common.Config)

func WithAddress

func WithAddress(addr string) Option

func WithKind

func WithKind(kind common.Kind) Option

func WithPprof

func WithPprof() Option

func WithServiceName

func WithServiceName(s string) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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