Skip to content
Snippets Groups Projects
Commit 7cc5e3185411 authored by Alexander Trost's avatar Alexander Trost
Browse files

Added prometheus metrics support

parent a6aca39a6794
No related branches found
No related tags found
No related merge requests found
package main package main
import ( import (
"flag"
"net/http" "net/http"
"os" "os"
"time" "time"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
...@@ -4,10 +5,11 @@ ...@@ -4,10 +5,11 @@
"net/http" "net/http"
"os" "os"
"time" "time"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version" "github.com/prometheus/common/version"
) )
var ready = false var ready = false
...@@ -10,6 +12,7 @@ ...@@ -10,6 +12,7 @@
"github.com/prometheus/common/version" "github.com/prometheus/common/version"
) )
var ready = false var ready = false
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
func main() { func main() {
...@@ -14,5 +17,6 @@ ...@@ -14,5 +17,6 @@
func main() { func main() {
flag.Parse()
log.Info("Starting presentation-gitlab-k8s application..") log.Info("Starting presentation-gitlab-k8s application..")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname() hostname, _ := os.Hostname()
...@@ -30,8 +34,9 @@ ...@@ -30,8 +34,9 @@
w.Write([]byte("500")) w.Write([]byte("500"))
} }
}) })
http.Handle("/metrics", promhttp.Handler())
go func() { go func() {
<-time.After(5 * time.Second) <-time.After(5 * time.Second)
ready = true ready = true
log.Info("Application is ready!") log.Info("Application is ready!")
}() }()
...@@ -33,8 +38,8 @@ ...@@ -33,8 +38,8 @@
go func() { go func() {
<-time.After(5 * time.Second) <-time.After(5 * time.Second)
ready = true ready = true
log.Info("Application is ready!") log.Info("Application is ready!")
}() }()
log.Info("Listen on :8000") log.Info("Listen on " + *addr)
log.Fatal(http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))) log.Fatal(http.ListenAndServe(*addr, handlers.LoggingHandler(os.Stdout, http.DefaultServeMux)))
} }
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
spec: spec:
type: ClusterIP type: ClusterIP
ports: ports:
- port: 8000 - name: http-metrics
port: 8000
protocol: TCP protocol: TCP
selector: selector:
app: __CI_ENVIRONMENT_SLUG__ app: __CI_ENVIRONMENT_SLUG__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment