stats

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 1 Imported by: 0

README

stats

Stats provides usecase for scoring your app metrics

How to Use

stats.Stats defines standard stats interface.

type service struct {
  stats stats.Stats
}

func (s *service) DoSomething() {
  // something happened
  if err != nil {
    s.stats.Increment("something_failed", stats.Option{
      Tags: stats.Tags{"method": "DoSomething"}
    })
  }
}

You can inject stats implementor.


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

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
}

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

func MergeTags

func MergeTags(t1, t2 Tags) 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