Skip to content

AaronJan/echo-contrib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echo Contribution

Forked from labstack/echo-contrib.

GoDoc License

Packages

prometheus

Original author: carlosedp

Embed Prometheus into an Existent Echo Instance

import "github.com/labstack/echo/v4"
import "github.com/aaronjan/echo-contrib/prometheus"

func urlSkipper(c echo.Context) bool {
    if strings.HasPrefix(c.Path(), "/health-check") {
        return true
    }
    return false
}

func main() {
    e := echo.New()

    additionMetrics := []*prometheus.Metric{&prometheus.Metric{
        ID:   "helloCnt",
        Name: "hellos_total",
        Description: "How many times this app says hello to users.",
        Type: "summary",
    }}

    p := prometheus.NewPrometheusWithConfig(prometheus.Config{
        MetricsPath: "/metrics",
        Subsystem: "echo",
        Skipper: urlSkipper,
        AdditionMetrics: additionMetrics,
    })
    p.Embed(e)

    e.Start()
}

Start Prometheus in a Separate Echo Instance

import "context"
import "github.com/labstack/echo/v4"
import "github.com/aaronjan/echo-contrib/prometheus"

func urlSkipper(c echo.Context) bool {
    if strings.HasPrefix(c.Path(), "/health-check") {
        return true
    }
    return false
}

func main() {
    e := echo.New()

    additionMetrics := []*prometheus.Metric{&prometheus.Metric{
        ID:   "helloCnt",
        Name: "hellos_total",
        Description: "How many times this app says hello to users.",
        Type: "summary",
    }}

    p := prometheus.NewPrometheusWithConfig(prometheus.Config{
        MetricsPath: "/metrics",
        Subsystem: "echo",
        Skipper: urlSkipper,
        AdditionMetrics: additionMetrics,
    })
    p.Mount(e)

    pe := echo.New()
    go p.Start(pe, ":1323")
    // To stop: pe.Shutdown()

    e.Start()
}

About

Echo community contribution

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.2%
  • Makefile 1.8%