@@ -44,27 +44,22 @@ const (
4444)
4545
4646var (
47- h * ipvs.Handle
48- serviceBackendActiveConn = prometheus .NewGaugeVec (prometheus.GaugeOpts {
47+ h * ipvs.Handle
48+ serviceActiveConn = prometheus .NewGaugeVec (prometheus.GaugeOpts {
4949 Namespace : namespace ,
50- Name : "service_backend_active_connections " ,
51- Help : "Active conntection to backend of service" ,
50+ Name : "service_active_connections " ,
51+ Help : "Active conntection to service" ,
5252 }, []string {"namespace" , "service_name" , "backend" })
53- serviceBackendInactiveConn = prometheus .NewGaugeVec (prometheus.GaugeOpts {
53+ servicePpsIn = prometheus .NewGaugeVec (prometheus.GaugeOpts {
5454 Namespace : namespace ,
55- Name : "service_backend_inactive_connections" ,
56- Help : "Active conntection to backend of service" ,
57- }, []string {"namespace" , "service_name" , "backend" })
58- serviceBackendPpsIn = prometheus .NewGaugeVec (prometheus.GaugeOpts {
59- Namespace : namespace ,
60- Name : "service_backend_pps_in" ,
55+ Name : "service_pps_in" ,
6156 Help : "Incoming packets per second" ,
62- }, []string {"namespace" , "service_name" , "backend" })
63- serviceBackendPpsOut = prometheus .NewGaugeVec (prometheus.GaugeOpts {
57+ }, []string {"namespace" , "service_name" })
58+ servicePpsOut = prometheus .NewGaugeVec (prometheus.GaugeOpts {
6459 Namespace : namespace ,
65- Name : "service_backend_pps_out " ,
60+ Name : "service_pps_out " ,
6661 Help : "Outoging packets per second" ,
67- }, []string {"namespace" , "service_name" , "backend" })
62+ }, []string {"namespace" , "service_name" })
6863)
6964
7065// NetworkServicesController enables local node as network service proxy through IPVS/LVS.
@@ -133,10 +128,9 @@ func (nsc *NetworkServicesController) Run(stopCh <-chan struct{}, wg *sync.WaitG
133128 }
134129
135130 // register metrics
136- prometheus .MustRegister (serviceBackendActiveConn )
137- prometheus .MustRegister (serviceBackendInactiveConn )
138- prometheus .MustRegister (serviceBackendPpsIn )
139- prometheus .MustRegister (serviceBackendPpsOut )
131+ prometheus .MustRegister (serviceActiveConn )
132+ prometheus .MustRegister (servicePpsIn )
133+ prometheus .MustRegister (servicePpsOut )
140134 http .Handle ("/metrics" , promhttp .Handler ())
141135 go http .ListenAndServe (":8080" , nil )
142136
@@ -679,41 +673,27 @@ func prepareEndpointForDsr(containerId string, endpointIP string, vip string) er
679673}
680674
681675func (nsc * NetworkServicesController ) publishMetrics (serviceInfoMap serviceInfoMap ) error {
682- // ipvsSvcs, err := h.GetServices()
683- // if err != nil {
684- // return errors.New("Failed to list IPVS services: " + err.Error())
685- // }
686- //
687- // for _, svc := range serviceInfoMap {
688- // for _, ipvsSvc := range ipvsSvcs {
689- // if strings.Compare(svc.clusterIP.String(), ipvsSvc.Address.String()) == 0 &&
690- // svc.protocol == strconv.Itoa(int(ipvsSvc.Protocol)) && uint16(svc.port) == ipvsSvc.Port {
691- // dsts, err := h.GetDestinations(ipvsSvc)
692- // if err != nil {
693- // glog.Errorf("Failed to get list of servers from ipvs service")
694- // }
695- // for _, dst := range dsts {
696- // serviceBackendActiveConn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.Stats))
697- // serviceBackendInactiveConn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.InactConns))
698- // serviceBackendPpsIn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.Stats.PPSIn))
699- // serviceBackendPpsOut.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.Stats.PPSOut))
700- // }
701- // }
702- // if strings.Compare(nsc.nodeIP.String(), ipvsSvc.Address.String()) == 0 &&
703- // svc.protocol == strconv.Itoa(int(ipvsSvc.Protocol)) && uint16(svc.port) == ipvsSvc.Port {
704- // dsts, err := h.GetDestinations(ipvsSvc)
705- // if err != nil {
706- // glog.Errorf("Failed to get list of servers from ipvs service")
707- // }
708- // for _, dst := range dsts {
709- // serviceBackendActiveConn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.ActiveConns))
710- // serviceBackendInactiveConn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.InactConns))
711- // serviceBackendPpsIn.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.Stats.PPSIn))
712- // serviceBackendPpsOut.WithLabelValues(svc.namespace, svc.name, dst.Address.String()).Set(float64(dst.Stats.PPSOut))
713- // }
714- // }
715- // }
716- // }
676+ ipvsSvcs , err := h .GetServices ()
677+ if err != nil {
678+ return errors .New ("Failed to list IPVS services: " + err .Error ())
679+ }
680+
681+ for _ , svc := range serviceInfoMap {
682+ for _ , ipvsSvc := range ipvsSvcs {
683+ if strings .Compare (svc .clusterIP .String (), ipvsSvc .Address .String ()) == 0 &&
684+ svc .protocol == strconv .Itoa (int (ipvsSvc .Protocol )) && uint16 (svc .port ) == ipvsSvc .Port {
685+ serviceActiveConn .WithLabelValues (svc .namespace , svc .name , svc .clusterIP .String ()).Set (float64 (ipvsSvc .Stats .Connections ))
686+ servicePpsIn .WithLabelValues (svc .namespace , svc .name , svc .clusterIP .String ()).Set (float64 (ipvsSvc .Stats .PacketsIn ))
687+ servicePpsOut .WithLabelValues (svc .namespace , svc .name , svc .clusterIP .String ()).Set (float64 (ipvsSvc .Stats .PacketsIn ))
688+ }
689+ if strings .Compare (nsc .nodeIP .String (), ipvsSvc .Address .String ()) == 0 &&
690+ svc .protocol == strconv .Itoa (int (ipvsSvc .Protocol )) && uint16 (svc .port ) == ipvsSvc .Port {
691+ serviceActiveConn .WithLabelValues (svc .namespace , svc .name , nsc .nodeIP .String ()).Set (float64 (ipvsSvc .Stats .Connections ))
692+ servicePpsIn .WithLabelValues (svc .namespace , svc .name , nsc .nodeIP .String ()).Set (float64 (ipvsSvc .Stats .PacketsIn ))
693+ servicePpsOut .WithLabelValues (svc .namespace , svc .name , nsc .nodeIP .String ()).Set (float64 (ipvsSvc .Stats .PacketsIn ))
694+ }
695+ }
696+ }
717697 return nil
718698}
719699
0 commit comments