epimetheus

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 11 Imported by: 0

README

Epimetheus

Mnemosyne

Epimetheus is a lightweight wrpper around Prometheus Go client and Statsd Go client which makes measuring communication, functions, background jobs, etc. easier, simultaneously with both Prometheus and Statsd.

Getting Started

Installing
go get -u github.com/cafebazaar/epimetheus
Initialize server
epimetheusServer := epimetheus.NewEpimetheusServer(config)
go epimetheusServer.Listen()

Predefined metrics
epi := epimetheus.NewEpimetheus(config)
commTimer := epi.CommTimer
go epimetheusServer.Listen()
Measuring duration and count
epi := epimetheus.NewEpimetheus(config)
timerWithCounter := epi.NewTimerWithCounter("req1", string[]{"label1"})
rtc := timerWithCounter.Start()
// Do some work here
rtc.Done("dispatch")
Measuring duration
epi := epimetheus.NewEpimetheus(config)
timer := epi.NewTimer("req1", string[]{"label1"})
t := timer.Start()
// Do some work here
t.Done("dispatch")
Measuring count
epi := epimetheus.NewEpimetheus(config)
counter := epi.NewCounter("req1", string[]{"label1"})
// Do some work here
c.Inc("dispatch")

Configuration

Epimetheus uses Viper as it's config engine. Template should be something like this:

    stats:
      prometheus:
        enabled: true
        port: 1234
      statsd:
        enabled: true
        port: 5678
        host: "w.x.y.z"
      namespace: search
      system-name: octopus

Documentation

Documents are available at https://godoc.org/github.com/cafebazaar/epimetheus

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Roadmap

- Improve documentation
- Add tests

Authors

  • Ramtin Rostami - Initial work - rrostami
  • Pedram Teymoori - Initial work - pedramteymoori
  • Parsa abdollahi - Initial work -

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Made with in Cafebazaar search

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter keeps the contents of underlying counter, including labels

func (*Counter) Inc

func (w *Counter) Inc(labelValues ...string)

Inc increments the value of current Counter

type Epimetheus

type Epimetheus struct {
	CommTimer     *TimerWithCounter
	FunctionTimer *TimerWithCounter
	CacheRate     *Counter
	BGWorker      *Counter
	// contains filtered or unexported fields
}

Epimetheus is the main struct of this library

You should have exactly one instance of it with `NewEpimetheusServer`, and then call `listen()` method of it

  • config: Instance of viper
  • CommTimer: An instance of `TimerWithCounter` which is used for your application communications
  • FunctionTimer: An instance of `TimerWithCounter` which is used for your application important functions
  • CacheRate: An instance of `Counter` which is used in conjunction with `Mnemosyne` project for caching
  • BGWorker: An instance of `Counter` which is used for your application background workers

func NewEpimetheus

func NewEpimetheus(config *viper.Viper) *Epimetheus

NewEpimetheus Creates a new instance of `Epimetheus` with prepared metrics in advance

func NewEpimetheusServer

func NewEpimetheusServer(config *viper.Viper) *Epimetheus

NewEpimetheusServer Creates a new instance of `Epimetheus` without prepared metrics in advance

func (*Epimetheus) Listen

func (e *Epimetheus) Listen() *Server

Listen makes epimetheus start on specified port if enabled, then return the server in order to stop later

func (*Epimetheus) NewCounter

func (e *Epimetheus) NewCounter(name string, labelNames []string) *Counter

NewCounter creates an instance of `Counter` with specified configs

func (*Epimetheus) NewGauge

func (e *Epimetheus) NewGauge(name string, labelNames []string) *Gauge

NewGauge creates an instance of `Gauge` with specified configs

func (*Epimetheus) NewTimer

func (e *Epimetheus) NewTimer(name string, labelNames []string) *Timer

NewTimer creates an instance of `Timer` with specified configs

func (*Epimetheus) NewTimerWithCounter

func (e *Epimetheus) NewTimerWithCounter(name string, labelNames []string) *TimerWithCounter

NewTimerWithCounter creates an instance of `TimerWithCounter` with specified configs

type Gauge

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

Gauge keeps the contents of underlying gauge, including labels

func (*Gauge) Set

func (w *Gauge) Set(value float64, labelValues ...string)

Set sets value of the gauge

type Server

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

Server contains http server of Epimetheus instance

func (*Server) Stop

func (s *Server) Stop(server *http.Server) error

Stop stops the server and returns it's error if exists

type StaticCounter

type StaticCounter struct {
	Base *Counter
	// contains filtered or unexported fields
}

StaticCounter keeps the contents of underlying counter, excluding labels

func (*StaticCounter) Inc

func (sc *StaticCounter) Inc()

Inc increments the value of current Counter

type StaticGauge

type StaticGauge struct {
	Base *Gauge
	// contains filtered or unexported fields
}

StaticGauge keeps the contents of underlying gauge, excluding labels

func (*StaticGauge) Set

func (rg *StaticGauge) Set(value float64)

Set sets value of the gauge

type Timer

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

Timer keeps the contents of underlying timer, including labels

func (*Timer) Done

func (t *Timer) Done(start time.Time, labelValues ...string)

Done finalize the current RunningTimer

func (*Timer) RunVoid

func (t *Timer) RunVoid(work func(), labelValues ...string)

RunVoid gets a void function and lables and run it with measurment

func (*Timer) RunWithError

func (t *Timer) RunWithError(work func() error, labelValues ...string) error

RunWithError gets a function with error and lables and run it with measurment

func (*Timer) Start

func (w *Timer) Start() time.Time

Start begins a RunningTimer and then returns it

type TimerWithCounter

type TimerWithCounter struct {
	*Timer
	*Counter
}

TimerWithCounter consists of a Timer and a Counter in order to measure count and duration simultaneously

func (*TimerWithCounter) Done

func (tc *TimerWithCounter) Done(start time.Time, labelValues ...string)

Done marks the related timer as done and increments the related counter too

func (*TimerWithCounter) Start

func (tc *TimerWithCounter) Start() time.Time

Start creates an instance of `RunningTimerWithCounter` and returns it

Jump to

Keyboard shortcuts

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