Skip to content

Commit

Permalink
Add a 'reserved ENIs' metric
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Nov 16, 2019
1 parent 548163a commit de3d0c7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ var (
Help: "The maximum number of ENIs that can be attached to the instance",
},
)
reservedENIs = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "awscni_eni_reserved",
Help: "The number of ENIs that are reserved on this instance",
},
)
ipMax = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "awscni_ip_max",
Expand Down Expand Up @@ -282,15 +288,13 @@ func (c *IPAMContext) nodeInit() error {
log.Error("Failed to get ENI limit")
return err
}
c.maxENI = nodeMaxENI - numReserved
enisMax.Set(float64(c.maxENI))

c.maxENI = nodeMaxENI
c.maxIPsPerENI, err = c.awsClient.GetENIipLimit()
if err != nil {
log.Error("Failed to get IPs per ENI limit")
return err
}
ipMax.Set(float64(c.maxIPsPerENI * c.maxENI))
c.updateIPStats(numReserved)

_, vpcCIDR, err := net.ParseCIDR(c.awsClient.GetVPCIPv4CIDR())
if err != nil {
Expand Down Expand Up @@ -390,6 +394,11 @@ func (c *IPAMContext) nodeInit() error {
return err
}

func (c *IPAMContext) updateIPStats(reserved int) {
ipMax.Set(float64(c.maxIPsPerENI * (c.maxENI - reserved)))
reservedENIs.Set(float64(reserved))
}

func (c *IPAMContext) getLocalPodsWithRetry() ([]*k8sapi.K8SPodInfo, error) {
var pods []*k8sapi.K8SPodInfo
var err error
Expand Down Expand Up @@ -917,7 +926,8 @@ func (c *IPAMContext) nodeIPPoolReconcile(interval time.Duration) {
ipamdErrInc("reconcileFailedGetENIs")
return
}
attachedENIs, _ := filterUnmanagedENIs(allENIs)
attachedENIs, numReserved := filterUnmanagedENIs(allENIs)
c.updateIPStats(numReserved)

curENIs := c.dataStore.GetENIInfos()

Expand Down

0 comments on commit de3d0c7

Please sign in to comment.