mirror of
https://github.com/simple-login/app.git
synced 2024-11-14 08:01:13 +01:00
0e82801512
* chore: add upcloud monitoring * Added db_role to new_relic metrics --------- Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
26 lines
837 B
Python
26 lines
837 B
Python
from monitor.metric import UpcloudMetrics
|
|
|
|
from newrelic_telemetry_sdk import GaugeMetric, MetricClient
|
|
|
|
_NEWRELIC_BASE_HOST = "metric-api.eu.newrelic.com"
|
|
|
|
|
|
class NewRelicClient:
|
|
def __init__(self, license_key: str):
|
|
self.__client = MetricClient(license_key=license_key, host=_NEWRELIC_BASE_HOST)
|
|
|
|
def send(self, metrics: UpcloudMetrics):
|
|
batch = []
|
|
|
|
for metric in metrics.metrics:
|
|
for record in metric.records:
|
|
batch.append(
|
|
GaugeMetric(
|
|
name=f"upcloud.db.{metric.metric_name}",
|
|
value=record.value,
|
|
tags={"host": record.label, "db_role": record.db_role},
|
|
)
|
|
)
|
|
|
|
response = self.__client.send_batch(batch)
|
|
response.raise_for_status()
|