goprometheus

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 6 Imported by: 1

README

GoPrometheus

GoPrometheus, GoGin and GoHystrix metrics exporter for Prometheus

Installation

go get github.com/gunerhuseyin/goprometheus

Usage

Import packages

import(
	"github.com/gunerhuseyin/goprometheus"
	ginmiddleware "github.com/gunerhuseyin/goprometheus/middleware/gin"
	hystrixmiddleware "github.com/gunerhuseyin/goprometheus/middleware/hystrix"
)

Create new GoPrometheus and GoGin

    r := gin.Default()
    gpm := goprometheus.New()

Configure gin middleware

	gpGinConfig := &ginmiddleware.Config{
		Engine:              r,  //Gin engine
		TimeFormat:          "2006-01-02T15:04:05",
		MetricName:          "gin_requests_duration",
		DurationType:        "ms",
		EnableRequestHeader: false,
		EnableRequestBody:   false,
		IgnorePaths: map[string]bool{
			"/metrics": true,
			"/ping":    true,
		},
	}

    gpGin := ginmiddleware.New(gpm, gpGinConfig)

Configure hystrix middleware

	gpHystrixConfig := &hystrixmiddleware.Config{
		Prefix: "hystrix_circuit_breaker_",
	}

	gpHystrix := hystrixmiddleware.New(gpm, gpHystrixConfig)

Use and run GoPrometheus

	gpm.UseGin(gpGin)
	gpm.UseHystrix(gpHystrix)
	gpm.Run()

Start http server

	http.Handle("/", r)	
    _ = http.ListenAndServe(":8080", nil)

Result

Metrics export to :8080/metrics

Sample gin metrics

gin_requests_duration_sum{code="200",handler="main.main.func3",host="localhost:8080",method="GET",node="gopoc-deployment-5597c7fdc4-npwzz",time="2019-07-02T12:16:06",url="/test2"} 55.95169900000001
gin_requests_duration_count{code="200",handler="main.main.func3",host="localhost:8080",method="GET",node="gopoc-deployment-5597c7fdc4-npwzz",time="2019-07-02T12:16:06",url="/test2"} 34

34 requests in one second, and a total of 55,95169900000001 ms. Average response time 1,6456382059 ms

Sample hystrix metrics

hystrix_circuit_breaker_attempts{name="test"} 100
hystrix_circuit_breaker_concurrency_in_use{name="test"} 0
hystrix_circuit_breaker_context_deadline_exceeded{name="test"} 0
hystrix_circuit_breaker_errors{name="test"} 100
hystrix_circuit_breaker_failures{name="test"} 50
hystrix_circuit_breaker_fallback_failures{name="test"} 100
hystrix_circuit_breaker_fallback_successes{name="test"} 0
hystrix_circuit_breaker_rejects{name="test"} 0
hystrix_circuit_breaker_run_duration{name="test"} 186636
hystrix_circuit_breaker_short_circuits{name="test"} 50
hystrix_circuit_breaker_successes{name="test"} 0
hystrix_circuit_breaker_timeouts{name="test"} 0
hystrix_circuit_breaker_total_duration{name="test"} 209263

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CounterVector

type CounterVector struct {
	Vector *p.CounterVec
	Labels []string
}

func (*CounterVector) AddMetric

func (v *CounterVector) AddMetric(value float64, labelValues ...string)

type GaugeVector

type GaugeVector struct {
	Vector *p.GaugeVec
	Labels []string
}

func (*GaugeVector) AddMetric

func (v *GaugeVector) AddMetric(value float64, labelValues ...string)

type GoPrometheus

type GoPrometheus struct {
	Vectors *Vectors
	// contains filtered or unexported fields
}

func New

func New() *GoPrometheus

func (*GoPrometheus) AddCounterVector

func (gp *GoPrometheus) AddCounterVector(name, desc string, labels []string)

func (*GoPrometheus) AddGaugeVector

func (gp *GoPrometheus) AddGaugeVector(name, desc string, labels []string)

func (*GoPrometheus) AddHistogramVector

func (gp *GoPrometheus) AddHistogramVector(name, desc string, labels []string)

func (*GoPrometheus) AddSummaryVector

func (gp *GoPrometheus) AddSummaryVector(name, desc string, labels []string)

func (*GoPrometheus) Run

func (gp *GoPrometheus) Run()

func (*GoPrometheus) UseGin

func (gp *GoPrometheus) UseGin(gin IGinPrometheus)

func (*GoPrometheus) UseHystrix

func (gp *GoPrometheus) UseHystrix(hystrix IHystrixPrometheus)

type HistogramVector

type HistogramVector struct {
	Vector *p.HistogramVec
	Labels []string
}

func (*HistogramVector) AddMetric

func (v *HistogramVector) AddMetric(value float64, labelValues ...string)

type IGinPrometheus

type IGinPrometheus interface {
	Middleware(c *gin.Context)
	GetEngine() *gin.Engine
}

type IGoPrometheus

type IGoPrometheus interface {
	AddSummaryVector(name, desc string, labels []string)
	AddCounterVector(name, desc string, labels []string)
	AddGaugeVector(name, desc string, labels []string)
	AddHistogramVector(name, desc string, labels []string)
}

type IHystrixPrometheus

type IHystrixPrometheus interface {
	Middleware(name string) metricCollector.MetricCollector
}

type SummaryVector

type SummaryVector struct {
	Vector *p.SummaryVec
	Labels []string
}

func (*SummaryVector) AddMetric

func (v *SummaryVector) AddMetric(value float64, labelValues ...string)

type Vectors

type Vectors struct {
	SummaryVectors   map[string]*SummaryVector
	CounterVectors   map[string]*CounterVector
	GaugeVectors     map[string]*GaugeVector
	HistogramVectors map[string]*HistogramVector
}

Directories

Path Synopsis
middleware
gin

Jump to

Keyboard shortcuts

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