@@ -122,6 +122,19 @@ var (
122
122
},
123
123
[]string {"cidr" },
124
124
)
125
+ noAvailableAddrs = prometheus .NewCounter (
126
+ prometheus.CounterOpts {
127
+ Name : "awscni_err_no_avail_addrs" ,
128
+ Help : "The number of IP/Prefix assignments that fail due to no available addresses at the ENI level" ,
129
+ },
130
+ )
131
+ eniUtilization = prometheus .NewGaugeVec (
132
+ prometheus.GaugeOpts {
133
+ Name : "awscni_eni_util" ,
134
+ Help : "The number of allocated ips partitioned by eni" ,
135
+ },
136
+ []string {"fn" },
137
+ )
125
138
prometheusRegistered = false
126
139
)
127
140
@@ -344,6 +357,8 @@ func prometheusRegister() {
344
357
prometheus .MustRegister (forceRemovedIPs )
345
358
prometheus .MustRegister (totalPrefixes )
346
359
prometheus .MustRegister (ipsPerCidr )
360
+ prometheus .MustRegister (noAvailableAddrs )
361
+ prometheus .MustRegister (eniUtilization )
347
362
prometheusRegistered = true
348
363
}
349
364
}
@@ -521,6 +536,7 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
521
536
DeviceNumber : deviceNumber ,
522
537
AvailableIPv4Cidrs : make (map [string ]* CidrInfo )}
523
538
539
+ ds .GetENIUtilization ()
524
540
enis .Set (float64 (len (ds .eniPool )))
525
541
return nil
526
542
}
@@ -714,6 +730,7 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
714
730
return addr .Address , eni .DeviceNumber , nil
715
731
}
716
732
}
733
+ noAvailableAddrs .Inc ()
717
734
return "" , - 1 , errors .New ("assignPodIPv6AddressUnsafe: no available IP addresses" )
718
735
}
719
736
@@ -781,6 +798,7 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
781
798
ds .log .Debugf ("AssignPodIPv4Address: ENI %s does not have available addresses" , eni .ID )
782
799
}
783
800
801
+ noAvailableAddrs .Inc ()
784
802
ds .log .Errorf ("DataStore has no available IP/Prefix addresses" )
785
803
return "" , - 1 , errors .New ("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses" )
786
804
}
@@ -797,6 +815,7 @@ func (ds *DataStore) assignPodIPAddressUnsafe(addr *AddressInfo, ipamKey IPAMKey
797
815
addr .IPAMMetadata = ipamMetadata
798
816
addr .AssignedTime = assignedTime
799
817
818
+ ds .log .Debugf ("IP allocation request" )
800
819
ds .assigned ++
801
820
// Prometheus gauge
802
821
assignedIPs .Set (float64 (ds .assigned ))
@@ -813,6 +832,7 @@ func (ds *DataStore) unassignPodIPAddressUnsafe(addr *AddressInfo) {
813
832
addr .IPAMKey = IPAMKey {} // unassign the addr
814
833
addr .IPAMMetadata = IPAMMetadata {}
815
834
ds .assigned --
835
+ ds .log .Debugf ("IP deallocation request" )
816
836
// Prometheus gauge
817
837
assignedIPs .Set (float64 (ds .assigned ))
818
838
}
@@ -866,6 +886,24 @@ func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats {
866
886
return stats
867
887
}
868
888
889
+ // GetENIUtilization updates a Prometheus gauge vector with each ENIs id and how many ip addresses are assigned on it
890
+ func (ds * DataStore ) GetENIUtilization () {
891
+ //eniUtilization.Reset()
892
+ for _ , eni := range ds .eniPool {
893
+ count := 0
894
+ for _ , assignedAddr := range eni .AvailableIPv4Cidrs {
895
+ for _ , addr := range assignedAddr .IPAddresses {
896
+ if addr .Assigned () {
897
+ count += 1
898
+ }
899
+ }
900
+ }
901
+ utilization := count
902
+ eniID := eni .ID
903
+ eniUtilization .WithLabelValues (eniID ).Set (float64 (utilization ))
904
+ }
905
+ }
906
+
869
907
// GetTrunkENI returns the trunk ENI ID or an empty string
870
908
func (ds * DataStore ) GetTrunkENI () string {
871
909
ds .lock .Lock ()
@@ -1072,6 +1110,7 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
1072
1110
1073
1111
// Prometheus update
1074
1112
enis .Set (float64 (len (ds .eniPool )))
1113
+ ds .GetENIUtilization ()
1075
1114
totalIPs .Set (float64 (ds .total ))
1076
1115
return removableENI
1077
1116
}
@@ -1126,6 +1165,7 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
1126
1165
1127
1166
// Prometheus gauge
1128
1167
enis .Set (float64 (len (ds .eniPool )))
1168
+ ds .GetENIUtilization ()
1129
1169
return nil
1130
1170
}
1131
1171
0 commit comments