-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (32 loc) · 886 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"net/http"
"time"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// Version populates in compile time
var Version string
var reqCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "epoch_request_count",
Help: "No of request handled by the handler",
},
)
func sendEpoch(w http.ResponseWriter, r *http.Request) {
epoch := time.Now().UTC().Unix()
hostname, err := os.Hostname()
if err != nil {
fmt.Println(err)
}
reqCounter.Inc()
fmt.Fprintf(w, "{\"host\": \"%s\", \"type\": \"epoch\", \"data\": %d, \"unit\": \"sec\", \"rev\": %q}", hostname, epoch, Version)
}
func main() {
prometheus.MustRegister(reqCounter)
http.HandleFunc("/", sendEpoch)
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8080", nil)
}