Add Labels to Metrics with Device Names
This commit is contained in:
parent
0885b10f1c
commit
6e36ad54fc
22
Program.cs
22
Program.cs
@ -27,6 +27,7 @@ namespace PrometheusExporterEdenic
|
|||||||
private readonly string _orgid;
|
private readonly string _orgid;
|
||||||
private readonly string _apimainurl = "https://api.edenic.io/api/v1";
|
private readonly string _apimainurl = "https://api.edenic.io/api/v1";
|
||||||
private string _devicename;
|
private string _devicename;
|
||||||
|
public string DeviceName => _devicename;
|
||||||
public string DeviceId { get; private set; }
|
public string DeviceId { get; private set; }
|
||||||
public int ph { get; private set; }
|
public int ph { get; private set; }
|
||||||
public int temperature { get; private set; }
|
public int temperature { get; private set; }
|
||||||
@ -201,9 +202,18 @@ namespace PrometheusExporterEdenic
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var ph = Metrics.CreateGauge("edenic_ph", "Edenic ph");
|
var phGauge = Metrics.CreateGauge("edenic_ph", "Edenic ph", new GaugeConfiguration
|
||||||
var temperature = Metrics.CreateGauge("edenic_temperature", "Edenic temperature");
|
{
|
||||||
var ec = Metrics.CreateGauge("edenic_ec", "Edenic EC");
|
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_API_TOKEN = Environment.GetEnvironmentVariable("EDENIC_API_TOKEN");
|
||||||
string EDENIC_ORG_ID = Environment.GetEnvironmentVariable("EDENIC_ORG_ID");
|
string EDENIC_ORG_ID = Environment.GetEnvironmentVariable("EDENIC_ORG_ID");
|
||||||
@ -217,9 +227,9 @@ namespace PrometheusExporterEdenic
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
await client.GetTelemetry();
|
await client.GetTelemetry();
|
||||||
ph.Set(client.ph / 100.0); // Convert back to float
|
phGauge.WithLabels(client.DeviceName).Set(client.ph / 100.0);
|
||||||
temperature.Set(client.temperature / 100.0); // Convert back to float
|
temperatureGauge.WithLabels(client.DeviceName).Set(client.temperature / 100.0);
|
||||||
ec.Set(client.ec / 100.0); // Convert back to float
|
ecGauge.WithLabels(client.DeviceName).Set(client.ec / 100.0);
|
||||||
await Task.Delay(60000);
|
await Task.Delay(60000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user