Skip to content

trafficstars/statuspage

Repository files navigation

Build Status go report GoDoc GoDoc (for framework "echo")

Description

The package allows to easily export application metrics (github.com/trafficstars/metrics) to prometheus.

Examples

Generic case

package main

import (
    "fmt"
    "math/rand"
    "net/http"

    "github.com/trafficstars/metrics"
    "github.com/trafficstars/statuspage"
)

func hello(w http.ResponseWriter, r *http.Request) {
    answerInt := rand.Intn(10)
        
    // just a metric
    metrics.Count(`hello`, metrics.Tags{`answer_int`: answerInt}).Increment()
        
    fmt.Fprintf(w, "Hello world! The answerInt == %v\n", answerInt)
}

func sendMetrics(w http.ResponseWriter, r *http.Request) {
    statuspage.WriteMetricsPrometheus(w)
}

func main() {
    http.HandleFunc("/", hello)
    http.HandleFunc("/metrics.prometheus", sendMetrics) // here we export metrics for prometheus
    http.ListenAndServe(":8000", nil)
}
$ curl http://localhost:8000/
Hello world! The answerInt == 1

$ curl http://localhost:8000/
Hello world! The answerInt == 7

$ curl http://localhost:8000/
Hello world! The answerInt == 7

$ curl -s http://localhost:8000/metrics.prometheus | grep hello
# TYPE metrics_hello counter
metrics_hello{answer_int="1"} 1
metrics_hello{answer_int="7"} 2

Framework "echo"

The same as above, but just use our handler:

// import "github.com/trafficstars/statuspage/handler/echostatuspage"

r := echo.New()
r.GET("/status.prometheus", echostatuspage.StatusPrometheus)

About

Easily export application metrics (github.com/trafficstars/metrics) to prometheus

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages