在代码中使用就比较简单了
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 gaugeprocess_windows_num_threads 25# HELP dotnet_totalmemory Total known allocated memory# TYPE dotnet_totalmemory gaugedotnet_totalmemory 7489568# HELP process_windows_processid Process ID# TYPE process_windows_processid gaugeprocess_windows_processid 3820# HELP process_windows_virtual_bytes Process virtual memory size# TYPE process_windows_virtual_bytes gaugeprocess_windows_virtual_bytes 2217671860224# HELP process_windows_open_handles Number of open handles# TYPE process_windows_open_handles gaugeprocess_windows_open_handles 496# HELP process_windows_private_bytes Process private memory size# TYPE process_windows_private_bytes gaugeprocess_windows_private_bytes 69120000# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.# TYPE process_cpu_seconds_total counterprocess_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 gaugeprocess_start_time_seconds 1541669168.15852# HELP dotnet_collection_count_total GC collection count# TYPE dotnet_collection_count_total counterdotnet_collection_count_total{generation="2"} 0dotnet_collection_count_total{generation="1"} 0dotnet_collection_count_total{generation="0"} 0# HELP dotnet_collection_errors_total Total number of errors that occured during collections# TYPE dotnet_collection_errors_total counterdotnet_collection_errors_total 0# HELP process_windows_working_set Process working set# TYPE process_windows_working_set gaugeprocess_windows_working_set 68280320