From 87ebfb79d7c713429fe1c4c22386b52ecd7df96f Mon Sep 17 00:00:00 2001 From: Serge K Date: Sun, 14 Jul 2024 14:04:48 +0700 Subject: [PATCH] feat: update hrd --- Prometheus.Client.Examples.sln | 2 +- .../Controllers/CounterController.cs | 10 +++---- .../Controllers/HistogramController.cs | 24 ++++++++++++++++ .../HttpRequestDurations.csproj} | 6 ++-- .../Program.cs | 4 +-- .../Startup.cs | 7 ++--- .../Controllers/HistogramController.cs | 28 ------------------- .../appsettings.Development.json | 9 ------ .../appsettings.json | 10 ------- 9 files changed, 36 insertions(+), 64 deletions(-) rename src/{WebHttpRequestDurations_3.1 => HttpRequestDurations}/Controllers/CounterController.cs (92%) create mode 100644 src/HttpRequestDurations/Controllers/HistogramController.cs rename src/{WebHttpRequestDurations_3.1/WebHttpRequestDurations_3.1.csproj => HttpRequestDurations/HttpRequestDurations.csproj} (68%) rename src/{WebHttpRequestDurations_3.1 => HttpRequestDurations}/Program.cs (92%) rename src/{WebHttpRequestDurations_3.1 => HttpRequestDurations}/Startup.cs (86%) delete mode 100644 src/WebHttpRequestDurations_3.1/Controllers/HistogramController.cs delete mode 100644 src/WebHttpRequestDurations_3.1/appsettings.Development.json delete mode 100644 src/WebHttpRequestDurations_3.1/appsettings.json diff --git a/Prometheus.Client.Examples.sln b/Prometheus.Client.Examples.sln index d2a77f3..2494a98 100644 --- a/Prometheus.Client.Examples.sln +++ b/Prometheus.Client.Examples.sln @@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks", "src\HealthC EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore_6.0", "src\AspNetCore_6.0\AspNetCore_6.0.csproj", "{297EA5CD-C468-40CA-A97C-8A5DC28CF701}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebHttpRequestDurations_3.1", "src\WebHttpRequestDurations_3.1\WebHttpRequestDurations_3.1.csproj", "{83246BAD-85BA-4532-84BF-70D18B7FF66A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpRequestDurations", "src\HttpRequestDurations\HttpRequestDurations.csproj", "{83246BAD-85BA-4532-84BF-70D18B7FF66A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebMetricPusher_3.1", "src\WebMetricPusher_3.1\WebMetricPusher_3.1.csproj", "{FC8559F9-D535-47C7-9964-AE754E8FB158}" EndProject diff --git a/src/WebHttpRequestDurations_3.1/Controllers/CounterController.cs b/src/HttpRequestDurations/Controllers/CounterController.cs similarity index 92% rename from src/WebHttpRequestDurations_3.1/Controllers/CounterController.cs rename to src/HttpRequestDurations/Controllers/CounterController.cs index 0960ae9..84c803f 100644 --- a/src/WebHttpRequestDurations_3.1/Controllers/CounterController.cs +++ b/src/HttpRequestDurations/Controllers/CounterController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Prometheus.Client; -namespace WebHttpRequestDurations.Controllers; +namespace HttpRequestDurations.Controllers; [Route("[controller]")] public class CounterController : Controller @@ -10,20 +10,20 @@ public class CounterController : Controller private readonly ICounter _counter; private readonly ICounter _counterTs; private readonly IMetricFamily> _conterLabel; - + public CounterController(IMetricFactory metricFactory) { _counter = metricFactory.CreateCounter("my_counter", "some help about this"); _conterLabel = metricFactory.CreateCounter("my_counter_label", "some help about this", ("label1","label2")); _counterTs = metricFactory.CreateCounter("my_counter_ts", "some help about this", true); } - + [HttpGet] public IActionResult Get() - { + { _counter.Inc(); _counterTs.Inc(3); _conterLabel.WithLabels(("my_label", "my_label2")).Inc(); return Ok(); } -} \ No newline at end of file +} diff --git a/src/HttpRequestDurations/Controllers/HistogramController.cs b/src/HttpRequestDurations/Controllers/HistogramController.cs new file mode 100644 index 0000000..f4f4c10 --- /dev/null +++ b/src/HttpRequestDurations/Controllers/HistogramController.cs @@ -0,0 +1,24 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Prometheus.Client; + +namespace HttpRequestDurations.Controllers; + +[Route("[controller]")] +public class HistogramController : Controller +{ + private readonly IMetricFamily> _histogram; + + public HistogramController(IMetricFactory metricFactory) + { + _histogram = metricFactory.CreateHistogram("test_hist", "help_text", ValueTuple.Create("params1")); + } + + [HttpGet] + public IActionResult Get() + { + _histogram.WithLabels("test1").Observe(1); + _histogram.WithLabels("test2").Observe(2); + return Ok(); + } +} diff --git a/src/WebHttpRequestDurations_3.1/WebHttpRequestDurations_3.1.csproj b/src/HttpRequestDurations/HttpRequestDurations.csproj similarity index 68% rename from src/WebHttpRequestDurations_3.1/WebHttpRequestDurations_3.1.csproj rename to src/HttpRequestDurations/HttpRequestDurations.csproj index 691ffab..fed245f 100644 --- a/src/WebHttpRequestDurations_3.1/WebHttpRequestDurations_3.1.csproj +++ b/src/HttpRequestDurations/HttpRequestDurations.csproj @@ -1,13 +1,11 @@ - netcoreapp3.1 - WebHttpRequestDurations - true + net6.0 - + diff --git a/src/WebHttpRequestDurations_3.1/Program.cs b/src/HttpRequestDurations/Program.cs similarity index 92% rename from src/WebHttpRequestDurations_3.1/Program.cs rename to src/HttpRequestDurations/Program.cs index f6cd9dd..8440665 100644 --- a/src/WebHttpRequestDurations_3.1/Program.cs +++ b/src/HttpRequestDurations/Program.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; -namespace WebHttpRequestDurations; +namespace HttpRequestDurations; public class Program { @@ -16,4 +16,4 @@ public static IHostBuilder CreateHostBuilder(string[] args) => { webBuilder.UseStartup(); }); -} \ No newline at end of file +} diff --git a/src/WebHttpRequestDurations_3.1/Startup.cs b/src/HttpRequestDurations/Startup.cs similarity index 86% rename from src/WebHttpRequestDurations_3.1/Startup.cs rename to src/HttpRequestDurations/Startup.cs index a23f39e..d2c63af 100644 --- a/src/WebHttpRequestDurations_3.1/Startup.cs +++ b/src/HttpRequestDurations/Startup.cs @@ -9,7 +9,7 @@ using Prometheus.Client.DependencyInjection; using Prometheus.Client.HttpRequestDurations; -namespace WebHttpRequestDurations; +namespace HttpRequestDurations; public class Startup { @@ -20,14 +20,12 @@ public Startup(IConfiguration configuration) public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMetricFactory(); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); @@ -52,7 +50,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { new Regex(@"\/[0-9]{1,}(?![a-z])"), "/id" } }; - // Just for example. Not for Production q.CustomLabels = new Dictionary> { { @@ -69,4 +66,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) endpoints.MapControllers(); }); } -} \ No newline at end of file +} diff --git a/src/WebHttpRequestDurations_3.1/Controllers/HistogramController.cs b/src/WebHttpRequestDurations_3.1/Controllers/HistogramController.cs deleted file mode 100644 index 9e810a1..0000000 --- a/src/WebHttpRequestDurations_3.1/Controllers/HistogramController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Microsoft.AspNetCore.Mvc; -using Prometheus.Client; - -namespace WebHttpRequestDurations.Controllers -{ - - - - [Route("[controller]")] - public class HistogramController : Controller - { - private readonly IMetricFamily> _histogram; - - public HistogramController(IMetricFactory metricFactory) - { - _histogram = metricFactory.CreateHistogram("test_hist", "help_text", ValueTuple.Create("params1")); - } - - [HttpGet] - public IActionResult Get() - { - _histogram.WithLabels("test1").Observe(1); - _histogram.WithLabels("test2").Observe(2); - return Ok(); - } - } -} diff --git a/src/WebHttpRequestDurations_3.1/appsettings.Development.json b/src/WebHttpRequestDurations_3.1/appsettings.Development.json deleted file mode 100644 index 8983e0f..0000000 --- a/src/WebHttpRequestDurations_3.1/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/src/WebHttpRequestDurations_3.1/appsettings.json b/src/WebHttpRequestDurations_3.1/appsettings.json deleted file mode 100644 index d9d9a9b..0000000 --- a/src/WebHttpRequestDurations_3.1/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*" -}