Skip to content

Commit

Permalink
put prometheus behind a node-monitoring flag
Browse files Browse the repository at this point in the history
  • Loading branch information
qu0b committed Sep 11, 2023
1 parent 83a3d7e commit a16337c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/node_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def perform_action(self):


class PrometheusAction(TestnetMonitorAction):
def __init__(self):
super().__init__(name="prometheus", interval=TestnetMonitorActionInterval.EVERY_SLOT)
def __init__(self, interval: TestnetMonitorActionInterval):
super().__init__(name="prometheus", interval=interval)

def perform_action(self) -> None:
queries = {
Expand All @@ -183,20 +183,20 @@ def _one_request(key, query):
params=dict(query=query)
)
if resp.status_code != 200:
logging.info(f"prometheus query {query} responded with status code {resp.status_code}, skipping")
logging.debug(f"prometheus query {query} responded with status code {resp.status_code}, skipping")
return

result_all = resp.json()
if (result_status := result_all["status"]) != "success":
logging.info(f"prometheus query {query} has result status {result_status!r}, skipping")
logging.debug(f"prometheus query {query} has result status {result_status!r}, skipping")
return

return key, result_all["data"]

with ThreadPoolExecutor(max_workers=8) as exc:
results = dict(exc.map(lambda item: _one_request(*item), queries.items()))

logging.info(
logging(
json.dumps({"prometheus_metrics": results})
)

Expand Down Expand Up @@ -240,7 +240,8 @@ def build_testnet_monitor(self, cli_args) -> TestnetMonitor:
"peers": PeersMonitorAction,
"blob": BlobMonitorAction,
"execution_availability": HeadsMonitorExecutionAvailabilityCheckAction,
"consensus_availability": HeadsMonitorConsensusAvailabilityCheckAction
"consensus_availability": HeadsMonitorConsensusAvailabilityCheckAction,
"prometheus": PrometheusAction,
}

intervals = {
Expand All @@ -256,6 +257,7 @@ def build_testnet_monitor(self, cli_args) -> TestnetMonitor:
raise Exception(f"Unknown metric: {metric}")
if interval not in intervals:
raise Exception(f"Unknown interval: {interval}")


_interval = intervals[interval]
testnet_monitor.add_action(
Expand All @@ -268,8 +270,6 @@ def build_testnet_monitor(self, cli_args) -> TestnetMonitor:
)
)

testnet_monitor.add_action(PrometheusAction())

return testnet_monitor

def get_testnet_info_str(self) -> str:
Expand Down

0 comments on commit a16337c

Please sign in to comment.