.NET6之MiniAPI(二十七):Metrics
應用的各種Metrics是保證應用健康穩定運行的基礎,特別對于一些可用性有所要求的應用,本文介紹prometheus-net這個三方指示庫。
prometheus-net的工作原理是,在應用內部埋點,通過prometheus采集數據,然后通過grafana把采集到的數據展現出來,所以這里首先要下載prometheus和grafana,因為是demo,這里下載兩個應用的windows版本。具體下載地址如下:
Prometheus下載地址:
https://prometheus.io/download/
Grafana下載地址:
https://grafana.com/grafana/download?platform=windows
接下來創建miniapi項目,引入NuGet包:
Install-Package?prometheus-net.AspNetCore
在miniapi項目中使用prometheus的默認指標很簡單,如下:
這里要把應用的url配置到promethues的配置文件(prometheus.yml)中,如下圖:
這時prometheus就配置好了,可以啟動了。
接下來配置grafana,首先創建數據源:
再創建兩個dashboard:10195和10427
這里就可以訪問應用了,打開兩個dashboard,就可以看到監控指標了。
asp.net core指示
應用系統指標
本篇中介簡單介紹了一下miniapi引入prometheus,并且與prometheus和grafana的協調工作,所有指標都是默認指標,如果需要業務指標,請參看系列:
asp.net?core監控—引入Prometheus(一)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(一)
asp.net?core監控—引入Prometheus(二)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(二)
asp.net?core監控—引入Prometheus(三)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(三)
asp.net?core監控—引入Prometheus(四)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(四)
asp.net?core監控—引入Prometheus(五)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(五)
asp.net?core監控—引入Prometheus(六)
桂素偉,公眾號:桂跡asp.net core監控—引入Prometheus(六)
如果想了解默認指標的具體詳情,請參見系列:
dotnet中的counter
桂素偉,公眾號:桂跡dotnet中的counter
dotnet中的counters說明(一)
桂素偉,公眾號:桂跡dotnet中的counters說明(一)
dotnet中的counters說明(二)
桂素偉,公眾號:桂跡dotnet中的counters說明(二)
dotnet中的counters說明(三)
桂素偉,公眾號:桂跡dotnet中的counters說明(三)
應用內moniter
桂素偉,公眾號:桂跡應用內moniter
自定義EventSource(一)EventCounter
桂素偉,公眾號:桂跡自定義EventSource(一)EventCounter
自定義EventSource(二)PollingCounter
桂素偉,公眾號:桂跡自定義EventSource(二)PollingCounter
自定義EventSource(三)IncrementingEventCounter
桂素偉,公眾號:桂跡自定義EventSource(三)IncrementingEventCounter
自定義EventSource(四)IncrementingPollingCounter
桂素偉,公眾號:桂跡自定義EventSource(四)IncrementingPollingCounter
總結
以上是生活随笔為你收集整理的.NET6之MiniAPI(二十七):Metrics的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Blazor University (5
- 下一篇: microdot - 一个开源 .NET