|
@@ -20,6 +20,7 @@ package server
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "github.com/gorilla/mux"
|
|
|
"github.com/lf-edge/ekuiper/internal/conf"
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
"net/http"
|
|
@@ -27,38 +28,58 @@ import (
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
- servers["prometheus"] = promeComp{}
|
|
|
+ p := promeComp{}
|
|
|
+ servers["prometheus"] = p
|
|
|
+ components["prometheus"] = p
|
|
|
}
|
|
|
|
|
|
type promeComp struct {
|
|
|
s *http.Server
|
|
|
}
|
|
|
|
|
|
+func (p promeComp) register() {
|
|
|
+ // Do nothing
|
|
|
+}
|
|
|
+
|
|
|
+func (p promeComp) rest(r *mux.Router) {
|
|
|
+ portPrometheus := conf.Config.Basic.PrometheusPort
|
|
|
+ portRest := conf.Config.Basic.RestPort
|
|
|
+ if portPrometheus == portRest {
|
|
|
+ r.Handle("/metrics", promhttp.Handler())
|
|
|
+ msg := fmt.Sprintf("Register prometheus metrics to http://localhost:%d/metrics", portPrometheus)
|
|
|
+ logger.Infof(msg)
|
|
|
+ fmt.Println(msg)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (p promeComp) serve() {
|
|
|
- //Start prometheus service
|
|
|
if conf.Config.Basic.Prometheus {
|
|
|
+ //Start prometheus service
|
|
|
portPrometheus := conf.Config.Basic.PrometheusPort
|
|
|
if portPrometheus <= 0 {
|
|
|
logger.Fatal("Miss configuration prometheusPort")
|
|
|
}
|
|
|
- mux := http.NewServeMux()
|
|
|
- mux.Handle("/metrics", promhttp.Handler())
|
|
|
- srvPrometheus := &http.Server{
|
|
|
- Addr: fmt.Sprintf("0.0.0.0:%d", portPrometheus),
|
|
|
- WriteTimeout: time.Second * 15,
|
|
|
- ReadTimeout: time.Second * 15,
|
|
|
- IdleTimeout: time.Second * 60,
|
|
|
- Handler: mux,
|
|
|
- }
|
|
|
- go func() {
|
|
|
- if err := srvPrometheus.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
|
- logger.Fatal("Listen prometheus error: ", err)
|
|
|
+ portRest := conf.Config.Basic.RestPort
|
|
|
+ if portPrometheus != portRest {
|
|
|
+ mux := http.NewServeMux()
|
|
|
+ mux.Handle("/metrics", promhttp.Handler())
|
|
|
+ srvPrometheus := &http.Server{
|
|
|
+ Addr: fmt.Sprintf("0.0.0.0:%d", portPrometheus),
|
|
|
+ WriteTimeout: time.Second * 15,
|
|
|
+ ReadTimeout: time.Second * 15,
|
|
|
+ IdleTimeout: time.Second * 60,
|
|
|
+ Handler: mux,
|
|
|
}
|
|
|
- }()
|
|
|
- p.s = srvPrometheus
|
|
|
- msg := fmt.Sprintf("Serving prometheus metrics on port http://localhost:%d/metrics", portPrometheus)
|
|
|
- logger.Infof(msg)
|
|
|
- fmt.Println(msg)
|
|
|
+ go func() {
|
|
|
+ if err := srvPrometheus.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
|
+ logger.Fatal("Listen prometheus error: ", err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ p.s = srvPrometheus
|
|
|
+ msg := fmt.Sprintf("Serving prometheus metrics on port http://localhost:%d/metrics", portPrometheus)
|
|
|
+ logger.Infof(msg)
|
|
|
+ fmt.Println(msg)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|