Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Agent Metrics #263

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Consul.Test/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,5 +993,12 @@ 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);
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
72 changes: 72 additions & 0 deletions Consul/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,68 @@ public enum LogLevel
Err
}

/// <summary>
/// Metrics represents the metrics returned by the Agent API
/// </summary>
public class Metrics
{
public string Timestamp { get; set; }
public List<Gauge> Gauges { get; set; }
public List<Point> Points { get; set; }
public List<Counter> Counters { get; set; }
public List<Sample> Samples { get; set; }
}

/// <summary>
/// Guage represents a Guage metric
/// </summary>
public class Gauge
{
public string Name { get; set; }
public double Value { get; set; }
public Dictionary<string, string> Labels { get; set; }
}

/// <summary>
/// Point represents a Point metric
/// </summary>
public class Point
{
public string Name { get; set; }
public double Value { get; set; }
public Dictionary<string, string> Labels { get; set; }
}

/// <summary>
/// Counter represents a Counter metric
/// </summary>
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<string, string> Labels { get; set; }
}

/// <summary>
/// Sample represents a Sample metric
/// </summary>
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<string, string> Labels { get; set; }
}

/// <summary>
/// Agent can be used to query the Agent endpoints
/// </summary>
Expand Down Expand Up @@ -879,6 +941,16 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
}

/// <summary>
/// GetAgentMetrics returns the metrics of the local agent
/// </summary>
/// <param name="ct"></param>
/// <returns>Metrics of the local agent</returns>
public async Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default)
{
return await _client.Get<Metrics>("/v1/agent/metrics").Execute(ct).ConfigureAwait(false);
}
}

public partial class ConsulClient : IConsulClient
Expand Down
2 changes: 1 addition & 1 deletion Consul/Interfaces/IAgentEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface IAgentEndpoint
Task<QueryResult<string>> GetWorstLocalServiceHealth(string serviceName, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);

Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
Task<WriteResult> Leave(string node, CancellationToken ct = default);
Task<WriteResult> Reload(string node, CancellationToken ct = default);
}
Expand Down
Loading