@@ -3618,6 +3618,82 @@ export class Monitoring {
3618
3618
}
3619
3619
}
3620
3620
3621
+ /**
3622
+ * Fetches metrics from Prometheus and returns their values.
3623
+ * If a metric is missing, it will be included in the result with a value of null.
3624
+ * @returns {Object[] } Array of metric values e.g. [{ name: "lcoms_stealing_penalty_stolenAmount", value: 150.75 },
3625
+ * { name: "lcoms_node_operator_status", value: 1 },
3626
+ * { name: "if a metric is missing", value: null }]
3627
+ */
3628
+ async fetchCsmMetrics ( ) {
3629
+ try {
3630
+ // Retrieve service information to ensure the service is available
3631
+ const serviceInfos = await this . getServiceInfos ( "LCOMService" ) ;
3632
+ if ( serviceInfos . length < 1 ) {
3633
+ return [ ] ;
3634
+ }
3635
+
3636
+ const queries = {
3637
+ lcoms_stealing_penalty_stolenAmount : "lcoms_stealing_penalty_stolenAmount" ,
3638
+ lcoms_node_operator_status : "lcoms_node_operator_status" ,
3639
+ lcoms_current_bond : "lcoms_current_bond" ,
3640
+ lcoms_required_bond : "lcoms_required_bond" ,
3641
+ lcoms_current_bond_shares : "lcoms_current_bond_shares" ,
3642
+ lcoms_required_bond_shares : "lcoms_required_bond_shares" ,
3643
+ lcoms_unbonded_keys : "lcoms_unbonded_keys" ,
3644
+ lcoms_required_bond_st_eth : "lcoms_required_bond_st_eth" ,
3645
+ lcoms_total_added_keys : "lcoms_total_added_keys" ,
3646
+ lcoms_total_withdrawn_keys : "lcoms_total_withdrawn_keys" ,
3647
+ lcoms_total_deposited_keys : "lcoms_total_deposited_keys" ,
3648
+ lcoms_total_vetted_keys : "lcoms_total_vetted_keys" ,
3649
+ lcoms_stuck_validators_count : "lcoms_stuck_validators_count" ,
3650
+ lcoms_depositable_validators_count : "lcoms_depositable_validators_count" ,
3651
+ lcoms_target_limit : "lcoms_target_limit" ,
3652
+ lcoms_target_limit_mode : "lcoms_target_limit_mode" ,
3653
+ lcoms_total_exited_keys : "lcoms_total_exited_keys" ,
3654
+ lcoms_enqueued_count : "lcoms_enqueued_count" ,
3655
+ lcoms_target_validators_count : "lcoms_target_validators_count" ,
3656
+ lcoms_refunded_validators_count : "lcoms_refunded_validators_count" ,
3657
+ lcoms_stuck_penalty_end_timestamp : "lcoms_stuck_penalty_end_timestamp" ,
3658
+ lcoms_total_exited_validators : "lcoms_total_exited_validators" ,
3659
+ lcoms_total_deposited_validators : "lcoms_total_deposited_validators" ,
3660
+ lcoms_fee_to_distribute : "lcoms_fee_to_distribute" ,
3661
+ lcoms_fee_distributed : "lcoms_fee_distributed" ,
3662
+ lcoms_fee_distributed_value : "lcoms_fee_distributed_value" ,
3663
+ lcoms_exit_request_timestamp : "lcoms_exit_request_timestamp" ,
3664
+ } ;
3665
+
3666
+ // Create promises to fetch all metric data from Prometheus
3667
+ const queryPromises = Object . entries ( queries ) . map ( ( [ key , query ] ) => {
3668
+ return this . queryPrometheus ( encodeURIComponent ( query ) ) . then ( ( result ) => ( { key, result } ) ) ;
3669
+ } ) ;
3670
+
3671
+ // Wait for all Prometheus queries to resolve
3672
+ const results = await Promise . all ( queryPromises ) ;
3673
+
3674
+ // Process results and extract metric values, ensuring missing metrics return null
3675
+ const metrics = Object . keys ( queries ) . map ( ( key ) => {
3676
+ const metric = results . find ( ( m ) => m . key === key ) ;
3677
+ if ( ! metric || metric . result . status !== "success" || ! metric . result . data . result || metric . result . data . result . length === 0 ) {
3678
+ return { name : key , value : null } ;
3679
+ }
3680
+
3681
+ const metricData = metric . result . data . result [ 0 ] ;
3682
+ if ( ! metricData || ! metricData . value || metricData . value . length < 2 ) {
3683
+ return { name : key , value : null } ;
3684
+ }
3685
+
3686
+ // Parse the metric value from Prometheus response
3687
+ return { name : key , value : parseFloat ( metricData . value [ 1 ] ) } ;
3688
+ } ) ;
3689
+
3690
+ return metrics ;
3691
+ } catch ( error ) {
3692
+ log . error ( "Fetching CSM Metrics Failed:\n" + error ) ;
3693
+ return [ ] ;
3694
+ }
3695
+ }
3696
+
3621
3697
/**
3622
3698
* Will gather metrics from Prometheus and evaluate.
3623
3699
* If thresholds are exceeded, an alert will be generated and added to the retuned array.
0 commit comments