Skip to content

Instantly share code, notes, and snippets.

@chris530
Created July 23, 2019 20:22
Show Gist options
  • Save chris530/11c711d663d2978bf83ab1ab955547a7 to your computer and use it in GitHub Desktop.
Save chris530/11c711d663d2978bf83ab1ab955547a7 to your computer and use it in GitHub Desktop.
Simple prometheus server
package main
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func recordMetrics() {
go func() {
for {
opsProcessed.Inc()
time.Sleep(2 * time.Second)
}
}()
}
var (
opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "myapp_processed_ops_total",
Help: "The total number of processed events",
})
)
func main() {
recordMetrics()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment