stats

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 1 Imported by: 0

README

stats

stats provides usecase for scoring your app metrics, commonly used for monitoring or capturing your business metric.

How to Use

stats.Stats defines standard stats interface.

type service struct {
  stats stats.Stats
}

func (s *service) DoSomething() {
  // something happened
  if err != nil {
    // Increment your failed metric count, used for monitoring or alerting
    s.stats.Increment("something_failed", stats.Option{
      Tags: stats.Tags{"method": "DoSomething"}
    })
  }
}

You can inject stats implementor using provided adapter.


import (
  gogox_prom "github.com/raymondwongso/gogox/stats/prometheus"
)

func main() {
  // e.g: prometheus stats, you can add base tags for your stats.
  prom := gogox_prom.New("mynamespace", stats.Tags{"service":"gogox_service"})

  service := service.NewService(prom)
}

Currently supported adapter:

  1. Prometheus
  2. Datadog (Will be in 1.x release)
  3. Nop

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	Rate float64
	Tags Tags
}

Option defines stats configuration

type Stats

type Stats interface {
	// Increment increase metric by 1
	Increment(metric string, opt Option) error
	// Histogram samples observations and counts them in configurable buckets
	Histogram(metric string, value float64, opt Option) error
	// Gauge represents a single numerical value
	Gauge(metric string, value float64, opt Option) error
	// Add increase metric by value
	Add(metric string, value float64, opt Option) error
}

Stats defines commonly used stats usecases.

type Tags

type Tags map[string]string

Tags defines key value mapping commonly used to give tags for metrices

func MergeTags

func MergeTags(t1, t2 Tags) Tags

MergeTags merge two tags

Directories

Path Synopsis
Package statsmock is a generated GoMock package.
Package statsmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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