Skip to content

Commit

Permalink
cloud metadata: added the ability to set the instance type and lifecy…
Browse files Browse the repository at this point in the history
…cle using CLI arguments or environment variables
  • Loading branch information
def committed Mar 29, 2023
1 parent b64ad23 commit 2163f5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
8 changes: 5 additions & 3 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ var (
externalNetworksWhitelist = kingpin.Flag("track-public-network", "Allow track connections to the specified IP networks, all private networks are allowed by default (e.g., Y.Y.Y.Y/mask)").Strings()
ExternalNetworksWhitelist []netaddr.IPPrefix

Provider = kingpin.Flag("provider", "`provider` label for `node_cloud_info` metric").String()
Region = kingpin.Flag("region", "`region` label for `node_cloud_info` metric").String()
AvailabilityZone = kingpin.Flag("availability-zone", "`availability_zone` label for `node_cloud_info` metric").String()
Provider = kingpin.Flag("provider", "`provider` label for `node_cloud_info` metric").Envar("PROVIDER").String()
Region = kingpin.Flag("region", "`region` label for `node_cloud_info` metric").Envar("REGION").String()
AvailabilityZone = kingpin.Flag("availability-zone", "`availability_zone` label for `node_cloud_info` metric").Envar("AVAILABILITY_ZONE").String()
InstanceType = kingpin.Flag("instance-type", "`instance_type` label for `node_cloud_info` metric").Envar("INSTANCE_TYPE").String()
InstanceLifeCycle = kingpin.Flag("instance-life-cycle", "`instance_life_cycle` label for `node_cloud_info` metric").Envar("INSTANCE_LIFE_CYCLE").String()
)

func GetString(fl *string) string {
Expand Down
31 changes: 21 additions & 10 deletions node/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,29 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
}
}

im := metadata.CloudMetadata{}
if c.instanceMetadata != nil {
im := c.instanceMetadata
ch <- gauge(cloudInfoDesc, 1,
string(im.Provider), im.AccountId, im.InstanceId, im.InstanceType, im.LifeCycle,
im.Region, im.AvailabilityZone, im.AvailabilityZoneId, im.LocalIPv4, im.PublicIPv4,
)
} else if flags.Provider != nil || flags.Region != nil || flags.AvailabilityZone != nil {
ch <- gauge(cloudInfoDesc, 1,
flags.GetString(flags.Provider), "", "", "", "",
flags.GetString(flags.Region), flags.GetString(flags.AvailabilityZone), "", "", "",
)
im = *c.instanceMetadata
}
if flags.Provider != nil {
im.Provider = metadata.CloudProvider(flags.GetString(flags.Provider))
}
if flags.Region != nil {
im.Region = flags.GetString(flags.Region)
}
if flags.AvailabilityZone != nil {
im.AvailabilityZone = flags.GetString(flags.AvailabilityZone)
}
if flags.InstanceType != nil {
im.InstanceType = flags.GetString(flags.InstanceType)
}
if flags.InstanceLifeCycle != nil {
im.LifeCycle = flags.GetString(flags.InstanceLifeCycle)
}
ch <- gauge(cloudInfoDesc, 1,
string(im.Provider), im.AccountId, im.InstanceId, im.InstanceType, im.LifeCycle,
im.Region, im.AvailabilityZone, im.AvailabilityZoneId, im.LocalIPv4, im.PublicIPv4,
)
}

func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
Expand Down

0 comments on commit 2163f5f

Please sign in to comment.