共用方式為


Orleans 可觀察性

可檢視性是分散式系統最重要的層面之一。 這是在任何指定時間了解系統狀態的能力。 您可以透過各種方式達成此目的,包括記錄、計量和分散式追蹤。

森林伐木業

Orleans 使用 Microsoft.Extensions.Logging 來記錄所有 silo 和客戶端的日誌。 您可以使用任何與 Microsoft.Extensions.Logging相容的記錄提供者。 您的應用程式程式代碼依賴 相依性插入 來取得的 ILogger<TCategoryName> 實例,並用它來記錄訊息。 如需詳細資訊,請參閱 在 .NET 中記錄

指標

度量是隨時間報告的數值測量。 您最常使用它們來監視應用程式的健康情況並產生警示。 如需詳細資訊,請參閱 .NET 中的計量。 Orleans 會使用 System.Diagnostics.Metrics API 來收集計量。 這些計量會公開給 OpenTelemetry 專案,其會將這些計量匯出至各種監視系統。

若要監視您的應用程式而不進行任何程式碼變更,請使用 dotnet counters .NET 診斷工具。 若要監視特定 Orleans 的 ActivitySource<ProcessName> 計數器,請使用 dotnet counters monitor 命令,如下所示:

dotnet counters monitor -n <ProcessName> --counters Microsoft.Orleans

假設您正在執行 Orleans GPS 追蹤器範例應用程式 ,並使用 命令在不同的終端 dotnet counters monitor 機中監視它。 下列輸出是典型的:

Press p to pause, r to resume, q to quit.
    Status: Running
[Microsoft.Orleans]
    orleans-app-requests-latency-bucket (Count / 1 sec)                    0
        duration=10000ms                                                   0
        duration=1000ms                                                    0
        duration=100ms                                                     0
        duration=10ms                                                      0
        duration=15000ms                                                   0
        duration=1500ms                                                    0
        duration=1ms                                                   2,530
        duration=2000ms                                                    0
        duration=200ms                                                     0
        duration=2ms                                                       0
        duration=400ms                                                     0
        duration=4ms                                                       0
        duration=5000ms                                                    0
        duration=50ms                                                      0
        duration=6ms                                                       0
        duration=800ms                                                     0
        duration=8ms                                                       0
        duration=9223372036854775807ms                                     0
    orleans-app-requests-latency-count (Count / 1 sec)                 2,530
    orleans-app-requests-latency-sum (Count / 1 sec)                       0
    orleans-catalog-activation-working-set                                36
    orleans-catalog-activations                                           38
    orleans-consistent-ring-range-percentage-average                     100
    orleans-consistent-ring-range-percentage-local                       100
    orleans-consistent-ring-size                                           1
    orleans-directory-cache-size                                          27
    orleans-directory-partition-size                                      26
    orleans-directory-ring-local-portion-average-percentage              100
    orleans-directory-ring-local-portion-distance                          0
    orleans-directory-ring-local-portion-percentage                        0
    orleans-directory-ring-size                                        1,295
    orleans-gateway-received (Count / 1 sec)                           1,291
    orleans-gateway-sent (Count / 1 sec)                               2,582
    orleans-messaging-processing-activation-data                           0
    orleans-messaging-processing-dispatcher-forwarded (Count / 1           0
    orleans-messaging-processing-dispatcher-processed (Count / 1       2,543
        Direction=Request,Status=Ok                                    2,582
    orleans-messaging-processing-dispatcher-received (Count / 1        1,271
        Context=Grain,Direction=Request                                1,291
        Context=None,Direction=Request                                 1,291
    orleans-messaging-processing-ima-enqueued (Count / 1 sec)          5,113

如需詳細資訊,請參閱調查效能計數器 (dotnet-counters)

Orleans 米

Orleans 會使用 System.Diagnostics.Metrics API 來收集計量。 Orleans 將每個計量分類為以網域為中心的考慮,例如網路、傳訊、網關等。下列小節描述計量 Orleans 的使用方式。

網路

下表顯示用來監視 Orleans 網路層的網路計量集合。

計量名稱 類型 說明
orleans-networking-sockets-closed Counter<T> 已關閉的套接字計數。
orleans-networking-sockets-opened Counter<T> 已開啟的套接字計數。

訊息傳送

下表顯示用來監視 Orleans 傳訊層的傳訊計量集合。

計量名稱 類型 說明
orleans-messaging-sent-messages-size Histogram<T> 直方圖,表示以已傳送的位元組為單位的訊息大小。
orleans-messaging-received-messages-size Histogram<T> 直方圖,表示已接收位元組的訊息大小。
orleans-messaging-sent-header-size ObservableCounter<T> 可觀察計數器,表示傳送的標頭位元組數目。
orleans-messaging-received-header-size ObservableCounter<T> 可觀察的計數器,表示收到的標頭位元組數目。
orleans-messaging-sent-failed Counter<T> 傳送失敗訊息的計數。
orleans-messaging-sent-dropped Counter<T> 已丟棄發送訊息的計數。
orleans-messaging-processing-dispatcher-received ObservableCounter<T> 可監控的計數器,表示調度器接收訊息的數量。
orleans-messaging-processing-dispatcher-processed ObservableCounter<T> 可觀察的計數器,用以表示分派器已處理的訊息數量。
orleans-messaging-processing-dispatcher-forwarded ObservableCounter<T> 可觀察的計數器,表示發送器轉寄的訊息數目。
orleans-messaging-processing-ima-received ObservableCounter<T> 可觀察的計數器,表示收到的傳入訊息數目。
orleans-messaging-processing-ima-enqueued ObservableCounter<T> 用來表示已加入佇列的傳入訊息數目的觀察型計數器。
orleans-messaging-processing-activation-data ObservableGauge<T> 代表所有處理激活數據的可視化指標。
orleans-messaging-pings-sent Counter<T> 傳送的 Ping 次數計算。
orleans-messaging-pings-received Counter<T> 收到的 Ping 計數。
orleans-messaging-pings-reply-received Counter<T> 收到的 Ping 回復計數。
orleans-messaging-pings-reply-missed Counter<T> 漏掉的 Ping 回覆次數。
orleans-messaging-expired" Counter<T> 已過期的訊息計數。
orleans-messaging-rejected Counter<T> 已拒絕的訊息計數。
orleans-messaging-rerouted Counter<T> 重新路由的訊息數量。
orleans-messaging-sent-local ObservableCounter<T> 可觀察的計數器,表示傳送的本機訊息數目。

閘道器

下表顯示用來監視 Orleans 閘道層的閘道計量集合。

計量名稱 類型 說明
orleans-gateway-connected-clients UpDownCounter<T> 代表已連線客戶端數目的增減計數器。
orleans-gateway-sent Counter<T> 傳送的閘道訊息計數。
orleans-gateway-received Counter<T> 收到的閘道訊息計數。
orleans-gateway-load-shedding Counter<T> 由於閘道超載而遭拒的閘道負載捨棄訊息計數。

執行時間

下表顯示用來監視運行時間層的 Orleans 運行時間計量集合。

計量名稱 類型 說明
orleans-scheduler-long-running-turns Counter<T> 排程器內長時間運行次數的計數。
orleans-runtime-total-physical-memory ObservableCounter<T> 可觀察的計數器,表示運行時間的記憶體總數(以 MB 為單位)。Orleans
orleans-runtime-available-memory ObservableCounter<T> 可觀察的計數器,表示運行時間的可用記憶體(以 MB 為單位)。Orleans

目錄

下表顯示用來監視 Orleans 目錄圖層的目錄計量集合。

計量名稱 類型 說明
orleans-catalog-activations ObservableGauge<T> 代表目錄啟用次數的可觀察量測計。
orleans-catalog-activation-working-set ObservableGauge<T> 可觀察量測計,表示工作集內的啟用數目。
orleans-catalog-activation-created Counter<T> 已建立的啟用次數計數。
orleans-catalog-activation-destroyed Counter<T> 被銷毀的啟用數量。
orleans-catalog-activation-failed-to-activate Counter<T> 無法完成啟用的次數統計。
orleans-catalog-activation-collections Counter<T> 閑置的啟動集合計數。
orleans-catalog-activation-shutdown Counter<T> 關機次數計算。
orleans-catalog-activation-non-existent Counter<T> 計數未激活的次數。
orleans-catalog-activation-concurrent-registration-attempts Counter<T> 並行啟用註冊嘗試的計數。

目錄

下表顯示用來監視 Orleans 目錄層的目錄計量集合。

計量名稱 類型 說明
orleans-directory-lookups-local-issued Counter<T> 發出的本機查閱計數。
orleans-directory-lookups-local-successes Counter<T> 本機成功查閱的計數。
orleans-directory-lookups-full-issued Counter<T> 發出的完整目錄查閱計數。
orleans-directory-lookups-remote-sent Counter<T> 傳送的遠端目錄查閱計數。
orleans-directory-lookups-remote-received Counter<T> 接收到的遠端目錄查詢次數。
orleans-directory-lookups-local-directory-issued Counter<T> 發出的本機目錄查閱計數。
orleans-directory-lookups-local-directory-successes Counter<T> 本地目錄成功查詢的次數。
orleans-directory-lookups-cache-issued Counter<T> 已發出的快取查詢計數。
orleans-directory-lookups-cache-successes Counter<T> 快取成功查詢的次數。
orleans-directory-validations-cache-sent Counter<T> 傳送的目錄快取驗證的計數。
orleans-directory-validations-cache-received Counter<T> 收到的目錄快取驗證計數。
orleans-directory-partition-size ObservableGauge<T> 代表目錄數據分割大小的可觀察量測計。
orleans-directory-cache-size ObservableGauge<T> 代表目錄快取大小的可觀察指標。
orleans-directory-ring-size ObservableGauge<T> 可觀察的指示器,用於表示目錄環大小。
orleans-directory-ring-local-portion-distance ObservableGauge<T> 可觀察的指標,表示本機目錄分割區擁有的環範圍。
orleans-directory-ring-local-portion-percentage ObservableGauge<T> 可觀察的儀表,代表本地目錄所擁有的環狀範圍,以總範圍的百分比表示。
orleans-directory-ring-local-portion-average-percentage ObservableGauge<T> 可觀察的量測儀表,代表每個儲存單元所擁有的目錄環狀範圍的平均百分比,並顯示目錄擁有權的平衡程度。
orleans-directory-registrations-single-act-issued Counter<T> 發出的目錄單一啟用註冊計數。
orleans-directory-registrations-single-act-local Counter<T> 由本機目錄分區處理的單一啟動註冊數量。
orleans-directory-registrations-single-act-remote-sent Counter<T> 傳送至遠端目錄分區的目錄單次啟動註冊計數。
orleans-directory-registrations-single-act-remote-received Counter<T> 從遠端主機接收的目錄單一啟用註冊計數。
orleans-directory-unregistrations-issued Counter<T> 目錄取消註冊次數計數。
orleans-directory-unregistrations-local Counter<T> 本機目錄分割區所處理的取消註冊計數。
orleans-directory-unregistrations-remote-sent Counter<T> 傳送至遠端目錄分割區的目錄取消註冊計數。
orleans-directory-unregistrations-remote-received Counter<T> 遠端主機接收的目錄註冊取消計數。
orleans-directory-unregistrations-many-issued Counter<T> 發出的目錄多重啟用取消註冊計數。
orleans-directory-unregistrations-many-remote-sent Counter<T> 傳送至遠端目錄分割區的目錄多重啟用取消註冊計數。
orleans-directory-unregistrations-many-remote-received Counter<T> 從遠端主機接收的目錄多重啟用取消註冊計數。

均勻的環

下表顯示用來監控 Orleans 一致環形層的環形計量器集合。

計量名稱 類型 說明
orleans-consistent-ring-size ObservableGauge<T> 代表一致環形大小的可觀察量測計。
orleans-consistent-ring-range-percentage-local ObservableGauge<T> 可觀察的儀表,表示穩定的環形區域百分比。
orleans-consistent-ring-range-percentage-average ObservableGauge<T> 可觀察的指示計,表示穩定的環平均百分比。

看門 狗

下表顯示用來監控看門狗層的 Orleans 看門狗計量器集合。

計量名稱 類型 說明
orleans-watchdog-health-checks Counter<T> 監控健康檢查次數的計數。
orleans-watchdog-health-checks-failed Counter<T> 監視程式狀態檢查失敗的計數。

客戶

下表顯示用來監視 Orleans 用戶端層的用戶端計量集合。

計量名稱 類型 說明
orleans-client-connected-gateways ObservableGauge<T> 可觀察的量測計,表示連線閘道客戶端的數目。

其他

下表顯示用來監視不同層級的雜項計量集合。

計量名稱 類型 說明
orleans-grains Counter<T> 表示穀粒數目的計數。
orleans-system-targets Counter<T> 表示系統目標數量的計數值。

應用程式要求

下表顯示用來監視 Orleans 應用程式要求層的應用程式要求計量集合。

計量名稱 類型 說明
orleans-app-requests-latency ObservableCounter<T> 代表應用程式要求延遲的可觀察計數器。
orleans-app-requests-timedout ObservableCounter<T> 可觀察的計數器,表示已逾時的應用程式請求。

提醒

下表顯示一組用來監控提醒層的 Orleans 提醒計表。

計量名稱 類型 說明
orleans-reminders-tardiness Histogram<T> 用於表示提醒被延遲秒數的直方圖。
orleans-reminders-active ObservableGauge<T> 可觀察的量測表,表示目前提醒的數目。
orleans-reminders-ticks-delivered Counter<T> 計數,表示已傳遞的提醒刻度數目。

存儲

下表顯示用來監視儲存層的 Orleans 儲存計量集合。

計量名稱 類型 說明
orleans-storage-read-errors Counter<T> 表示記憶體讀取錯誤的計數。
orleans-storage-write-errors Counter<T> 表示記憶體寫入錯誤的計數。
orleans-storage-clear-errors Counter<T> 計數,表示記憶體清除錯誤的數目。
orleans-storage-read-latency Histogram<T> 直方圖,表示以毫秒為單位的記憶體讀取延遲。
orleans-storage-write-latency Histogram<T> 直方圖,表示以毫秒為單位的記憶體寫入延遲。
orleans-storage-clear-latency Histogram<T> 直方圖,表示以毫秒為單位的記憶體清除延遲。

溪流

下表顯示用來監視 Orleans 數據流層的數據流計量集合。

計量名稱 類型 說明
orleans-streams-pubsub-producers-added Counter<T> 新增的串流出版訂閱生產者計數。
orleans-streams-pubsub-producers-removed Counter<T> 已移除串流發布訂閱生產者的計數。
orleans-streams-pubsub-producers Counter<T> 串流發布-訂閱生產者計數。
orleans-streams-pubsub-consumers-added Counter<T> 已新增串流發布/訂閱系統使用者的數量。
orleans-streams-pubsub-consumers-removed Counter<T> 已移除串流發佈/訂閱取用者的計數。
orleans-streams-pubsub-consumers Counter<T> 串流發佈/訂閱消費者的計數。
orleans-streams-persistent-stream-pulling-agents ObservableGauge<T> 可觀察的指標,代表持續拉取數據流的代理程式數量。
orleans-streams-persistent-stream-messages-read Counter<T> 讀取的永續性數據流訊息計數。
orleans-streams-persistent-stream-messages-sent Counter<T> 傳送的持續性串流訊息計數。
orleans-streams-persistent-stream-pubsub-cache-size ObservableGauge<T> 可觀察的指標,表示持續流數據 pubsub 快取大小。
orleans-streams-queue-initialization-failures Counter<T> Steam 佇列初始化失敗的計數。
orleans-streams-queue-initialization-duration Counter<T> 蒸汽佇列初始化發生次數的計數。
orleans-streams-queue-initialization-exceptions Counter<T> Steam佇列初始化例外狀況的計數。
orleans-streams-queue-read-failures Counter<T> Steam 佇列讀取失敗的次數。
orleans-streams-queue-read-duration Counter<T> 蒸汽佇列讀取次數的計數。
orleans-streams-queue-read-exceptions Counter<T> 蒸汽佇列讀取例外狀況的計數。
orleans-streams-queue-shutdown-failures Counter<T> 蒸汽佇列關機失敗的計數。
orleans-streams-queue-shutdown-duration Counter<T> 蒸汽佇列關機次數的計數。
orleans-streams-queue-shutdown-exceptions Counter<T> 蒸汽佇列關機例外狀況的計數。
orleans-streams-queue-messages-received ObservableCounter<T> 可觀察的計數器,表示收到的數據流佇列訊息數目。
orleans-streams-queue-oldest-message-enqueue-age ObservableGauge<T> 可觀察的指標,表示佇列中最舊訊息的年齡。
orleans-streams-queue-newest-message-enqueue-age ObservableGauge<T> 可觀察的指標,代表最新加入佇列訊息的年齡。
orleans-streams-block-pool-total-memory ObservableCounter<T> 可觀察的計數器,表示流媒體區塊池的總記憶體大小(以位元組計)。
orleans-streams-block-pool-available-memory ObservableCounter<T> 一個可觀察的計數器,表示資料流塊池中可用記憶體的位元組數。
orleans-streams-block-pool-claimed-memory ObservableCounter<T> 可觀察的計數器,表示數據流區塊集區以位元組為單位宣告的記憶體。
orleans-streams-block-pool-released-memory ObservableCounter<T> 表示以位元組為單位釋放記憶體的數據流區塊池的可觀察計數器。
orleans-streams-block-pool-allocated-memory ObservableCounter<T> 可觀察的計數器,表示以位元組為單位配置的數據流區塊集區內存。
orleans-streams-queue-cache-size ObservableCounter<T> 可觀察的計數器,表示以位元組為單位的數據流佇列快取大小。
orleans-streams-queue-cache-length ObservableCounter<T> 代表數據流佇列長度的可觀察計數器。
orleans-streams-queue-cache-messages-added ObservableCounter<T> 一個可觀察的計數器,表示添加到流佇列中的訊息。
orleans-streams-queue-cache-messages-purged ObservableCounter<T> 可觀察的計數器,表示已清除的流訊息佇列。
orleans-streams-queue-cache-memory-allocated ObservableCounter<T> 可觀察的計數器,用於顯示已分配的資料流佇列記憶體。
orleans-streams-queue-cache-memory-released ObservableCounter<T> 可觀測的計數器,用於表示已釋放的數據流佇列記憶體。
orleans-streams-queue-cache-oldest-to-newest-duration ObservableGauge<T> 可觀察的指標,表示從最舊到最新的流佇列快取的持續時間。
orleans-streams-queue-cache-oldest-age ObservableGauge<T> 可觀察指標,表示最舊快取訊息的年齡。
orleans-streams-queue-cache-pressure ObservableGauge<T> 可觀察的指標,表示串流佇列快取區的壓力。
orleans-streams-queue-cache-under-pressure ObservableGauge<T> 可觀察的量測計,表示串流佇列快取是否承受壓力。
orleans-streams-queue-cache-pressure-contribution-count ObservableCounter<T> 代表數據流佇列快取壓力貢獻的可觀察計數器。

交易

下表顯示用來監視 Orleans 交易層的交易計量集合。

計量名稱 類型 說明
orleans-transactions-started ObservableCounter<T> 一個可觀察的計數器,用來表示已啟動的交易數量。
orleans-transactions-successful ObservableCounter<T> 代表成功交易數目的可觀察計數器。
orleans-transactions-failed ObservableCounter<T> 代表失敗交易數目的可觀察計數器。
orleans-transactions-throttled ObservableCounter<T> 代表節流交易數目之可觀測計數器。

普羅 米修斯

各種第三方計量提供者可用於 Orleans。 其中一個熱門範例是 Prometheus,您可以使用 Prometheus 從應用程式使用 OpenTelemetry 收集計量。

若要搭配 Orleans使用 OpenTelemetry 和 Prometheus,請呼叫下列 IServiceCollection 擴充方法:

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics =>
    {
        metrics
            .AddPrometheusExporter()
            .AddMeter("Microsoft.Orleans");
    });

這很重要

OpenTelemetry.Exporter.PrometheusOpenTelemetry.Exporter.Prometheus.AspNetCore NuGet 套件目前都處於預覽狀態,作為發行候選專案。 不建議將其用於生產環境。

AddPrometheusExporter方法可確保 PrometheusExporter 已將 新增至 builder。 Orleans 使用名為 Meter"Microsoft.Orleans" 來為許多 Counter<T> 特定的計量建立 Orleans 實例。 使用 AddMeter 方法來指定要訂閱的計量表名稱,在此情況下為 "Microsoft.Orleans"

設定匯出工具並建置您的應用程式之後,請在 (MapPrometheusScrapingEndpoint實例) 上IEndpointRouteBuilder呼叫 app ,將計量公開給 Prometheus。 例如:

WebApplication app = builder.Build();

app.MapPrometheusScrapingEndpoint();
app.Run();

分散式追蹤

分散式追蹤是監視和疑難解答分散式應用程式的一組工具和作法。 它是可觀察性的重要元件,是瞭解應用程式行為的重要工具。 Orleans 支援使用 OpenTelemetry 的分散式追蹤。

無論您選擇的分散式追蹤匯出工具為何,請呼叫:

Orleans回到 GPS 追蹤器範例應用程式,您可以使用 Zipkin 分散式追蹤系統來更新Program.cs來監視應用程式。 若要使用 Orleans 搭配 OpenTelemetry 和 Zipkin,請呼叫下列 IServiceCollection 擴充方法:

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing =>
    {
        // Set a service name
        tracing.SetResourceBuilder(
            ResourceBuilder.CreateDefault()
                .AddService(serviceName: "GPSTracker", serviceVersion: "1.0"));

        tracing.AddSource("Microsoft.Orleans.Runtime");
        tracing.AddSource("Microsoft.Orleans.Application");

        tracing.AddZipkinExporter(zipkin =>
        {
            zipkin.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
        });
    });

這很重要

OpenTelemetry.Exporter.Zipkin NuGet 套件目前處於預覽狀態,作為發行候選版本。 不建議用於生產環境。

Zipkin 追踪會顯示在 Jaeger UI 中(使用相同數據格式的 Zipkin 替代方案):

Orleans GPS 追蹤器範例應用程式:Jaeger UI 追蹤。

如需詳細資訊,請參閱 分散式追蹤

Orleans 透過 ITelemetryConsumer 介面輸出其運行時間統計數據和計量。 您的應用程式可以為其獨立數據儲存和客戶端註冊一或多個遙測資料消費者,以接收 Orleans 運行環境定期發佈的統計數據和計量。 這些可以是熱門遙測分析解決方案的使用者,或針對任何其他目的地和用途的自定義使用者。 Orleans 程式代碼基底目前包含三個遙測取用者。

它們會以個別的 NuGet 套件的形式發行:

  • Microsoft.Orleans.OrleansTelemetryConsumers.AI:用於發佈至 Azure Application Insights

  • Microsoft.Orleans.OrleansTelemetryConsumers.Counters:用於發佈至 Windows 性能計數器。 執行時期 Orleans 會持續更新許多內容。 NuGet 套件中包含的 Microsoft.Orleans.CounterControl 工具可協助註冊必要的性能計數器類別。 它必須以提升的權限執行。 使用任何標準監視工具監視性能計數器。

  • Microsoft.Orleans.OrleansTelemetryConsumers.NewRelic:發行至 New Relic

若要將您的儲存區和客戶端設定為使用遙測消費者,儲存區配置程式碼如下所示:

var siloHostBuilder = new HostBuilder()
    .UseOrleans(c =>
    {
        c.AddApplicationInsightsTelemetryConsumer("INSTRUMENTATION_KEY");
    });

用戶端設定程式代碼看起來像這樣:

var clientBuilder = new ClientBuilder();
clientBuilder.AddApplicationInsightsTelemetryConsumer("INSTRUMENTATION_KEY");

若要使用自訂定義 TelemetryConfiguration (可能具有 TelemetryProcessorsTelemetrySinks等),孤立體配置程式碼如下所示:

var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
var siloHostBuilder = new HostBuilder()
    .UseOrleans(c =>
    {
        c.AddApplicationInsightsTelemetryConsumer(telemetryConfiguration);
    });

用戶端設定程式代碼看起來像這樣:

var clientBuilder = new ClientBuilder();
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
clientBuilder.AddApplicationInsightsTelemetryConsumer(telemetryConfiguration);

另請參閱