Skip to content

Commit

Permalink
feat: update hrd
Browse files Browse the repository at this point in the history
  • Loading branch information
phnx47 committed Jul 14, 2024
1 parent 34680f6 commit 87ebfb7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Prometheus.Client.Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
using Microsoft.AspNetCore.Mvc;
using Prometheus.Client;

namespace WebHttpRequestDurations.Controllers;
namespace HttpRequestDurations.Controllers;

[Route("[controller]")]
public class CounterController : Controller
{
private readonly ICounter _counter;
private readonly ICounter _counterTs;
private readonly IMetricFamily<ICounter, ValueTuple<string, string>> _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();
}
}
}
24 changes: 24 additions & 0 deletions src/HttpRequestDurations/Controllers/HistogramController.cs
Original file line number Diff line number Diff line change
@@ -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<IHistogram, ValueTuple<string>> _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();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>WebHttpRequestDurations</RootNamespace>
<InvariantGlobalization>true</InvariantGlobalization>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prometheus.Client" Version="5.2.0" />
<PackageReference Include="Prometheus.Client.AspNetCore" Version="5.0.0" />
<PackageReference Include="Prometheus.Client.DependencyInjection" Version="1.4.0" />
<PackageReference Include="Prometheus.Client.HttpRequestDurations" Version="3.6.0" />
<PackageReference Include="Prometheus.Client.HttpRequestDurations" Version="3.6.0.131-g1e3d7fa" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace WebHttpRequestDurations;
namespace HttpRequestDurations;

public class Program
{
Expand All @@ -16,4 +16,4 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Prometheus.Client.DependencyInjection;
using Prometheus.Client.HttpRequestDurations;

namespace WebHttpRequestDurations;
namespace HttpRequestDurations;

public class Startup
{
Expand All @@ -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();
Expand All @@ -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<string, Func<string>>
{
{
Expand All @@ -69,4 +66,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
endpoints.MapControllers();
});
}
}
}
28 changes: 0 additions & 28 deletions src/WebHttpRequestDurations_3.1/Controllers/HistogramController.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/WebHttpRequestDurations_3.1/appsettings.Development.json

This file was deleted.

10 changes: 0 additions & 10 deletions src/WebHttpRequestDurations_3.1/appsettings.json

This file was deleted.

0 comments on commit 87ebfb7

Please sign in to comment.