diff --git a/Consul.Test/AgentTest.cs b/Consul.Test/AgentTest.cs
index d3e3d3e4d..88452c2fb 100644
--- a/Consul.Test/AgentTest.cs
+++ b/Consul.Test/AgentTest.cs
@@ -993,5 +993,16 @@ await _client.Agent.ServiceRegister(new AgentServiceRegistration
Assert.Single(actual);
Assert.Equal(checkName, actual.Values.First().Name);
}
+
+ [Fact]
+ public async Task Agent_Metrics()
+ {
+ var agentMetrics = await _client.Agent.GetAgentMetrics();
+ Assert.NotNull(agentMetrics.Response.Timestamp);
+ Assert.NotNull(agentMetrics.Response.Counters);
+ Assert.NotNull(agentMetrics.Response.Gauges);
+ Assert.NotNull(agentMetrics.Response.Points);
+ Assert.NotNull(agentMetrics.Response.Samples);
+ }
}
}
diff --git a/Consul/Agent.cs b/Consul/Agent.cs
index b81e6708c..86ac63cfc 100644
--- a/Consul/Agent.cs
+++ b/Consul/Agent.cs
@@ -430,6 +430,68 @@ public enum LogLevel
Err
}
+ ///
+ /// Metrics represents the metrics returned by the Agent API
+ ///
+ public class Metrics
+ {
+ public string Timestamp { get; set; }
+ public List Gauges { get; set; }
+ public List Points { get; set; }
+ public List Counters { get; set; }
+ public List Samples { get; set; }
+ }
+
+ ///
+ /// Guage represents a Guage metric
+ ///
+ public class Gauge
+ {
+ public string Name { get; set; }
+ public double Value { get; set; }
+ public Dictionary Labels { get; set; }
+ }
+
+ ///
+ /// Point represents a Point metric
+ ///
+ public class Point
+ {
+ public string Name { get; set; }
+ public double Value { get; set; }
+ public Dictionary Labels { get; set; }
+ }
+
+ ///
+ /// Counter represents a Counter metric
+ ///
+ public class Counter
+ {
+ public string Name { get; set; }
+ public long Count { get; set; }
+ public double Sum { get; set; }
+ public double Min { get; set; }
+ public double Max { get; set; }
+ public double Mean { get; set; }
+ public double Stddev { get; set; }
+ public Dictionary Labels { get; set; }
+ }
+
+ ///
+ /// Sample represents a Sample metric
+ ///
+ public class Sample
+ {
+ public string Name { get; set; }
+ public long Count { get; set; }
+ public double Sum { get; set; }
+ public double Min { get; set; }
+ public double Max { get; set; }
+ public double Mean { get; set; }
+ public double Stddev { get; set; }
+ public Dictionary Labels { get; set; }
+ }
+
///
/// Agent can be used to query the Agent endpoints
///
@@ -879,6 +941,16 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
}
+
+ ///
+ /// GetAgentMetrics returns the metrics of the local agent
+ ///
+ ///
+ /// Metrics of the local agent
+ public async Task> GetAgentMetrics(CancellationToken ct = default)
+ {
+ return await _client.Get("/v1/agent/metrics").Execute(ct).ConfigureAwait(false);
+ }
}
public partial class ConsulClient : IConsulClient
diff --git a/Consul/Interfaces/IAgentEndpoint.cs b/Consul/Interfaces/IAgentEndpoint.cs
index a3a4cb04b..22529cdc7 100644
--- a/Consul/Interfaces/IAgentEndpoint.cs
+++ b/Consul/Interfaces/IAgentEndpoint.cs
@@ -62,7 +62,7 @@ public interface IAgentEndpoint
Task> GetWorstLocalServiceHealth(string serviceName, CancellationToken ct = default);
Task> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
-
+ Task> GetAgentMetrics(CancellationToken ct = default);
Task Leave(string node, CancellationToken ct = default);
Task Reload(string node, CancellationToken ct = default);
}