前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Prometheus采集ASP.NET Core指标信息

Prometheus采集ASP.NET Core指标信息

作者头像
yoyofx
发布2023-05-26 17:21:20
9630
发布2023-05-26 17:21:20
举报
文章被收录于专栏:ASP.NETCore

ASP.NET Core Prometheus 集成&采集&展示

本文实例代码

https://github.com/yoyofx/dotnet-metric-prometheus

创建 ASP.NET Core Web API

此项目在.NET 7 环境创建

代码语言:javascript
复制
dotnet new webapi

添加包

代码语言:javascript
复制
dotnet add package prometheus-net.AspNetCore --version 8.0.0

添加指标端点代码

program.cs

代码语言:javascript
复制
...
...
app.UseMetricServer();
...
...

完整文件内容如下:

代码语言:javascript
复制
using Prometheus;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseMetricServer();

app.UseAuthorization();

app.MapControllers();

app.Run();

运行 http://localhost:5069/metrics 端口号替换成运行端口

端点指标内容如下:

代码语言:javascript
复制
# HELP process_private_memory_bytes Process private memory size
# TYPE process_private_memory_bytes gauge
process_private_memory_bytes 0
# HELP system_runtime_alloc_total (B) Allocation Rate
# TYPE system_runtime_alloc_total counter
system_runtime_alloc_total 1230088
# HELP system_runtime_gen_0_size (B) Gen 0 Size
# TYPE system_runtime_gen_0_size gauge
system_runtime_gen_0_size 0
# HELP system_runtime_poh_size (B) POH (Pinned Object Heap) Size
# TYPE system_runtime_poh_size gauge
system_runtime_poh_size 0
# HELP prometheus_net_meteradapter_instruments_connected Number of instruments that are currently connected to the adapter.
# TYPE prometheus_net_meteradapter_instruments_connected gauge
prometheus_net_meteradapter_instruments_connected 0
# HELP system_runtime_gc_committed (MB) GC Committed Bytes
# TYPE system_runtime_gc_committed gauge
system_runtime_gc_committed 0
# HELP process_working_set_bytes Process working set
# TYPE process_working_set_bytes gauge
process_working_set_bytes 118489088
# HELP system_runtime_threadpool_thread_count ThreadPool Thread Count
# TYPE system_runtime_threadpool_thread_count gauge
system_runtime_threadpool_thread_count 5
# HELP system_net_sockets_bytes_received Bytes Received
# TYPE system_net_sockets_bytes_received gauge
system_net_sockets_bytes_received 10322
# HELP system_runtime_gen_1_gc_count_total Gen 1 GC Count
# TYPE system_runtime_gen_1_gc_count_total counter
system_runtime_gen_1_gc_count_total 0
# HELP system_runtime_il_bytes_jitted (B) IL Bytes Jitted
# TYPE system_runtime_il_bytes_jitted gauge
system_runtime_il_bytes_jitted 283857
# HELP microsoft_aspnetcore_hosting_current_requests Current Requests
# TYPE microsoft_aspnetcore_hosting_current_requests gauge
microsoft_aspnetcore_hosting_current_requests 0
# HELP microsoft_aspnetcore_server_kestrel_current_tls_handshakes Current TLS Handshakes
# TYPE microsoft_aspnetcore_server_kestrel_current_tls_handshakes gauge
microsoft_aspnetcore_server_kestrel_current_tls_handshakes 0
# HELP system_net_sockets_datagrams_received Datagrams Received
# TYPE system_net_sockets_datagrams_received gauge
system_net_sockets_datagrams_received 0
# HELP microsoft_aspnetcore_server_kestrel_total_connections Total Connections
# TYPE microsoft_aspnetcore_server_kestrel_total_connections gauge
microsoft_aspnetcore_server_kestrel_total_connections 5
# HELP system_net_sockets_incoming_connections_established Incoming Connections Established
# TYPE system_net_sockets_incoming_connections_established gauge
system_net_sockets_incoming_connections_established 5

采集

与上篇Java的文章类同。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-05-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ASP.NET Core Prometheus 集成&采集&展示
    • 本文实例代码
      • 创建 ASP.NET Core Web API
        • 添加包
          • program.cs
        • 采集
        相关产品与服务
        Prometheus 监控服务
        Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档