Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions graph_node_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Comment on lines +318 to +325
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably can do just one peers(), and ask for CC status instead of computeUnitsTotal.

Then you can count Active in Python. This way, it would be less load on the Indexer, and less data over the wire.

''')

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:
Expand Down
3 changes: 3 additions & 0 deletions metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +50 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
ACTIVE_PEERS = Gauge("fluence_active_peer_count", "Total count of peers in active CCs", registry=registry)
PEERS_TOTAL = Gauge("fluence_total_peer_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)
Expand Down