通过


Orleans 仪表板

仪表板 Orleans 是基于 Web 的内置监视工具,可实时查看 Orleans 群集。 它允许你监视孤岛运行状况、粒度激活、方法调用、提醒和系统指标,而无需外部监视基础结构。

对于 Orleans 10.0,请使用官方仪表板包: Microsoft.Orleans.DashboardMicrosoft.Orleans.Dashboard.Abstractions

重要

此功能从 10.0 开始 Orleans 可用。 它目前以 预览版 提供,将来的版本中可能会更改。

Features

仪表板 Orleans 提供以下功能:

  • 群集概述:查看群集中的所有孤岛及其状态、运行时间和资源利用率。
  • 粒度监视:跟踪每个粒度类型的粒度激活、方法调用和性能指标。
  • 方法分析:分析粒度方法调用频率、延迟和错误率。
  • 提醒管理:浏览和监视群集中所有已注册的提醒。
  • 实时日志流式处理:查看群集的实时日志输出。
  • 接收器详细信息:检查各个接收器属性、计数器和粒度分布。
  • 粒度状态检查:查看单个粒度实例的当前状态。

Installation

仪表板 Orleans 分布在两个 NuGet 包中:

Package Description
Microsoft.Orleans.仪表板 包含 UI 和 API 终结点的主仪表板包
Microsoft.Orleans.Dashboard.Abstractions 集成仪表板的抽象(例如 NoProfilingAttribute

基本设置

若要将 Orleans 仪表板添加到应用程序,请在 silo 构建器上调用 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;
});
选项 类型 违约 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);
});
选项 类型 违约 Description
TraceAlways bool false true 时,即使未查询仪表板,也会持续收集概要分析数据。
DeactivationTime TimeSpan 1 分钟 非活动状态的持续时间,之后分析会自动停止。 仅在TraceAlwaysfalse时适用。

从分析中排除粒度

使用 [NoProfiling] 特性从性能分析中排除特定粒度:

using Orleans.Dashboard;

[NoProfiling]
public class HighFrequencyGrain : Grain, IHighFrequencyGrain
{
    // This grain won't be included in profiling data
}

部署模式

最简单的部署模式是将仪表板直接托管在您的 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();

重要

当使用单独的仪表板主机时,仍必须在 silo 构建器上调用 AddDashboard()。 信息孤岛需要仪表板服务来收集和提供指标数据。

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");

Troubleshooting

仪表板显示“丢失连接”消息

当仪表板无法与 Orleans 群集通信时,会发生此错误。 常见原因:

  1. Silo未启动:在访问仪表板之前,请确保OrleansSilo正在运行。
  2. 网络问题:验证仪表板主机和独立单元之间的网络连接。
  3. 群集配置错误:检查是否已正确配置群集。

性能分析数据未显示

如果粒度方法分析数据为空:

  1. 进行粒度调用:分析仅在调用粒度方法后显示数据。
  2. 检查 TraceAlways:默认情况下,分析在仪表板处于非活动状态 1 分钟后停止。 将TraceAlways = true设置为持续分析。
  3. 检查 [NoProfiling]:确保粒度未被 [NoProfiling] 属性标记。

实时跟踪终结点已禁用

如果/Trace终结点返回 403 禁止:

  • 检查是否 DashboardOptions.HideTrace 未设置为 true

另请参阅

Orleans 仪表板 是 Orleans 10.0 中引入的内置监控工具。 对于 Orleans 9.0、8.0 和 7.0,请使用非官方社区仪表板包:

Orleans 仪表板 是 Orleans 10.0 中引入的内置监控工具。 对于 Orleans 3.x,请使用非官方社区仪表板包: