mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-03 05:51:08 +02:00
* - added protocol & port label to metrics - removed some redundant code * added example dashboard * added dashboard screenshot * updated dashboard json & screenshot * ammend bad dashboard export * first new metric * . * more metrics: controller_publish_metrics_time & controller_iptables_sync_time * namespace redeclared * fix typo in name * smal fixes * new metric controller_bgp_peers & controller_bgp_internal_peers_sync_time * typo fix * new metric controller_ipvs_service_sync_time * fix * register metric * fix * fix * added more metrics * service controller log levels * fix * fix * added metrics controller * fixes * fix * fix * fixed more log levels * server and graceful shutdown * fix * fix * fix * code cleanup * docs * move metrics exporting to controller * fix * fix * fixes * fix * fix missing * fix * fix * test * test * fix * fix * fix * updated dashboard * updates to metric controller * fixed order in newmetricscontroller * err declared and not used * updated dashboard * updated dashboard screenshot * removed --metrics & changed --metrics-port to enable / disable metrics * https://github.com/cloudnativelabs/kube-router/issues/271 * cannot use config.MetricsPort (type uint16) as type int in assignment * cannot use mc.MetricsPort (type uint16) as type int in argument to strconv.Itoa * updated docs * changed default metric port to 0, disabled * added missing newline to .dockerignore * add lag parse to pickup on -v directives * test * test * test * fix regression * syntax error: non-declaration statement outside function body * fix * changed nsc to mc * updated docs * markdown fix * moved metrics registration out to respective controller so only metrics for running parts will be exposed * removed junk that came from visual studio code * fixed some typos * Moved the metrics back into each controller and added expose behaviour so only the running components metrics would be published * removed to much, added back instanciation of metricscontroller * fixed some invalid variable names * fixed last typos on config name * fixed order in newnetworkservicecontroller * updated metrics docs & removed the metrics sync period as it will obey the controllers sync period * forgott to save options.go * cleanup * Updated metric name & docs * updated metrics.md * fixed a high cpu usage bug in the metrics_controller's wait loop
155 lines
5.8 KiB
Go
155 lines
5.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"strconv"
|
|
"sync"
|
|
|
|
"github.com/cloudnativelabs/kube-router/app/options"
|
|
"github.com/golang/glog"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"golang.org/x/net/context"
|
|
"k8s.io/client-go/kubernetes"
|
|
)
|
|
|
|
var (
|
|
serviceTotalConn = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_total_connections",
|
|
Help: "Total incoming conntections made",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
servicePacketsIn = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_packets_in",
|
|
Help: "Total incoming packets",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
servicePacketsOut = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_packets_out",
|
|
Help: "Total outoging packets",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
serviceBytesIn = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_bytes_in",
|
|
Help: "Total incoming bytes",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
serviceBytesOut = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_bytes_out",
|
|
Help: "Total outgoing bytes",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
servicePpsIn = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_pps_in",
|
|
Help: "Incoming packets per second",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
servicePpsOut = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_pps_out",
|
|
Help: "Outoging packets per second",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
serviceCPS = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_cps",
|
|
Help: "Service connections per second",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
serviceBpsIn = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_bps_in",
|
|
Help: "Incoming bytes per second",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
serviceBpsOut = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "service_bps_out",
|
|
Help: "Outoging bytes per second",
|
|
}, []string{"namespace", "service_name", "service_vip", "protocol", "port"})
|
|
controllerIpvsServices = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_ipvs_services",
|
|
Help: "Number of ipvs services in the instance",
|
|
}, []string{})
|
|
controllerIptablesSyncTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_iptables_sync_time",
|
|
Help: "Time it took for controller to sync iptables",
|
|
}, []string{})
|
|
controllerPublishMetricsTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_publish_metrics_time",
|
|
Help: "Time it took to publish metrics",
|
|
}, []string{})
|
|
controllerIpvsServicesSyncTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_ipvs_services_sync_time",
|
|
Help: "Time it took for controller to sync ipvs services",
|
|
}, []string{})
|
|
controllerBPGpeers = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_bgp_peers",
|
|
Help: "BGP peers in the runtime configuration",
|
|
}, []string{})
|
|
controllerBGPInternalPeersSyncTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_bgp_internal_peers_sync_time",
|
|
Help: "Time it took to sync internal bgp peers",
|
|
}, []string{})
|
|
controllerBGPadvertisementsReceived = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_bgp_advertisements_received",
|
|
Help: "Time it took to sync internal bgp peers",
|
|
}, []string{})
|
|
controllerIpvsMetricsExportTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Name: "controller_ipvs_metrics_export_time",
|
|
Help: "Time it took to export metrics",
|
|
}, []string{})
|
|
)
|
|
|
|
// MetricsController Holds settings for the metrics controller
|
|
type MetricsController struct {
|
|
endpointsMap endpointsInfoMap
|
|
MetricsPath string
|
|
MetricsPort uint16
|
|
mu sync.Mutex
|
|
nodeIP net.IP
|
|
serviceMap serviceInfoMap
|
|
}
|
|
|
|
// Run prometheus metrics controller
|
|
func (mc *MetricsController) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) error {
|
|
defer wg.Done()
|
|
glog.Info("Starting metrics controller")
|
|
|
|
// register metrics for this controller
|
|
prometheus.MustRegister(controllerIpvsMetricsExportTime)
|
|
|
|
srv := &http.Server{Addr: ":" + strconv.Itoa(int(mc.MetricsPort)), Handler: http.DefaultServeMux}
|
|
|
|
// add prometheus handler on metrics path
|
|
http.Handle(mc.MetricsPath, promhttp.Handler())
|
|
|
|
go func() {
|
|
if err := srv.ListenAndServe(); err != nil {
|
|
// cannot panic, because this probably is an intentional close
|
|
glog.Errorf("Metrics controller error: %s", err)
|
|
}
|
|
}()
|
|
|
|
<-stopCh
|
|
glog.Infof("Shutting down metrics controller")
|
|
if err := srv.Shutdown(context.Background()); err != nil {
|
|
glog.Errorf("could not shutdown: %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NewMetricsController returns new MetricController object
|
|
func NewMetricsController(clientset *kubernetes.Clientset, config *options.KubeRouterConfig) (*MetricsController, error) {
|
|
mc := MetricsController{}
|
|
mc.MetricsPath = config.MetricsPath
|
|
mc.MetricsPort = config.MetricsPort
|
|
return &mc, nil
|
|
}
|