Zzdats.Lgp.Common.Web
10.0.9
Prefix Reserved
dotnet add package Zzdats.Lgp.Common.Web --version 10.0.9
NuGet\Install-Package Zzdats.Lgp.Common.Web -Version 10.0.9
<PackageReference Include="Zzdats.Lgp.Common.Web" Version="10.0.9" />
<PackageVersion Include="Zzdats.Lgp.Common.Web" Version="10.0.9" />
<PackageReference Include="Zzdats.Lgp.Common.Web" />
paket add Zzdats.Lgp.Common.Web --version 10.0.9
#r "nuget: Zzdats.Lgp.Common.Web, 10.0.9"
#:package Zzdats.Lgp.Common.Web@10.0.9
#addin nuget:?package=Zzdats.Lgp.Common.Web&version=10.0.9
#tool nuget:?package=Zzdats.Lgp.Common.Web&version=10.0.9
Common-Web .NET10
Common-Web repozitorijs satur kopējās lietas web projektiem (API, MVC)
Šis repozitorijs ir kā daļa no LGP .Net Core projekta.
Pakas
Pakas nosaukums: Zzdats.Lgp.Common.Web
Izmantošana
Failā Startup.cs:
ConfigureServicespievienojam:
services.AddLgpCore(Configuration.GetSection("Lgp"));
Configurepievienojam:
app.UseLgpCore();
Failā Program.cs izmantojam:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Zzdats.Audit.RestAPI
{
/// <summary>
/// Represents the current application.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point to the application.
/// </summary>
/// <param name="args">The arguments provided at start-up, if any.</param>
public static async Task Main(string[] args) => await CreateHostBuilder(args).Build().RunAsync();
/// <summary>
/// Create host builder.
/// </summary>
/// <param name="args">The arguments provided at start-up, if any.</param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseLgpCore()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseLgpCore()
.UseStartup<Startup>();
});
}
}
Failā Program.cs izmantojam priekš net6:
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Zzdats.DGC.Public.Service.Api;
await Host.CreateDefaultBuilder(args)
.UseLgpCore()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseLgpCore()
.UseStartup<Startup>();
})
.Build()
.RunAsync();
Iespējas, kas tiek pievienotas pēc noklusējuma
- Health check (
/healthz, atbild tikai par procesu — ārējās atkarības netiek pārbaudītas) - Prometheus metriku eksporta URL
/metrics - Elastic APM (
HttpDiagnosticsSubscriberunAspNetCoreDiagnosticSubscriber) - Log ierakstu veidošana ECS formātā
Pielāgošana
Papildus Elastic APM mērījumu pievienošana
ConfigureServicespievienojam:
services.AddLgpCore(Configuration.GetSection("Lgp"), opt =>
{
opt.ElasticApmDiagnosticsSubscribers.Add(new ElasticsearchDiagnosticsSubscriber());
});
Health check saturs
/healthz atbild uz vienu jautājumu: vai process spēj apkalpot HTTP. Tas atgriež {"status":"pass"} ar HTTP 200 un
neveic nevienu datu bāzes, CSSO, authority vai cita tīkla resursa izsaukumu.
Nepievienojiet šim galapunktam ārējo atkarību pārbaudes. Konteinera veselības pārbaude var tikai pārstartēt procesu, un nesasniedzamu atkarību restarts nesalabo — tā vietā tas pārvērš atkarības pārtraukumu restartu ciklā. Ja atkarība neatbild, kļūdu saņem tie pieprasījumi, kuriem tā bija vajadzīga; pieejamību mēra monitorings. Skat. API servisu veselības pārbaudes un datu bāzu savienojumu vadlīnijas.
Konfigurācijas piemērs
{
"Lgp": {
"Log": {
"File": "./logs/log.log",
"Console": true,
"ConsoleTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
"ExcludePaths": "/healthz,/metrics"
},
"Infrastructure": {
"Health": {
"Enabled": true
},
"Metrics": {
"Enabled": true,
"Authorization": "Bearer <token>"
}
}
},
}
Prometheus eksporteris
Lai ieslēgtu prometheus metrikas eksportēšanu /metrics URL, Lgp:Infrastructure:Metrics:Enabled jābūt true.
Lai aizsargātu šo endpoint, Lgp:Infrastructure:Metrics:Authorization jānorādā kāds Authorization header tiks padods pieprasījumā no prometheus, pretējā gadījumā /metrics atbildēs ar 401 Unauthorized.
Attiecīgi prometheus metriku ievācējam (scraper) jānorāda šis Authorization header.
Konfigurācijas piemērs:
{
"Lgp": {
"Infrastructure": {
"Metrics": {
"Enabled": true,
"Authorization": "Bearer <token>"
}
}
}
}
Autorizēta izsaukuma piemērs:
GET /metrics HTTP/1.1
Host: localhost:5000
Authorization: Bearer <token>
# HELP dotnet_gc_pause_ratio The percentage of time the process spent paused for garbage collection
# TYPE dotnet_gc_pause_ratio gauge
dotnet_gc_pause_ratio 0
# HELP dotnet_sockets_bytes_received_total The total number of bytes received over the network
# TYPE dotnet_sockets_bytes_received_total counter
dotnet_sockets_bytes_received_total 23384
# HELP process_working_set_bytes Process working set
# TYPE process_working_set_bytes gauge
process_working_set_bytes 149901312
# HELP dotnet_gc_heap_size_bytes The current size of all heaps (only updated after a garbage collection)
# TYPE dotnet_gc_heap_size_bytes gauge
dotnet_gc_heap_size_bytes{gc_generation="2"} 0
dotnet_gc_heap_size_bytes{gc_generation="loh"} 0
dotnet_gc_heap_size_bytes{gc_generation="0"} 0
dotnet_gc_heap_size_bytes{gc_generation="1"} 0
# HELP dotnet_jit_method_total Total number of methods compiled by the JIT compiler
# TYPE dotnet_jit_method_total counter
dotnet_jit_method_total 4573
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1713525913.5505784
# HELP dotnet_collection_count_total GC collection count
# TYPE dotnet_collection_count_total counter
dotnet_collection_count_total{generation="2"} 0
dotnet_collection_count_total{generation="0"} 0
dotnet_collection_count_total{generation="1"} 0
# HELP http_requests_received_total Provides the count of HTTP requests that have been processed by the ASP.NET Core pipeline.
# TYPE http_requests_received_total counter
http_requests_received_total{code="200",method="GET",controller="Account",action="GetExternalAuthorizations",endpoint="internal-api/account/external_authorization"} 1
http_requests_received_total{code="200",method="GET",controller="Account",action="GetCaptchaState",endpoint="internal-api/account/getcaptchastate"} 1
http_requests_received_total{code="200",method="POST",controller="Token",action="RefreshToken",endpoint="refresh_token"} 2
http_requests_received_total{code="200",method="GET",controller="WsFedAuthentication",action="Get",endpoint="authentication/external/icon/wsfederation"} 1
http_requests_received_total{code="101",method="GET",controller="",action="",endpoint=""} 1
http_requests_received_total{code="304",method="GET",controller="",action="",endpoint=""} 2
http_requests_received_total{code="200",method="GET",controller="Account",action="State",endpoint="internal-api/account"} 1
http_requests_received_total{code="200",method="GET",controller="",action="",endpoint=""} 1
# HELP process_cpu_count The number of processor cores available to this process.
# TYPE process_cpu_count gauge
process_cpu_count 12
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.96875
# HELP dotnet_gc_collection_count_total Counts the number of garbage collections that have occurred, broken down by generation number.
# TYPE dotnet_gc_collection_count_total counter
dotnet_gc_collection_count_total{gc_generation="2"} 0
dotnet_gc_collection_count_total{gc_generation="0"} 0
dotnet_gc_collection_count_total{gc_generation="1"} 0
# HELP dotnet_gc_memory_total_available_bytes The upper limit on the amount of physical memory .NET can allocate to
# TYPE dotnet_gc_memory_total_available_bytes gauge
dotnet_gc_memory_total_available_bytes 34029125632
# HELP dotnet_threadpool_timer_count The number of timers active
# TYPE dotnet_threadpool_timer_count gauge
dotnet_threadpool_timer_count 27
# HELP dotnet_sockets_bytes_sent_total The total number of bytes sent over the network
# TYPE dotnet_sockets_bytes_sent_total counter
dotnet_sockets_bytes_sent_total 66451
# HELP dotnet_contention_total The number of locks contended
# TYPE dotnet_contention_total counter
dotnet_contention_total 31
# HELP dotnet_sockets_connections_established_outgoing_total The total number of outgoing established TCP connections
# TYPE dotnet_sockets_connections_established_outgoing_total counter
dotnet_sockets_connections_established_outgoing_total 6
# HELP http_request_duration_seconds The duration of HTTP requests processed by an ASP.NET Core application.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_sum{code="200",method="GET",controller="",action="",endpoint=""} 9.2418655
http_request_duration_seconds_count{code="200",method="GET",controller="",action="",endpoint=""} 1
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.001"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.002"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.004"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.008"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.016"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.032"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.064"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.128"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.256"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="0.512"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="1.024"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="2.048"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="4.096"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="8.192"} 0
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="16.384"} 1
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="32.768"} 1
http_request_duration_seconds_bucket{code="200",method="GET",controller="",action="",endpoint="",le="+Inf"} 1
# HELP dotnet_sockets_connections_established_incoming_total The total number of incoming established TCP connections
# TYPE dotnet_sockets_connections_established_incoming_total counter
dotnet_sockets_connections_established_incoming_total 6
# HELP dotnet_build_info Build information about prometheus-net.DotNetRuntime and the environment
# TYPE dotnet_build_info gauge
dotnet_build_info{version="4.4.0.0",target_framework=".NETCoreApp,Version=v6.0",runtime_version=".NET 6.0.28",os_version="Microsoft Windows 10.0.22631",process_architecture="X64",gc_mode="Server"} 1
# HELP dotnet_total_memory_bytes Total known allocated memory
# TYPE dotnet_total_memory_bytes gauge
dotnet_total_memory_bytes 52096400
# HELP dotnet_exceptions_total Count of exceptions thrown
# TYPE dotnet_exceptions_total counter
dotnet_exceptions_total 56
# HELP dotnet_gc_allocated_bytes_total The total number of bytes allocated on the managed heap
# TYPE dotnet_gc_allocated_bytes_total counter
dotnet_gc_allocated_bytes_total 12093424
# HELP dotnet_threadpool_queue_length Measures the queue length of the thread pool. Values greater than 0 indicate a backlog of work for the threadpool to process.
# TYPE dotnet_threadpool_queue_length histogram
dotnet_threadpool_queue_length_sum 1
dotnet_threadpool_queue_length_count 17
dotnet_threadpool_queue_length_bucket{le="0"} 16
dotnet_threadpool_queue_length_bucket{le="1"} 17
dotnet_threadpool_queue_length_bucket{le="10"} 17
dotnet_threadpool_queue_length_bucket{le="100"} 17
dotnet_threadpool_queue_length_bucket{le="1000"} 17
dotnet_threadpool_queue_length_bucket{le="+Inf"} 17
# HELP process_open_handles Number of open handles
# TYPE process_open_handles gauge
process_open_handles 1013
# HELP process_private_memory_bytes Process private memory size
# TYPE process_private_memory_bytes gauge
process_private_memory_bytes 146071552
# HELP dotnet_threadpool_throughput_total The total number of work items that have finished execution in the thread pool
# TYPE dotnet_threadpool_throughput_total counter
dotnet_threadpool_throughput_total 1116
# HELP process_num_threads Total number of threads
# TYPE process_num_threads gauge
process_num_threads 55
# HELP dotnet_jit_il_bytes Total bytes of IL compiled by the JIT compiler
# TYPE dotnet_jit_il_bytes gauge
dotnet_jit_il_bytes 585215
# HELP http_requests_in_progress The number of requests currently in progress in the ASP.NET Core pipeline. One series without controller/action label values counts all in-progress requests, with separate series existing for each controller-action pair.
# TYPE http_requests_in_progress gauge
http_requests_in_progress{method="POST",controller="",action="",endpoint=""} 0
http_requests_in_progress{method="GET",controller="",action="",endpoint=""} 4
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2223227957248
# HELP dotnet_threadpool_num_threads The number of active threads in the thread pool
# TYPE dotnet_threadpool_num_threads gauge
dotnet_threadpool_num_threads 24
IDAuth adaptera autentifikācija
Šī bibliotēka satur arī autentifikācijas apstrādātāju.
Apstrādātājs noraida talonu, ja IDAuth sesija nav aktīva (active: false), un izlaiž JWT talonus (talonus, kas satur punktu), lai tos apstrādātu JWT shēma.
Lai izmantotu IDAuth autentifikācijas talonus:
- Jāpievieno konfigurācijā IDAuth URL ceļā
Lgp:Infrastructure:IdAuth:Urlvai ar vides mainīgoLGP__INFRASTRUCTURE__IDAUTH__URL - Jāpievieno konfigurācija Startup.cs failā pie ConfigureServices
services.AddAuthentication(opt =>
{
opt.DefaultScheme = IDAuthDefaults.AuthenticationScheme;
})
.AddScheme<IDAuthAuthenticationOptions, IDAuthAuthenticationHandler>("IDAuth", options =>
{
options.AuthUrl = Configuration.GetValue<string>("Lgp:Infrastructure:IdAuth:Url");
});
Var izmantot arī vairākus autentifikācijas apstrādātājus, lai varētu izmantot IDauth talonu un ja tas neapstrādājas, tad caurskrist (fallback) uz JWT taloniem.
Piemērs:
services.AddAuthentication(opt =>
{
opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(opt =>
{
opt.Authority = Configuration.GetValue<string>("Lgp:Infrastructure:Authority:Url");
opt.RequireHttpsMetadata = !Environment.IsDevelopment();
opt.TokenValidationParameters = new TokenValidationParameters()
{
ValidateAudience = false,
};
}).AddScheme<IDAuthAuthenticationOptions, IDAuthAuthenticationHandler>("IDAuth", options =>
{
options.AuthUrl = Configuration.GetValue<string>("Lgp:Infrastructure:IdAuth:Url");
});
un tad kontroliera klasē var norādīt abus.
[ApiController]
[Authorize(AuthenticationSchemes =JwtBearerDefaults.AuthenticationScheme + "," + IDAuthDefaults.AuthenticationScheme)]
public class BusinessEventController : ApiControllerBase
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Destructurama.Attributed (>= 5.3.0)
- prometheus-net (>= 8.2.1)
- prometheus-net.AspNetCore (>= 8.2.1)
- prometheus-net.DotNetRuntime (>= 4.4.1)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Serilog.Sinks.File (>= 7.0.0)
- Zzdats.Lgp.Common.Apm (>= 10.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Zzdats.Lgp.Common.Web:
| Package | Downloads |
|---|---|
|
Zzdats.Lgp.Common.Mvc
MVC LGP common components and infrastructure integration |
GitHub repositories
This package is not used by any popular GitHub repositories.