Skip to content

Commit

Permalink
Make the http query and set the pool price on each call
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinmartian committed Jan 15, 2024
1 parent 3ab6ca7 commit 34cbf77
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions poolprice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func getCurrentPoolPrice() {
if ok && len(poolPrice) > 0 {
lastPrice, ok := poolPrice[len(poolPrice)-1].([]interface{})
if ok && len(lastPrice) > 1 {
poolpriceMetric.Set(lastPrice[1].(float64))
price := lastPrice[1].(float64)
poolpriceMetric.Set(price)
fmt.Println("Set the pool price: ", price)
} else {
fmt.Println("Error setting pool price", poolPrice)
}
Expand All @@ -70,19 +72,16 @@ func getCurrentPoolPrice() {
}
}

func main() {
// Start the HTTP server for Prometheus scraping
go func() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))
}()

// Collect and expose the poolprice metric
func metricsHandler(w http.ResponseWriter, r *http.Request) {
// Trigger the HTTP query and metric update
getCurrentPoolPrice()

// Do something with poolpriceStats if needed
fmt.Println(poolpriceMetric)
// Serve the metrics endpoint
promhttp.Handler().ServeHTTP(w, r)
}

// Keep the program running to expose the metric
select {}
func main() {
// Start the HTTP server for Prometheus scraping
http.HandleFunc("/metrics", metricsHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit 34cbf77

Please sign in to comment.