Add Labels to Metrics with Device Names

This commit is contained in:
Michal 2024-10-24 15:03:46 +01:00
parent 0885b10f1c
commit 6e36ad54fc

View File

@ -27,6 +27,7 @@ namespace PrometheusExporterEdenic
private readonly string _orgid;
private readonly string _apimainurl = "https://api.edenic.io/api/v1";
private string _devicename;
public string DeviceName => _devicename;
public string DeviceId { get; private set; }
public int ph { get; private set; }
public int temperature { get; private set; }
@ -201,9 +202,18 @@ namespace PrometheusExporterEdenic
});
});
var ph = Metrics.CreateGauge("edenic_ph", "Edenic ph");
var temperature = Metrics.CreateGauge("edenic_temperature", "Edenic temperature");
var ec = Metrics.CreateGauge("edenic_ec", "Edenic EC");
var phGauge = Metrics.CreateGauge("edenic_ph", "Edenic ph", new GaugeConfiguration
{
LabelNames = new[] { "device_name" }
});
var temperatureGauge = Metrics.CreateGauge("edenic_temperature", "Edenic temperature", new GaugeConfiguration
{
LabelNames = new[] { "device_name" }
});
var ecGauge = Metrics.CreateGauge("edenic_ec", "Edenic EC", new GaugeConfiguration
{
LabelNames = new[] { "device_name" }
});
string EDENIC_API_TOKEN = Environment.GetEnvironmentVariable("EDENIC_API_TOKEN");
string EDENIC_ORG_ID = Environment.GetEnvironmentVariable("EDENIC_ORG_ID");
@ -217,9 +227,9 @@ namespace PrometheusExporterEdenic
while (true)
{
await client.GetTelemetry();
ph.Set(client.ph / 100.0); // Convert back to float
temperature.Set(client.temperature / 100.0); // Convert back to float
ec.Set(client.ec / 100.0); // Convert back to float
phGauge.WithLabels(client.DeviceName).Set(client.ph / 100.0);
temperatureGauge.WithLabels(client.DeviceName).Set(client.temperature / 100.0);
ecGauge.WithLabels(client.DeviceName).Set(client.ec / 100.0);
await Task.Delay(60000);
}
});