Skip to content

Commit

Permalink
cleaned up async
Browse files Browse the repository at this point in the history
Signed-off-by: metonymic-smokey <[email protected]>
  • Loading branch information
metonymic-smokey committed Sep 21, 2021
1 parent fe332ad commit e7216ea
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"time"

"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -24,7 +23,7 @@ func recordMetrics() {
}

for _, interval := range dat.Data.Timestep[0].TempVal {
jobsInQueue.Set(interval.Values.Temp)
tempCelsius.Set(interval.Values.Temp)
}

opsProcessed.Inc()
Expand All @@ -34,41 +33,21 @@ func recordMetrics() {

var opsProcessed = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "myapp_processed_ops_total",
Help: "The total number of processed events",
Name: "processed_ops_total",
Help: "The total number of processed operations",
},
)

var jobsInQueue = promauto.NewGauge(
var tempCelsius = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "current_temperature_api_celsius",
Help: "Current temperature",
},
)

var httpDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "http_response_time_seconds",
Help: "Duration of HTTP requests.",
}, []string{"path"})

func prometheusMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
route := mux.CurrentRoute(r)
path, _ := route.GetPathTemplate()

timer := prometheus.NewTimer(httpDuration.WithLabelValues(path))

timer.ObserveDuration()
})
}

func main() {
go recordMetrics()

router := mux.NewRouter()
router.Use(prometheusMiddleware)

//http.Handle("/metrics", promhttp.Handler())
router.Path("/metrics").Handler(promhttp.Handler())
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil)
}

0 comments on commit e7216ea

Please sign in to comment.