2019-08-21 09:28:02 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2020-07-09 05:14:10 +00:00
|
|
|
klog "k8s.io/klog/v2"
|
2019-08-21 09:28:02 +00:00
|
|
|
)
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// ValidateURL validates the url.
|
2019-08-21 09:28:02 +00:00
|
|
|
func ValidateURL(c *Config) error {
|
|
|
|
_, err := url.Parse(c.MetricsPath)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// StartMetricsServer starts http server.
|
2019-08-21 09:28:02 +00:00
|
|
|
func StartMetricsServer(c *Config) {
|
|
|
|
addr := net.JoinHostPort(c.MetricsIP, strconv.Itoa(c.MetricsPort))
|
|
|
|
http.Handle(c.MetricsPath, promhttp.Handler())
|
|
|
|
err := http.ListenAndServe(addr, nil)
|
|
|
|
if err != nil {
|
|
|
|
klog.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|