Orleans儀表板是一個內建的網頁監控工具,提供對叢集Orleans的即時可視性。 它讓你能監控穀倉健康狀況、穀粒啟動、方法呼叫、提醒和系統指標,而不需要外部監控基礎設施。
對於 Orleans 10.0 版本,請使用官方儀表板套件:Microsoft.Orleans.Dashboard 和 Microsoft.Orleans.Dashboard.Abstractions。
這很重要
此功能自 10.0 版本起 Orleans 提供。 目前仍處於 預覽 階段,未來版本可能會有所變動。
Features
Orleans儀表板提供以下功能:
- 叢集概述:查看叢集中所有孤島及其狀態、運作時間及資源利用率。
- 穀粒監測:追蹤穀粒活化、方法呼叫及各穀粒類型的效能指標。
- 方法分析:分析顆粒法呼叫頻率、延遲及錯誤率。
- 提醒管理:瀏覽並監控整個叢集中所有已註冊的提醒。
- 即時日誌串流:查看叢集的即時日誌輸出。
- 穀倉細節:檢查各個穀倉特性、計數器及穀粒分布。
- 穀粒狀態檢查:查看個別穀粒實例的當前狀態。
安裝
儀表板 Orleans 以兩個 NuGet 套件形式發佈:
| Package | Description |
|---|---|
| Microsoft.Orleans.儀表板 | 主儀表板套件,包含 UI 和 API 端點 |
| Microsoft.Orleans.Dashboard.Abstractions | 儀表板整合的抽象層(例如,NoProfilingAttribute) |
基本設定
要將 Orleans 儀表板加入應用程式,請在 silo builder 上呼叫 AddDashboard(),並 MapOrleansDashboard() 映射儀表板端點:
using Orleans.Dashboard;
var builder = WebApplication.CreateBuilder(args);
// Configure Orleans with the dashboard
builder.UseOrleans(siloBuilder =>
{
siloBuilder.UseLocalhostClustering();
siloBuilder.AddMemoryGrainStorageAsDefault();
// Add the dashboard services
siloBuilder.AddDashboard();
});
var app = builder.Build();
// Map dashboard endpoints at the root path
app.MapOrleansDashboard();
app.Run();
啟動應用程式後,請前往 http://localhost:5000/ (或你已設定的 URL)進入儀表板。
自訂路由前綴
你可以透過指定路由前綴,將儀表板架設在自訂路徑上:
// Map dashboard endpoints at /dashboard
app.MapOrleansDashboard(routePrefix: "/dashboard");
使用此配置,請訪問儀表板http://localhost:5000/dashboard/。
設定
儀表板選項
使用 DashboardOptions 配置儀表板行為。
siloBuilder.AddDashboard(options =>
{
// Disable the live log streaming endpoint
options.HideTrace = true;
// Set the counter update interval (minimum 1000ms)
options.CounterUpdateIntervalMs = 2000;
// Set the history buffer length for metrics
options.HistoryLength = 200;
});
| Option | 類型 | 預設 | Description |
|---|---|---|---|
HideTrace |
bool |
false |
當 true時,會停用即時日誌串流端點。 |
CounterUpdateIntervalMs |
int |
1000 |
計數器樣本之間的毫秒間隔 必須是 >= 1000。 |
HistoryLength |
int |
100 |
需要維護的歷史數據點數量,以供指標使用。 |
穀粒分析器選項
晶粒剖面儀收集方法層級的性能數據。 請使用 GrainProfilerOptions 來配置:
builder.Services.Configure<GrainProfilerOptions>(options =>
{
// Always collect profiling data, even when dashboard is inactive
options.TraceAlways = true;
// Time after which profiling stops if dashboard is inactive
options.DeactivationTime = TimeSpan.FromMinutes(5);
});
| Option | 類型 | 預設 | Description |
|---|---|---|---|
TraceAlways |
bool |
false |
當 true時,即使儀表板未被查詢,分析資料仍持續被收集。 |
DeactivationTime |
TimeSpan | 1 分鐘 | 超過不活動時間後,自動停止性能分析的時間長度。 僅當 TraceAlways 是 false 時適用。 |
排除顆粒度分析
使用屬性 [NoProfiling] 來排除特定顆粒,避免在性能分析中出現:
using Orleans.Dashboard;
[NoProfiling]
public class HighFrequencyGrain : Grain, IHighFrequencyGrain
{
// This grain won't be included in profiling data
}
部署模式
與 silo 共同主辦(建議)
最簡單的部署模式是直接將儀表板架設在你的 Orleans 孤島上。 這是大多數情況下推薦的做法:
using Orleans.Dashboard;
var builder = WebApplication.CreateBuilder(args);
builder.UseOrleans(siloBuilder =>
{
siloBuilder.UseLocalhostClustering();
siloBuilder.UseInMemoryReminderService();
siloBuilder.AddMemoryGrainStorageAsDefault();
siloBuilder.AddDashboard();
});
var app = builder.Build();
app.MapOrleansDashboard();
app.Run();
獨立儀表板主機
如果你想將儀表板與你的孤島分開運行(例如提供專用監控端點),你可以將儀表板架設在 Orleans 用戶端:
using Orleans.Configuration;
using Orleans.Dashboard;
using System.Net;
// Start the silo host
var siloHostBuilder = Host.CreateApplicationBuilder(args);
siloHostBuilder.UseOrleans(builder =>
{
builder.UseDevelopmentClustering(options =>
options.PrimarySiloEndpoint = new IPEndPoint(IPAddress.Loopback, 11111));
builder.UseInMemoryReminderService();
builder.AddMemoryGrainStorageAsDefault();
builder.ConfigureEndpoints(IPAddress.Loopback, 11111, 30000);
// Dashboard must also be added to silos
builder.AddDashboard();
});
using var siloHost = siloHostBuilder.Build();
await siloHost.StartAsync();
// Create a separate web application for the dashboard
var dashboardBuilder = WebApplication.CreateBuilder(args);
// Configure Orleans client
dashboardBuilder.UseOrleansClient(clientBuilder =>
{
clientBuilder.UseStaticClustering(options =>
options.Gateways.Add(new IPEndPoint(IPAddress.Loopback, 30000).ToGatewayUri()));
// Add dashboard services to the client
clientBuilder.AddDashboard();
});
var dashboardApp = dashboardBuilder.Build();
// Map dashboard endpoints on the client
dashboardApp.MapOrleansDashboard();
await dashboardApp.RunAsync();
await siloHost.StopAsync();
這很重要
使用獨立儀表板主機時,仍需呼叫 AddDashboard() silo 建置器。 孤島需要儀表板服務來收集並提供指標資料。
Authorization
儀表板端點支援 ASP.NET 核心授權。 使用 RequireAuthorization() 擴充方法來保護存取權限:
// Require authentication for dashboard access
app.MapOrleansDashboard()
.RequireAuthorization();
您也可以套用特定的授權政策:
// Configure authorization
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("DashboardAccess", policy =>
policy.RequireRole("Admin", "Operator"));
});
builder.Services.AddAuthentication(/* your auth configuration */);
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
// Apply the policy to dashboard endpoints
app.MapOrleansDashboard()
.RequireAuthorization("DashboardAccess");
故障排除
儀表板顯示「失去連線」訊息
此錯誤發生於儀表板無法與 Orleans 叢集通訊時。 常見原因:
- Silo 尚未啟動:在進入儀表板前,請確保你的 Orleans silo 正在運作。
- 網路問題:確認儀表板主機與孤島之間的網路連線。
- 叢集設定錯誤:檢查叢集設定是否正確。
資料分析資料未顯示
若顆粒方法剖面資料為空:
- 進行粒度呼叫:剖析僅在穀粒方法被調用後顯示資料。
-
檢查
TraceAlways:預設情況下,分析會在儀表板不活躍 1 分鐘後停止。 設定TraceAlways = true為持續分析。 -
檢查
[NoProfiling]:確保紋理未被標示[NoProfiling]屬性。
即時追蹤端點已被停用
若 /Trace 端點回傳 403 Forbidden:
- 檢查
DashboardOptions.HideTrace沒有被設定為true。
另請參閱
Orleans儀表板是內建的監控工具,於 10.0 版本Orleans中引入。 針對 Orleans 9.0、8.0 和 7.0,請使用非官方的社群儀表板套件:
- OrleansDashboard(社群):由社群維護的儀表板套件,適用於 Orleans 10.0 之前的版本。
- OpenTelemetry 整合:內建可觀測功能可在 Orleans 7.0 及以上版本中提供。 參見Orleans中的可觀察性。
Orleans儀表板是內建的監控工具,於 10.0 版本Orleans中引入。 對於 Orleans 3.x,請使用非官方的社群儀表板套件:
- OrleansDashboard(社群):由社群維護的儀表板套件,適用於 Orleans 10.0 之前的版本。