Skip to content

Commit da93f82

Browse files
pete-woodsnickethier
authored andcommitted
Add node "status" and "scheduling eligibility" tags to client metrics (#6130)
When summing up the capability of your Nomad fleet for scaling purposes, it's important to exclude draining nodes, as they won't accept new jobs.
1 parent 477cf83 commit da93f82

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

client/client.go

+22-15
Original file line numberDiff line numberDiff line change
@@ -2593,12 +2593,12 @@ func (c *Client) emitStats() {
25932593
}
25942594

25952595
// setGaugeForMemoryStats proxies metrics for memory specific statistics
2596-
func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats) {
2596+
func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats, baseLabels []metrics.Label) {
25972597
if !c.config.DisableTaggedMetrics {
2598-
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "total"}, float32(hStats.Memory.Total), c.baseLabels)
2599-
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "available"}, float32(hStats.Memory.Available), c.baseLabels)
2600-
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "used"}, float32(hStats.Memory.Used), c.baseLabels)
2601-
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "free"}, float32(hStats.Memory.Free), c.baseLabels)
2598+
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "total"}, float32(hStats.Memory.Total), baseLabels)
2599+
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "available"}, float32(hStats.Memory.Available), baseLabels)
2600+
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "used"}, float32(hStats.Memory.Used), baseLabels)
2601+
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "free"}, float32(hStats.Memory.Free), baseLabels)
26022602
}
26032603

26042604
if c.config.BackwardsCompatibleMetrics {
@@ -2610,10 +2610,10 @@ func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats)
26102610
}
26112611

26122612
// setGaugeForCPUStats proxies metrics for CPU specific statistics
2613-
func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats) {
2613+
func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats, baseLabels []metrics.Label) {
26142614
for _, cpu := range hStats.CPU {
26152615
if !c.config.DisableTaggedMetrics {
2616-
labels := append(c.baseLabels, metrics.Label{
2616+
labels := append(baseLabels, metrics.Label{
26172617
Name: "cpu",
26182618
Value: cpu.CPU,
26192619
})
@@ -2634,10 +2634,10 @@ func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats) {
26342634
}
26352635

26362636
// setGaugeForDiskStats proxies metrics for disk specific statistics
2637-
func (c *Client) setGaugeForDiskStats(nodeID string, hStats *stats.HostStats) {
2637+
func (c *Client) setGaugeForDiskStats(nodeID string, hStats *stats.HostStats, baseLabels []metrics.Label) {
26382638
for _, disk := range hStats.DiskStats {
26392639
if !c.config.DisableTaggedMetrics {
2640-
labels := append(c.baseLabels, metrics.Label{
2640+
labels := append(baseLabels, metrics.Label{
26412641
Name: "disk",
26422642
Value: disk.Device,
26432643
})
@@ -2737,9 +2737,9 @@ func (c *Client) setGaugeForAllocationStats(nodeID string) {
27372737
}
27382738

27392739
// No labels are required so we emit with only a key/value syntax
2740-
func (c *Client) setGaugeForUptime(hStats *stats.HostStats) {
2740+
func (c *Client) setGaugeForUptime(hStats *stats.HostStats, baseLabels []metrics.Label) {
27412741
if !c.config.DisableTaggedMetrics {
2742-
metrics.SetGaugeWithLabels([]string{"client", "uptime"}, float32(hStats.Uptime), c.baseLabels)
2742+
metrics.SetGaugeWithLabels([]string{"client", "uptime"}, float32(hStats.Uptime), baseLabels)
27432743
}
27442744
if c.config.BackwardsCompatibleMetrics {
27452745
metrics.SetGauge([]string{"client", "uptime"}, float32(hStats.Uptime))
@@ -2750,11 +2750,18 @@ func (c *Client) setGaugeForUptime(hStats *stats.HostStats) {
27502750
func (c *Client) emitHostStats() {
27512751
nodeID := c.NodeID()
27522752
hStats := c.hostStatsCollector.Stats()
2753+
node := c.Node()
2754+
2755+
node.Canonicalize()
2756+
labels := append(c.baseLabels,
2757+
metrics.Label{Name: "node_status", Value: node.Status},
2758+
metrics.Label{Name: "node_scheduling_eligibility", Value: node.SchedulingEligibility},
2759+
)
27532760

2754-
c.setGaugeForMemoryStats(nodeID, hStats)
2755-
c.setGaugeForUptime(hStats)
2756-
c.setGaugeForCPUStats(nodeID, hStats)
2757-
c.setGaugeForDiskStats(nodeID, hStats)
2761+
c.setGaugeForMemoryStats(nodeID, hStats, labels)
2762+
c.setGaugeForUptime(hStats, labels)
2763+
c.setGaugeForCPUStats(nodeID, hStats, labels)
2764+
c.setGaugeForDiskStats(nodeID, hStats, labels)
27582765
}
27592766

27602767
// emitClientMetrics emits lower volume client metrics

0 commit comments

Comments
 (0)