###Http終結點報表
Metrics.NET具有通過HTTP終結點爲指標服務的能力。
啓動一個Http監聽器:
Metric.Config.WithHttpEndpoint("http://localhost:1234/");
運行應用並在瀏覽器中打開 http://localhost:1234/。
如果你使用NancyFx,參見NancyAdapter。
如果你的應用宿主是IIS或任何OWIN兼容的服務器,OWINAdapter是一個更好的選擇。
默認終結點
默認情況下,Metrics.NET通過健康檢查報告爲可視化應用及JSON和文本報告服務。
JSON報告可在/ v2 / json(最新版本支持上下文)或/ v1 / json(初始版本,沒有任何上下文支持)上提供。 / json將根據請求的accept頭中定義的接受的MIME類型提供/ v1 / json或/ v2 / json。 / text提供人可讀的文本報告。運行狀況可以從/ health或/ v1 / health中得到。
可視化應用程序現在在Metrics.NET.FlotVisualization中可用。
自定義終結點
終結點指標報告格式可自定義,通過鏈接調用MetricsEndpointReports.WithEndpointReport來進行配置。
Metric.Config.WithHttpEndpoint("http://localhost:1234/", config => config
.WithEndpointReport("sample", (d, h, r) => new MetricsEndpointResponse("sample", "text/plain")));
構建新報告一個簡單的方式是爲MetricsEndpointReports提供一個擴展方法,其內部調用MetricsEndpointReports.WithEndpointReport。然後通過以下代碼容易的進行配置,不用再通過在配置塊中建立響應工廠:
Metric.Config.WithHttpEndpoint("http://localhost:1234/", config => config
.WithMyCustomEndpointReport("sample"/* any other parameters */));