Fork me on GitHub

.NetCore下使用Prometheus实现系统监控和警报 (四)客户端代码处理

在代码中使用就比较简单了

Nuget包获取下

prometheus-net

prometheus-net.AspNetCore

然后添加中间件就行了

 app.UseMetricServer();

默认地址都是/metrics,在Prometheus中的targets就是指向了这个地址,当然如果需要认证的话需要处理,Prometheus也需要设置先关认证,这里我写在了GateWay中,允许查看下

http://localhost:5000/metrics

# HELP process_windows_num_threads Total number of threads
# TYPE process_windows_num_threads gauge
process_windows_num_threads 25
# HELP dotnet_totalmemory Total known allocated memory
# TYPE dotnet_totalmemory gauge
dotnet_totalmemory 7489568
# HELP process_windows_processid Process ID
# TYPE process_windows_processid gauge
process_windows_processid 3820
# HELP process_windows_virtual_bytes Process virtual memory size
# TYPE process_windows_virtual_bytes gauge
process_windows_virtual_bytes 2217671860224
# HELP process_windows_open_handles Number of open handles
# TYPE process_windows_open_handles gauge
process_windows_open_handles 496
# HELP process_windows_private_bytes Process private memory size
# TYPE process_windows_private_bytes gauge
process_windows_private_bytes 69120000
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 1.921875
# 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 1541669168.15852
# 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="1"} 0
dotnet_collection_count_total{generation="0"} 0
# HELP dotnet_collection_errors_total Total number of errors that occured during collections
# TYPE dotnet_collection_errors_total counter
dotnet_collection_errors_total 0
# HELP process_windows_working_set Process working set
# TYPE process_windows_working_set gauge
process_windows_working_set 68280320

 

posted @ 2018-11-08 17:28  龙码精神  阅读(1814)  评论(1编辑  收藏  举报