@@ -20,13 +20,20 @@ var metrics *PrometheusMetrics
2020// It is set on initialization and does not change for the lifetime of the program.
2121var globalTelemetryEnabled bool
2222
23+ // Task statuses used as labels
24+ const (
25+ FinishedTaskStatus = "finished"
26+ ErrorTaskStatus = "error"
27+ SkippedTaskStatus = "skipped"
28+ )
29+
2330type PrometheusMetrics struct {
2431 PacketsRelayedSuccess * prometheus.CounterVec
2532 UnrelayedPackets * prometheus.GaugeVec
2633 TasksCount * prometheus.CounterVec
27- TaskExecutionTime * prometheus.SummaryVec
34+ FinishedTaskExecutionTime * prometheus.SummaryVec
2835 TunnelsPerDestinationChain * prometheus.CounterVec
29- ActiveTargetContractsCount prometheus.Gauge
36+ ActiveTargetContractsCount * prometheus.GaugeVec
3037 TxsCount * prometheus.CounterVec
3138 TxProcessTime * prometheus.SummaryVec
3239 GasUsed * prometheus.SummaryVec
@@ -38,82 +45,93 @@ func updateMetrics(updateFn func()) {
3845 }
3946}
4047
41- // IncPacketsRelayedSuccess increments the count of successfully relayed packets for a specific tunnel .
48+ // IncPacketsRelayedSuccess increments the count of successfully relayed packets.
4249func IncPacketsRelayedSuccess (tunnelID uint64 ) {
4350 updateMetrics (func () {
4451 metrics .PacketsRelayedSuccess .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Inc ()
4552 })
4653}
4754
48- // SetUnrelayedPackets sets the number of unrelayed packets for a specific tunnel .
49- func SetUnrelayedPackets (tunnelID uint64 , unrelayedPackets float64 ) {
55+ // SetUnrelayedPackets sets the number of unrelayed packets.
56+ func SetUnrelayedPackets (tunnelID uint64 , unrelayedPackets uint64 ) {
5057 updateMetrics (func () {
51- metrics .UnrelayedPackets .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Set (unrelayedPackets )
58+ metrics .UnrelayedPackets .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Set (float64 ( unrelayedPackets ) )
5259 })
5360}
5461
55- // IncTasksCount increments the total tasks count for a specific tunnel .
56- func IncTasksCount (tunnelID uint64 ) {
62+ // IncTasksCount increments the total count of executed tasks .
63+ func IncTasksCount (tunnelID uint64 , destinationChain string , taskStatus string ) {
5764 updateMetrics (func () {
58- metrics .TasksCount .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Inc ()
65+ metrics .TasksCount .WithLabelValues (fmt .Sprintf ("%d" , tunnelID ), destinationChain , taskStatus ).Inc ()
5966 })
6067}
6168
62- // ObserveTaskExecutionTime records the execution time of a task for a specific tunnel.
63- func ObserveTaskExecutionTime (tunnelID uint64 , taskExecutionTime float64 ) {
69+ // ObserveFinishedTaskExecutionTime records the execution time (ms) of a finished task.
70+ func ObserveFinishedTaskExecutionTime (
71+ tunnelID uint64 ,
72+ destinationChain string ,
73+ finishedTaskExecutionTime int64 ,
74+ ) {
6475 updateMetrics (func () {
65- metrics .TaskExecutionTime .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Observe (taskExecutionTime )
76+ metrics .FinishedTaskExecutionTime .WithLabelValues (fmt .Sprintf ("%d" , tunnelID ), destinationChain ).
77+ Observe (float64 (finishedTaskExecutionTime ))
6678 })
6779}
6880
69- // IncTunnelsPerDestinationChain increments the total number of tunnels per specific destination chain.
81+ // IncTunnelsPerDestinationChain increments the count of tunnels per destination chain.
7082func IncTunnelsPerDestinationChain (destinationChain string ) {
7183 updateMetrics (func () {
7284 metrics .TunnelsPerDestinationChain .WithLabelValues (destinationChain ).Inc ()
7385 })
7486}
7587
7688// IncActiveTargetContractsCount increases the count of active target contracts.
77- func IncActiveTargetContractsCount () {
89+ func IncActiveTargetContractsCount (destinationChain string ) {
7890 updateMetrics (func () {
79- metrics .ActiveTargetContractsCount .Inc ()
91+ metrics .ActiveTargetContractsCount .WithLabelValues ( destinationChain ). Inc ()
8092 })
8193}
8294
8395// DecActiveTargetContractsCount decreases the count of active target contracts.
84- func DecActiveTargetContractsCount () {
96+ func DecActiveTargetContractsCount (destinationChain string ) {
8597 updateMetrics (func () {
86- metrics .ActiveTargetContractsCount .Dec ()
98+ metrics .ActiveTargetContractsCount .WithLabelValues ( destinationChain ). Dec ()
8799 })
88100}
89101
90- // IncTxsCount increments the transactions count metric for a specific tunnel .
91- func IncTxsCount (tunnelID uint64 ) {
102+ // IncTxsCount increments the transactions count.
103+ func IncTxsCount (tunnelID uint64 , destinationChain string , txStatus string ) {
92104 updateMetrics (func () {
93- metrics .TxsCount .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Inc ()
105+ metrics .TxsCount .WithLabelValues (fmt .Sprintf ("%d" , tunnelID ), destinationChain , txStatus ).Inc ()
94106 })
95107}
96108
97- // ObserveTxProcessTime tracks transaction processing time in seconds with millisecond precision .
98- func ObserveTxProcessTime (destinationChain string , txProcessTime float64 ) {
109+ // ObserveTxProcessTime records the processing time (ms) for each transaction .
110+ func ObserveTxProcessTime (tunnelID uint64 , destinationChain string , txStatus string , txProcessTime int64 ) {
99111 updateMetrics (func () {
100- metrics .TxProcessTime .WithLabelValues (destinationChain ).Observe (txProcessTime )
112+ metrics .TxProcessTime .WithLabelValues (fmt .Sprintf ("%d" , tunnelID ), destinationChain , txStatus ).
113+ Observe (float64 (txProcessTime ))
101114 })
102115}
103116
104- // ObserveGasUsed tracks gas used for the each relayed transaction.
105- func ObserveGasUsed (tunnelID uint64 , gasUsed uint64 ) {
117+ // ObserveGasUsed tracks the amount of gas used for each transaction.
118+ func ObserveGasUsed (tunnelID uint64 , destinationChain string , txStatus string , gasUsed float64 ) {
106119 updateMetrics (func () {
107- metrics .GasUsed .WithLabelValues (fmt .Sprintf ("%d" , tunnelID )).Observe (float64 (gasUsed ))
120+ metrics .GasUsed .WithLabelValues (fmt .Sprintf ("%d" , tunnelID ), destinationChain , txStatus ).
121+ Observe (gasUsed )
108122 })
109123}
110124
111125func InitPrometheusMetrics () {
112126 packetLabels := []string {"tunnel_id" }
113- taskLabels := []string {"tunnel_id" }
127+ tasksCountLabels := []string {"tunnel_id" , "destination_chain" , "task_status" }
128+ finishedTaskExecutionTimeLabels := []string {"tunnel_id" , "destination_chain" }
114129 tunnelPerDestinationChainLabels := []string {"destination_chain" }
115- txLabels := []string {"tunnel_id" }
116- gasUsedLabels := []string {"tunnel_id" }
130+ activeTargetContractsLabels := []string {"destination_chain" }
131+ txsCountLabels := []string {"tunnel_id" , "destination_chain" , "tx_status" }
132+ txProcessTimeLabels := []string {"tunnel_id" , "destination_chain" , "tx_status" }
133+
134+ gasUsedLabels := []string {"tunnel_id" , "destination_chain" , "tx_status" }
117135
118136 metrics = & PrometheusMetrics {
119137 PacketsRelayedSuccess : promauto .NewCounterVec (prometheus.CounterOpts {
@@ -126,38 +144,38 @@ func InitPrometheusMetrics() {
126144 }, packetLabels ),
127145 TasksCount : promauto .NewCounterVec (prometheus.CounterOpts {
128146 Name : "falcon_tasks_count" ,
129- Help : "Total number of successfully executed tasks" ,
130- }, taskLabels ),
131- TaskExecutionTime : promauto .NewSummaryVec (prometheus.SummaryOpts {
132- Name : "falcon_task_execution_time " ,
133- Help : "Task execution time in milliseconds " ,
147+ Help : "Total number of executed tasks" ,
148+ }, tasksCountLabels ),
149+ FinishedTaskExecutionTime : promauto .NewSummaryVec (prometheus.SummaryOpts {
150+ Name : "falcon_finished_task_execution_time " ,
151+ Help : "Execution time (ms) for finished tasks " ,
134152 Objectives : map [float64 ]float64 {
135153 0.5 : 0.05 ,
136154 0.9 : 0.01 ,
137155 0.99 : 0.001 ,
138156 },
139- }, taskLabels ),
157+ }, finishedTaskExecutionTimeLabels ),
140158 TunnelsPerDestinationChain : promauto .NewCounterVec (prometheus.CounterOpts {
141159 Name : "falcon_tunnels_per_destination_chain" ,
142- Help : "Total number of destination chains " ,
160+ Help : "Total number of tunnels per destination chain " ,
143161 }, tunnelPerDestinationChainLabels ),
144- ActiveTargetContractsCount : promauto .NewGauge (prometheus.GaugeOpts {
162+ ActiveTargetContractsCount : promauto .NewGaugeVec (prometheus.GaugeOpts {
145163 Name : "falcon_active_target_contracts_count" ,
146164 Help : "Number of active target chain contracts" ,
147- }),
165+ }, activeTargetContractsLabels ),
148166 TxsCount : promauto .NewCounterVec (prometheus.CounterOpts {
149167 Name : "falcon_txs_count" ,
150- Help : "Total number of transactions per tunnel " ,
151- }, txLabels ),
168+ Help : "Total number of transactions" ,
169+ }, txsCountLabels ),
152170 TxProcessTime : promauto .NewSummaryVec (prometheus.SummaryOpts {
153171 Name : "falcon_tx_process_time" ,
154- Help : "Transaction processing time in milliseconds " ,
172+ Help : "Processing time (ms) for transaction " ,
155173 Objectives : map [float64 ]float64 {
156174 0.5 : 0.05 ,
157175 0.9 : 0.01 ,
158176 0.99 : 0.001 ,
159177 },
160- }, txLabels ),
178+ }, txProcessTimeLabels ),
161179 GasUsed : promauto .NewSummaryVec (prometheus.SummaryOpts {
162180 Name : "falcon_gas_used" ,
163181 Help : "Amount of gas used per transaction" ,
@@ -178,7 +196,7 @@ func StartMetricsServer(ctx context.Context, log *zap.Logger, metricsListenAddr
178196 ln , err := net .Listen ("tcp" , metricsListenAddr )
179197 if err != nil {
180198 log .Error (
181- "Failed to start metrics server you can change the address and port using metrics-listen-addr config setting or --metrics-listen-flag" ,
199+ "Failed to start metrics server you can change the address and port using metrics-listen-addr config setting or --metrics-listen-addr flag" ,
182200 )
183201
184202 return fmt .Errorf ("failed to listen on metrics address %q: %w" , metricsListenAddr , err )
0 commit comments