HttpReports は .NET Core で開発された APM 監視システムで、MIT オープンソースライセンスを使用しています。主な機能は、統計、分析、可視化、監視、トレースなどであり、マイクロサービス環境での使用に適しています。
公式サイト:https://www.yuque.com/httpreports/docs/uyaiil
主な機能
- インターフェース呼び出し指標分析
- 複数サービスノードのデータ集約分析
- 遅いリクエスト、エラーリクエストの分析
- インターフェース呼び出しログの検索
- 複数タイプのアラート監視
- HTTP、Grpc 呼び出し分析
- 分散トレース
- 複数データベース対応、統合が容易
- プログラム性能監視
ステップ 1
VS を開き、新しい.NET プロジェクトを作成します。ここでは.NET Core Web API を使用してデモを行います。
ステップ 2
NuGet を使用して MHttpReports.Dashboard パッケージと HttpReports.SqlServer をインストールします。

ステップ 3
appsetting.json を設定します。
{
"HttpReportsDashboard": {
"ExpireDay": 3,
"Storage": {
"ConnectionString": "Server=10.1.30.252;Database=GEISDB;user id=sa;password=Mg2021;",
"DeferSecond": 10,
"DeferThreshold": 100
},
"Check": {
"Mode": "Self",
"Switch": true,
"Endpoint": "",
"Range": "500,2000"
},
"Mail": {
"Server": "smtp.163.com",
"Port": 465,
"Account": "HttpReports@qq.com",
"Password": "*******",
"EnableSsL": true,
"Switch": true
}
}
}
パラメータ説明:
- ExpireDay - データの有効期限(日数)、デフォルトは 3 日。HttpReports は期限切れデータを自動的に削除します。
- Storage - ストレージ情報
- DeferSecond - バッチデータ登録の秒数。推奨値:5-60
- DeferThreshold - バッチデータ登録の件数。推奨値:100-1000
- Mail - メール情報。監視を設定する場合、アラートメールを送信できます。
- Check - ヘルスチェック設定。詳細は「ヘルスチェック」ページを参照。
ステップ 4
Startup を設定します。
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReportsDashboard().AddSQLServerStorage();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReportsDashboard();
}
Dashboard プログラムを起動します。問題がなければ、Dashboard のログインページにリダイレクトされます。

デフォルトアカウント:admin
パスワード:123456
これで Dashboard の可視化はできましたが、データがありません。サービスプログラムに HttpReports を追加して情報を収集する必要があります。
ステップ 5
新しい WebAPI プロジェクト UserService を作成し、ユーザーサービスとして使用します。次に HttpReports、HttpReports.Transport.Http をインストールします。

ステップ 6
Services の Appsettings.json を編集し、簡単に設定します。
{
"HttpReports": {
"Transport": {
"CollectorAddress": "http://localhost:5000/",
"DeferSecond": 10,
"DeferThreshold": 100
},
"Server": "http://localhost:7000",
"Service": "User",
"Switch": true,
"RequestFilter": ["/api/health/*", "/HttpReports*"],
"WithRequest": true,
"WithResponse": true,
"WithCookie": true,
"WithHeader": true
}
}
パラメータ説明:
Transport -
CollectorAddress - データ送信先アドレス。Dashboard プロジェクトのアドレスを設定します。
DeferSecond - バッチデータ登録の秒数。推奨値:5-60
DeferThreshold - バッチデータ登録の件数。推奨値:100-300
Server - サービスのアドレス
Service - サービスの名前
Switch - データ収集の有効/無効
RequestFilter - データフィルター。
*を使用して曖昧一致WithRequest - インターフェースの入力パラメータを記録するかどうか
WithResponse - インターフェースの出力パラメータを記録するかどうか
WithCookie - Cookie 情報を記録するかどうか
WithHeader - リクエストヘッダー情報を記録するかどうか
最後のステップ
次に UserService プロジェクトの Startup.cs ファイルを編集します。
app.UseHttpReports(); は Configure メソッドの一番上に配置することを推奨します。
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReports().AddHttpTransport();
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReports();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
UserService のインターフェースをリフレッシュし、Dashboard ページに戻ると、データが表示されているはずです。

まとめ
このブログでは、HttpReports を使用したインターフェース統計、分析、可視化、監視、トレースなどについて説明しました。気に入っていただけたら、フォローをお願いします。