diff --git a/cns/kubecontroller/nodenetworkconfig/metrics.go b/cns/kubecontroller/nodenetworkconfig/metrics.go index a1ca124b6e..d85398bca6 100644 --- a/cns/kubecontroller/nodenetworkconfig/metrics.go +++ b/cns/kubecontroller/nodenetworkconfig/metrics.go @@ -24,6 +24,18 @@ var ( Help: "Unused IP count.", }, ) + hasNNC = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "nnc_has_nodenetworkconfig", + Help: "Has received a NodeNetworkConfig", + }, + ) + ncs = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "nnc_ncs", + Help: "Network Container count in the NodeNetworkConfig", + }, + ) ) func init() { @@ -31,5 +43,7 @@ func init() { allocatedIPs, requestedIPs, unusedIPs, + hasNNC, + ncs, ) } diff --git a/cns/kubecontroller/nodenetworkconfig/reconciler.go b/cns/kubecontroller/nodenetworkconfig/reconciler.go index 40b8fd1c05..4d5eb1bcd1 100644 --- a/cns/kubecontroller/nodenetworkconfig/reconciler.go +++ b/cns/kubecontroller/nodenetworkconfig/reconciler.go @@ -64,13 +64,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco nnc, err := r.nnccli.Get(ctx, req.NamespacedName) if err != nil { if apierrors.IsNotFound(err) { + hasNNC.Set(0) logger.Printf("[cns-rc] CRD not found, ignoring %v", err) return reconcile.Result{}, errors.Wrapf(client.IgnoreNotFound(err), "NodeNetworkConfig %v not found", req.NamespacedName) } logger.Errorf("[cns-rc] Error retrieving CRD from cache : %v", err) return reconcile.Result{}, errors.Wrapf(err, "failed to get NodeNetworkConfig %v", req.NamespacedName) } - + hasNNC.Set(1) logger.Printf("[cns-rc] CRD Spec: %+v", nnc.Spec) ipAssignments := 0 @@ -78,7 +79,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco // during node upgrades, an nnc may be updated with new ncs. at any given time, only the ncs // that exist in the nnc are valid. any others that may have been previously created and no // longer exist in the nnc should be considered stale. - validNCIDs := make([]string, len(nnc.Status.NetworkContainers)) + ncCount := len(nnc.Status.NetworkContainers) + ncs.Set(float64(ncCount)) + validNCIDs := make([]string, ncCount) for i := range nnc.Status.NetworkContainers { validNCIDs[i] = nnc.Status.NetworkContainers[i].ID } diff --git a/cns/restserver/internalapi.go b/cns/restserver/internalapi.go index fa41525030..8d477cbab8 100644 --- a/cns/restserver/internalapi.go +++ b/cns/restserver/internalapi.go @@ -225,6 +225,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo for _, nc := range ncVersionListResp.Containers { nmaNCs[strings.ToLower(nc.NetworkContainerID)] = nc.Version } + hasNC.Set(float64(len(nmaNCs))) for ncID := range outdatedNCs { nmaNCVersionStr, ok := nmaNCs[ncID] if !ok { diff --git a/cns/restserver/metrics.go b/cns/restserver/metrics.go index 010779ef20..b4c0dae8dd 100644 --- a/cns/restserver/metrics.go +++ b/cns/restserver/metrics.go @@ -65,6 +65,12 @@ var ( }, []string{"ok"}, ) + hasNC = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "has_networkcontainer", + Help: "Number of Network Containers retrieved from NMA", + }, + ) allocatedIPCount = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "cx_allocated_ips_v2", @@ -114,6 +120,7 @@ func init() { ipConfigStatusStateTransitionTime, syncHostNCVersionCount, syncHostNCVersionLatency, + hasNC, allocatedIPCount, assignedIPCount, availableIPCount,