0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MiniAPI(二十七):Metrics

Posted at

アプリケーションの各種Metricsは、アプリケーションの健康と安定な運行を保証する基礎であり、特に可用性が求められるアプリケーションにとっては重要です。本記事では、prometheus-netというサードパーティのライブラリを紹介します。
prometheus-netの動作原理は、アプリケーション内に計測ポイントを埋め込み、prometheusを通じてデータを収集し、grafanaを使って収集したデータを表示することです。そこでまず、prometheusとgrafanaをダウンロードする必要があります。デモのため、ここでは両アプリケーションのWindows版をダウンロードします。ダウンロード先は以下の通りです:
Prometheusのダウンロード先:
https://prometheus.io/download/
Grafanaのダウンロード先:
https://grafana.com/grafana/download?platform=windows
次に、miniapiプロジェクトを作成し、NuGetパッケージをインストールします:

Install-Package prometheus-net.AspNetCore

miniapiプロジェクトでprometheusのデフォルト指標を使用することは非常に簡単です。以下のようにします:

using Prometheus;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/test", () => {
    return "OK";
});
app.MapMetrics();
app.UseHttpMetrics();
app.Run();

アプリケーションのURLをprometheusの設定ファイル(prometheus.yml)に設定する必要があります。以下の画像のようにします:
alt 画像
これで、prometheusの設定が完了し、起動することができます。
次に、Grafanaの設定を行います。まずデータソースを作成します:
alt 画像
次に、2つのダッシュボード10195と10427を作成します:
alt 画像
これでアプリケーションにアクセスできるようになり、両方のダッシュボードを開いて、監視指標を見ることができます。
ASP.NET Core指示
alt 画像
アプリケーションシステム指標
alt 画像
本記事では、miniapiがprometheusを導入し、prometheusとgrafanaとの連携について簡単に説明しました。すべての指標はデフォルトのものであり、ビジネス指標が必要な場合は、以下のシリーズを参照してください:
ASP.NET Core監視- Prometheusの導入(その1)
ASP.NET Core監視- Prometheusの導入(その2)
ASP.NET Core監視- Prometheusの導入(その3)
ASP.NET Core監視- Prometheusの導入(その4)
ASP.NET Core監視- Prometheusの導入(その5)
ASP.NET Core監視- Prometheusの導入(その6)
デフォルト指標の詳細情報が知りたい場合は、以下のシリーズを参照してください:
dotnetのcounter
dotnetのcountersの説明(その1)
dotnetのcountersの説明(その2)
dotnetのcountersの説明(その3)
アプリ内でのmoniter
カスタムEventSource(その1)EventCounter
カスタムEventSource(その2)PollingCounter
カスタムEventSource(その3)IncrementingEventCounter
カスタムEventSource(その4)IncrementingPollingCounter

(Translated by GPT)

元のリンク:https://mp.weixin.qq.com/s?__biz=MzA3NDM1MzIyMQ==&mid=2247485015&idx=1&sn=64b2e276461947675532f532e42cf753&chksm=9f00597da877d06bd653fcd2a482c5042186e3916a4871bd3bde24ed902799fdb22b5c79590a&token=732480897&lang=zh_CN&poc_token=HHXd22WjhyAybn56EkXjLpGS8I8uLJHHF81DIIB7

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?