diff --git a/README.md b/README.md index 0a6bf90bf..d515b737d 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,11 @@ You should also be able to authenticate with the in-cluster service account using the `InClusterConfig` function shown below. ## Monitoring -There is optional built-in metric generation for prometheus client metrics. -The exported metrics are: +Metrics are built in to HttpClient using System.Diagnostics.DiagnosticsSource. +https://learn.microsoft.com/en-us/dotnet/core/diagnostics/built-in-metrics-system-net -* `k8s_dotnet_request_total` - Counter of request, broken down by HTTP Method -* `k8s_dotnet_response_code_total` - Counter of responses, broken down by HTTP Method and response code -* `k8s_request_latency_seconds` - Latency histograms broken down by method, api group, api version and resource kind - -There is an example integrating these monitors in the examples/prometheus directory. +There are many ways these metrics can be consumed/exposed but that decision is up to the application, not KubernetesClient itself. +https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-collection ## Sample Code diff --git a/examples/prometheus/Prometheus.cs b/examples/prometheus/Prometheus.cs deleted file mode 100755 index fc7baa7b5..000000000 --- a/examples/prometheus/Prometheus.cs +++ /dev/null @@ -1,29 +0,0 @@ -using k8s; -using Prometheus; -using System; -using System.Threading; - -namespace prom -{ - internal class Prometheus - { - private static void Main(string[] args) - { - var config = KubernetesClientConfiguration.BuildDefaultConfig(); - var handler = new PrometheusHandler(); - IKubernetes client = new Kubernetes(config, handler); - - var server = new MetricServer(hostname: "localhost", port: 1234); - server.Start(); - - Console.WriteLine("Making requests!"); - while (true) - { - client.CoreV1.ListNamespacedPod("default"); - client.CoreV1.ListNode(); - client.AppsV1.ListNamespacedDeployment("default"); - Thread.Sleep(1000); - } - } - } -} diff --git a/examples/prometheus/prometheus.csproj b/examples/prometheus/prometheus.csproj deleted file mode 100755 index 52e6553de..000000000 --- a/examples/prometheus/prometheus.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - Exe - - - diff --git a/src/KubernetesClient/KubernetesClient.csproj b/src/KubernetesClient/KubernetesClient.csproj index 3c480fd54..e32d6d70b 100644 --- a/src/KubernetesClient/KubernetesClient.csproj +++ b/src/KubernetesClient/KubernetesClient.csproj @@ -10,7 +10,6 @@ - @@ -22,4 +21,4 @@ OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> - \ No newline at end of file + diff --git a/src/KubernetesClient/PrometheusHandler.cs b/src/KubernetesClient/PrometheusHandler.cs deleted file mode 100644 index c74abe460..000000000 --- a/src/KubernetesClient/PrometheusHandler.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Prometheus; -using System.Net.Http; - -namespace k8s -{ - public class PrometheusHandler : DelegatingHandler - { - private const string PREFIX = "k8s_dotnet"; - private readonly Counter requests = Metrics.CreateCounter( - $"{PREFIX}_request_total", "Number of requests sent by this client", - new CounterConfiguration - { - LabelNames = new[] { "method" }, - }); - - private readonly Histogram requestLatency = Metrics.CreateHistogram( - $"{PREFIX}_request_latency_seconds", "Latency of requests sent by this client", - new HistogramConfiguration - { - LabelNames = new[] { "verb", "group", "version", "kind" }, - }); - - private readonly Counter responseCodes = Metrics.CreateCounter( - $"{PREFIX}_response_code_total", "Number of response codes received by the client", - new CounterConfiguration - { - LabelNames = new[] { "method", "code" }, - }); - - private readonly Gauge activeRequests = Metrics.CreateGauge( - $"{PREFIX}_active_requests", "Number of requests currently in progress", - new GaugeConfiguration - { - LabelNames = new[] { "method" }, - }); - - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - if (request == null) - { - throw new ArgumentNullException(nameof(request)); - } - - var digest = KubernetesRequestDigest.Parse(request); - requests.WithLabels(digest.Verb).Inc(); - using (activeRequests.WithLabels(digest.Verb).TrackInProgress()) - using (requestLatency.WithLabels(digest.Verb, digest.ApiGroup, digest.ApiVersion, digest.Kind).NewTimer()) - { - var resp = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); - responseCodes.WithLabels(request.Method.ToString(), ((int)resp.StatusCode).ToString()).Inc(); - return resp; - } - } - } -}