diff --git a/graph_node_metrics.py b/graph_node_metrics.py index 40945af..f731b7c 100644 --- a/graph_node_metrics.py +++ b/graph_node_metrics.py @@ -312,9 +312,34 @@ def collect_graph_networks_metrics(client): logger.error(f"Error collecting graph networks: {e}") raise +def collect_active_peers_count(client): + try: + query = gql(''' + query { + active_peers:peers(where: {and: [{currentCapacityCommitment_:{status:Active}}, {provider_: {approved: true}}]}) { + computeUnitsTotal + }, + peers_total:peers(where: {and: [{provider_: {approved: true}}]}) { + computeUnitsTotal + } + } + ''') + + response = client.execute(query) + active_peers = response['active_peers'] + peers_total = response['peers_total'] + active_peers_count = len(active_peers) + peers_total_count = len(peers_total) + ACTIVE_PEERS.set(active_peers_count) + PEERS_TOTAL.set(peers_total_count) + except Exception as e: + logger.error(f"Error in collecting active peers count metrics from graph-node: {e}") + raise () + def collect_metrics(graph_node, providers_to_monitor): try: get_latest_block(graph_node) + collect_active_peers_count(graph_node) collect_graph_networks_metrics(graph_node) if providers_to_monitor: for provider_id in providers_to_monitor: diff --git a/metrics.py b/metrics.py index fc9a259..79e5181 100644 --- a/metrics.py +++ b/metrics.py @@ -47,6 +47,9 @@ EFFECTORS_TOTAL = Gauge("fluence_network_effectors_total", "Total count of effectors", registry=registry) COMMITMENT_CREATED_COUNT = Gauge("fluence_network_commitment_created_count", "Total count of CommitmentCreated events", registry=registry) +ACTIVE_PEERS = Gauge("fluence_active_peers_count", "Total count of peers in active CCs", registry=registry) +PEERS_TOTAL = Gauge("fluence_peers_total_count", "Total count of peers", registry=registry) + INFO = Info("fluence_network_info", "Info about network", registry=registry) FLUENCE_NFT_SUBGRAPH_LATEST_BLOCK = Gauge('fluence_network_nft_subgraph_latest_block','The latest block number seen by subgraph for NFT', registry=registry) NFTS_TOKENS_TOTAL = Gauge("fluence_network_nfts_tokens_total", "Total count of NFTs", registry=registry)