added prometheus metrics.
This commit is contained in:
parent
d16ec173a9
commit
e7ec9b8aa6
@ -8,6 +8,7 @@
|
||||
<ItemGroup Label="Nocr">
|
||||
<PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" Version="0.6.2" />
|
||||
<PackageVersion Include="prometheus-net" Version="8.2.1" />
|
||||
<PackageVersion Include="prometheus-net.AspNetCore" Version="8.2.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Telegram">
|
||||
<PackageVersion Include="WTelegramClient" Version="4.3.4" />
|
||||
@ -24,10 +25,10 @@
|
||||
<PackageVersion Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Microsoft">
|
||||
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.4" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(MicrosoftVersion)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftVersion)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftVersion)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.4" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftVersion)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -18,6 +18,8 @@ public sealed class UpdateHandler : IUpdateHandler
|
||||
|
||||
public async Task HandleUpdate(Update update, CancellationToken cancellationToken = default)
|
||||
{
|
||||
TelegramListenerMetrics.UpdatesReceived.Inc();
|
||||
TelegramListenerMetrics.LastUpdateTimestamp.Set(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
|
||||
try
|
||||
{
|
||||
switch (update)
|
||||
@ -29,9 +31,12 @@ public sealed class UpdateHandler : IUpdateHandler
|
||||
_logger.LogInformation($"Update of type `{update.GetType().Name}` fired.");
|
||||
break;
|
||||
}
|
||||
|
||||
TelegramListenerMetrics.UpdatesProcessed.Inc();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TelegramListenerMetrics.UpdatesErrors.Inc();
|
||||
_logger.LogError(ex, "Critical error in HandleUpdate.");
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using Nocr.TelegramListener.AppServices;
|
||||
using Nocr.TelegramListener.Async.Api.Contracts.Events;
|
||||
using Nocr.TelegramListener.Core.Dates;
|
||||
using Nocr.TelegramListener.Core.Options;
|
||||
using Prometheus;
|
||||
using Rebus.Bus;
|
||||
using Rebus.Config;
|
||||
using Rebus.Routing.TypeBased;
|
||||
@ -46,6 +47,12 @@ public class Startup
|
||||
// TODO: BackgroundService
|
||||
bus.Advanced.Topics.Subscribe(Constants.RoutingKeys.Subscriptions).GetAwaiter().GetResult();
|
||||
|
||||
app.UseHealthChecks("/health");
|
||||
app.UseHttpMetrics();
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapHealthChecks("/health");
|
||||
endpoints.MapMetrics();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="prometheus-net.AspNetCore" />
|
||||
<PackageReference Include="Serilog.AspNetCore" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user