@@ -16,7 +16,7 @@ use prometheus::TextEncoder;
1616use reqwest:: StatusCode ;
1717use tower_http:: cors:: CorsLayer ;
1818
19- use crate :: box_kind:: PoolBox ;
19+ use crate :: box_kind:: { OracleBox , PoolBox } ;
2020use crate :: monitor:: check_oracle_health;
2121use crate :: monitor:: check_pool_health;
2222use crate :: monitor:: OracleHealth ;
@@ -127,6 +127,21 @@ static MY_ORACLE_BOX_HEIGHT: Lazy<IntGaugeVec> = Lazy::new(|| {
127127 m
128128} ) ;
129129
130+ static MY_ORACLE_CLAIMABLE_REWARDS : Lazy < IntGauge > = Lazy :: new ( || {
131+ let m = IntGauge :: with_opts (
132+ Opts :: new (
133+ "oracle_claimable_rewards" ,
134+ "The amount of claimable rewards for this oracle" ,
135+ )
136+ . namespace ( "ergo" )
137+ . subsystem ( "oracle" ) ,
138+ )
139+ . unwrap ( ) ;
140+
141+ prometheus:: register ( Box :: new ( m. clone ( ) ) ) . expect ( "Failed to register" ) ;
142+ m
143+ } ) ;
144+
130145static ALL_ORACLE_BOX_HEIGHT : Lazy < IntGaugeVec > = Lazy :: new ( || {
131146 let m = IntGaugeVec :: new (
132147 Opts :: new (
@@ -142,6 +157,21 @@ static ALL_ORACLE_BOX_HEIGHT: Lazy<IntGaugeVec> = Lazy::new(|| {
142157 m
143158} ) ;
144159
160+ static ALL_ORACLE_CLAIMABLE_REWARDS : Lazy < IntGaugeVec > = Lazy :: new ( || {
161+ let m = IntGaugeVec :: new (
162+ Opts :: new (
163+ "all_oracle_claimable_rewards" ,
164+ "The amount of claimable rewards for all oracles" ,
165+ )
166+ . namespace ( "ergo" )
167+ . subsystem ( "oracle" ) ,
168+ & [ "oracle_address" ] ,
169+ )
170+ . unwrap ( ) ;
171+ prometheus:: register ( Box :: new ( m. clone ( ) ) ) . expect ( "Failed to register" ) ;
172+ m
173+ } ) ;
174+
145175static ACTIVE_ORACLE_BOX_HEIGHT : Lazy < IntGaugeVec > = Lazy :: new ( || {
146176 let m = IntGaugeVec :: new (
147177 Opts :: new (
@@ -270,6 +300,40 @@ fn update_reward_tokens_in_buyback_box(oracle_pool: Arc<OraclePool>) {
270300 }
271301}
272302
303+ fn update_oracle_claimable_reward_tokens ( pool_health : & PoolHealth ) {
304+ for oracle in & pool_health. details . all_oracle_boxes {
305+ let reward_tokens = oracle. reward_tokens ;
306+
307+ if reward_tokens > 0 {
308+ let claimable_tokens = reward_tokens - 1 ;
309+ ALL_ORACLE_CLAIMABLE_REWARDS
310+ . with_label_values ( & [ & oracle. address . to_base58 ( ) ] )
311+ . set ( claimable_tokens as i64 ) ;
312+ } else {
313+ ALL_ORACLE_CLAIMABLE_REWARDS
314+ . with_label_values ( & [ & oracle. address . to_base58 ( ) ] )
315+ . set ( 0 ) ;
316+ }
317+ }
318+ }
319+
320+ fn update_my_claimable_reward_tokens ( oracle_pool : Arc < OraclePool > ) {
321+ if let Some ( oracle_box) = oracle_pool
322+ . get_local_datapoint_box_source ( )
323+ . get_local_oracle_datapoint_box ( )
324+ . ok ( )
325+ . flatten ( )
326+ {
327+ let num_tokens = * oracle_box. reward_token ( ) . amount . as_u64 ( ) ;
328+ if num_tokens == 0 {
329+ MY_ORACLE_CLAIMABLE_REWARDS . set ( num_tokens as i64 )
330+ } else {
331+ let claimable_tokens = num_tokens - 1 ;
332+ MY_ORACLE_CLAIMABLE_REWARDS . set ( claimable_tokens as i64 )
333+ }
334+ }
335+ }
336+
273337pub fn update_metrics ( oracle_pool : Arc < OraclePool > ) -> Result < ( ) , anyhow:: Error > {
274338 let node_api = NodeApi :: new (
275339 ORACLE_SECRETS . node_api_key . clone ( ) ,
@@ -302,7 +366,9 @@ pub fn update_metrics(oracle_pool: Arc<OraclePool>) -> Result<(), anyhow::Error>
302366 let wallet_balance: i64 = node_api. node . wallet_nano_ergs_balance ( ) ? as i64 ;
303367 ORACLE_NODE_WALLET_BALANCE . set ( wallet_balance) ;
304368 POOL_BOX_REWARD_TOKEN_AMOUNT . set ( pool_box. reward_token ( ) . amount . into ( ) ) ;
305- update_reward_tokens_in_buyback_box ( oracle_pool) ;
369+ update_reward_tokens_in_buyback_box ( oracle_pool. clone ( ) ) ;
370+ update_my_claimable_reward_tokens ( oracle_pool) ;
371+ update_oracle_claimable_reward_tokens ( & pool_health) ;
306372 Ok ( ( ) )
307373}
308374
0 commit comments