From 36b04ae242be5bd820b7aee4e8fc111b8b0aacf1 Mon Sep 17 00:00:00 2001 From: Dmitry Belousov Date: Sun, 15 Sep 2024 23:48:25 +0300 Subject: [PATCH 1/4] Rename metrics with base units. Add spool initial weight. --- spoolman/prometheus/metrics.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/spoolman/prometheus/metrics.py b/spoolman/prometheus/metrics.py index d3e978978..349c28a8e 100644 --- a/spoolman/prometheus/metrics.py +++ b/spoolman/prometheus/metrics.py @@ -14,16 +14,21 @@ PREFIX = "spoolman" -SPOOL_PRICE = Gauge(f"{PREFIX}_spool_price", "Total Spool price", ["spool_id", "filament_id"]) -SPOOL_USED_WEIGHT = Gauge(f"{PREFIX}_spool_weight_used", "Spool Used Weight", ["spool_id", "filament_id"]) +SPOOL_PRICE = Gauge(f"{PREFIX}_spool_price_total", "Total Spool price", ["spool_id", "filament_id"]) +SPOOL_INITIAL_WEIGHT = Gauge( + f"{PREFIX}_spool_initial_weight_grams", + "Spool Net weight in gram", + ["spool_id", "filament_id"], +) +SPOOL_USED_WEIGHT = Gauge(f"{PREFIX}_spool_weight_used_grams", "Spool Used weight in gram", ["spool_id", "filament_id"]) FILAMENT_INFO = Gauge( f"{PREFIX}_filament_info", "Filament information", ["filament_id", "vendor", "name", "material", "color"], ) -FILAMENT_DENSITY = Gauge(f"{PREFIX}_filament_density", "Density of filament", ["filament_id"]) -FILAMENT_DIAMETER = Gauge(f"{PREFIX}_filament_diameter", "Diameter of filament", ["filament_id"]) -FILAMENT_WEIGHT = Gauge(f"{PREFIX}_filament_weight", "Net weight of filament", ["filament_id"]) +FILAMENT_DENSITY = Gauge(f"{PREFIX}_filament_density", "Density of filament gram/cm3", ["filament_id"]) +FILAMENT_DIAMETER = Gauge(f"{PREFIX}_filament_diameter_meters", "Diameter of filament", ["filament_id"]) +FILAMENT_WEIGHT = Gauge(f"{PREFIX}_filament_weight_grams", "Net weight of filament", ["filament_id"]) logger = logging.getLogger(__name__) @@ -55,6 +60,8 @@ async def spool_metrics(db: AsyncSession) -> None: for row in result: if row.price is not None: SPOOL_PRICE.labels(str(row.id), str(row.filament_id)).set(row.price) + if row.initial_weight is not None: + SPOOL_INITIAL_WEIGHT.labels(str(row.id), str(row.filament_id)).set(row.initial_weight) SPOOL_USED_WEIGHT.labels(str(row.id), str(row.filament_id)).set(row.used_weight) @@ -84,6 +91,6 @@ async def filament_metrics(db: AsyncSession) -> None: row.color_hex, ).set(1) FILAMENT_DENSITY.labels(str(row.id)).set(row.density) - FILAMENT_DIAMETER.labels(str(row.id)).set(row.diameter) + FILAMENT_DIAMETER.labels(str(row.id)).set(row.diameter / 1000) if row.weight is not None: FILAMENT_WEIGHT.labels(str(row.id)).set(row.weight) From 4ee34f67d13084f402090b203fc7c74099d07069 Mon Sep 17 00:00:00 2001 From: Dmitry Belousov Date: Thu, 12 Dec 2024 22:38:11 +0300 Subject: [PATCH 2/4] Add spool initial weight. Change some descriptions. --- spoolman/prometheus/metrics.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spoolman/prometheus/metrics.py b/spoolman/prometheus/metrics.py index d3e978978..3963c57fc 100644 --- a/spoolman/prometheus/metrics.py +++ b/spoolman/prometheus/metrics.py @@ -15,13 +15,18 @@ PREFIX = "spoolman" SPOOL_PRICE = Gauge(f"{PREFIX}_spool_price", "Total Spool price", ["spool_id", "filament_id"]) -SPOOL_USED_WEIGHT = Gauge(f"{PREFIX}_spool_weight_used", "Spool Used Weight", ["spool_id", "filament_id"]) +SPOOL_USED_WEIGHT = Gauge(f"{PREFIX}_spool_weight_used", "Spool Used Weight in grams", ["spool_id", "filament_id"]) +SPOOL_INITIAL_WEIGHT = Gauge( + f"{PREFIX}_spool_initial_weight", + "Spool Net weight in grams", + ["spool_id", "filament_id"], +) FILAMENT_INFO = Gauge( f"{PREFIX}_filament_info", "Filament information", ["filament_id", "vendor", "name", "material", "color"], ) -FILAMENT_DENSITY = Gauge(f"{PREFIX}_filament_density", "Density of filament", ["filament_id"]) +FILAMENT_DENSITY = Gauge(f"{PREFIX}_filament_density", "Density of filament gram/cm3", ["filament_id"]) FILAMENT_DIAMETER = Gauge(f"{PREFIX}_filament_diameter", "Diameter of filament", ["filament_id"]) FILAMENT_WEIGHT = Gauge(f"{PREFIX}_filament_weight", "Net weight of filament", ["filament_id"]) @@ -55,6 +60,8 @@ async def spool_metrics(db: AsyncSession) -> None: for row in result: if row.price is not None: SPOOL_PRICE.labels(str(row.id), str(row.filament_id)).set(row.price) + if row.initial_weight is not None: + SPOOL_INITIAL_WEIGHT.labels(str(row.id), str(row.filament_id)).set(row.initial_weight) SPOOL_USED_WEIGHT.labels(str(row.id), str(row.filament_id)).set(row.used_weight) From 385d9bb3da8b57d063c4ec4fe7e9d14a09ab28f1 Mon Sep 17 00:00:00 2001 From: Dmitry Belousov Date: Thu, 12 Dec 2024 22:40:35 +0300 Subject: [PATCH 3/4] Add spool initial weight. Change some descriptions. --- spoolman/prometheus/metrics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spoolman/prometheus/metrics.py b/spoolman/prometheus/metrics.py index 3963c57fc..3995ff6db 100644 --- a/spoolman/prometheus/metrics.py +++ b/spoolman/prometheus/metrics.py @@ -91,6 +91,5 @@ async def filament_metrics(db: AsyncSession) -> None: row.color_hex, ).set(1) FILAMENT_DENSITY.labels(str(row.id)).set(row.density) - FILAMENT_DIAMETER.labels(str(row.id)).set(row.diameter) if row.weight is not None: FILAMENT_WEIGHT.labels(str(row.id)).set(row.weight) From b37c19eb9e0ff4cf60c64a6f41d557154f31b30e Mon Sep 17 00:00:00 2001 From: Dmitry Belousov Date: Thu, 12 Dec 2024 22:42:22 +0300 Subject: [PATCH 4/4] diameter is missed --- spoolman/prometheus/metrics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spoolman/prometheus/metrics.py b/spoolman/prometheus/metrics.py index 3995ff6db..3963c57fc 100644 --- a/spoolman/prometheus/metrics.py +++ b/spoolman/prometheus/metrics.py @@ -91,5 +91,6 @@ async def filament_metrics(db: AsyncSession) -> None: row.color_hex, ).set(1) FILAMENT_DENSITY.labels(str(row.id)).set(row.density) + FILAMENT_DIAMETER.labels(str(row.id)).set(row.diameter) if row.weight is not None: FILAMENT_WEIGHT.labels(str(row.id)).set(row.weight)