Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Collect latest block seen by subgraph #14

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
21 changes: 21 additions & 0 deletions graph_node_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def connect_graph_node(graph_node_url):
raise


def get_latest_block(client):
"""Get latest block number"""
try:
query = gql('''
query {
_meta {
block {
number
}
}
}
''')
response = client.execute(query)
block = response['_meta']['block']['number']
FLUENCE_SUBGRAPH_LATEST_BLOCK.set(block)
except Exception as e:
logger.error(f"Error fetching latest block number: {e}")
raise


def get_providers(client):
"""Fetch all providers from the Graph Node."""
try:
Expand Down Expand Up @@ -213,6 +233,7 @@ def collect_deal_metrics(client, provider_id, provider_name):

def collect_metrics(graph_node, providers_to_monitor):
try:
get_latest_block(graph_node)
if providers_to_monitor:
for provider_id in providers_to_monitor:
provider_name = get_provider_name(graph_node, provider_id)
Expand Down
2 changes: 2 additions & 0 deletions metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@

FLUENCE_DEAL_ACTIVE = Gauge('fluence_network_deal_active_total','Total deals active',['provider_id','provider_name'], registry=registry)
FLUENCE_DEAL_ACTIVE_START_DATE=Gauge('fluence_network_deal_active_start_date', 'Duration of a deal', ['provider_id', 'provider_name', 'deal_id'], registry=registry)

FLUENCE_SUBGRAPH_LATEST_BLOCK = Gauge('fluence_network_subgraph_latest_block','The latest block number seen by subgraph', registry=registry)