@@ -45,6 +45,7 @@ type Metrics struct {
4545 actionsCounter api.Int64Counter
4646 actionsCounterV2 api.Int64Counter
4747 errorEventsCounter api.Int64Counter
48+ nodesCounter api.Int64Counter
4849}
4950
5051// InitMetrics will initialize, register and expose, via http server, the metrics with Opentelemetry.
@@ -101,6 +102,26 @@ func (m Metrics) NodeActionsInc(action, nodeName string, eventID string, err err
101102 m .actionsCounterV2 .Add (context .Background (), 1 , api .WithAttributes (labelsV2 ... ))
102103}
103104
105+ // NodesInc will increment one for the node stats counter, partitioned by nodeName, and only if metrics are enabled.
106+ func (m Metrics ) NodesInc (nodeName string ) {
107+ m .NodesModify (1 , nodeName )
108+ }
109+
110+ // NodesInc will decrease one for the node stats counter, partitioned by nodeName, and only if metrics are enabled.
111+ func (m Metrics ) NodesDec (nodeName string ) {
112+ m .NodesModify (- 1 , nodeName )
113+ }
114+
115+ func (m Metrics ) NodesModify (num int64 , nodeName string ) {
116+ if ! m .enabled {
117+ return
118+ }
119+
120+ labels := []attribute.KeyValue {labelNodeNameKey .String (nodeName )}
121+
122+ m .actionsCounter .Add (context .Background (), num , api .WithAttributes (labels ... ))
123+ }
124+
104125func registerMetricsWith (provider * metric.MeterProvider ) (Metrics , error ) {
105126 meter := provider .Meter ("aws.node.termination.handler" )
106127
@@ -127,11 +148,20 @@ func registerMetricsWith(provider *metric.MeterProvider) (Metrics, error) {
127148 return Metrics {}, fmt .Errorf ("failed to create Prometheus counter %q: %w" , name , err )
128149 }
129150 errorEventsCounter .Add (context .Background (), 0 )
151+
152+ name = "nodes"
153+ nodesCounter , err := meter .Int64Counter (name , api .WithDescription ("Number of nodes processing" ))
154+ if err != nil {
155+ return Metrics {}, fmt .Errorf ("failed to create Prometheus counter %q: %w" , name , err )
156+ }
157+ nodesCounter .Add (context .Background (), 0 )
158+
130159 return Metrics {
131160 meter : meter ,
132161 errorEventsCounter : errorEventsCounter ,
133162 actionsCounter : actionsCounter ,
134163 actionsCounterV2 : actionsCounterV2 ,
164+ nodesCounter : nodesCounter ,
135165 }, nil
136166}
137167
0 commit comments