Microsoft Orleans — Dashboard Update — CPU/Memory Stats
Tags: dotnetcore, softwaredevelopment, actormodel, softwareengineering
Published: 2019-02-26 16:47:38

---
title: Microsoft Orleans — Dashboard Update — CPU/Memory Stats
published: true
tags: dotnet-core,software-development,actor-model,software-engineering
canonical_url: https://hackernoon.com/microsoft-orleans-dashboard-update-cpu-memory-stats-706daed82cf8
cover_image: https://cdn-images-1.medium.com/max/1024/1*050BNc2zKDgssiqmx4VSbQ.png
series: Microsoft Orleans
---

### Microsoft Orleans — Dashboard Update — CPU/Memory Stats

Quick update to a post I did a while back regarding Orleans Dashboard — additional reporting metrics for your cluster!

As a refresher, Orleans is a virtual actor model framework — a framework that can be used to build new, distributed “primitives”. These primitives’ work can be farmed out to a cluster of nodes as a means of getting “work” done faster than what would be possible if working constrained to a single piece of hardware.

In a previous post:

[How to set up Microsoft Orleans’ Reporting Dashboard](https://dev.to/kritner/microsoft-orleansreporting-dashboard-2716)

I had pointed out:

> Currently CPU/Memory usage is not visible from the .net core implementation of Orleans. Hopefully something will be done to remedy that in the future? Perhaps it’s a limitation of the API available in netstandard?

This ***seems*** to have been true at a point in time, but it is no longer! (At least if you’re running in a windows runtime.)

The additional CPU and memory metrics are completely dependant on a registered IHostEnvironmentStatistics implementation. By default, a “NoImplementation” implementation is registered, and you would see something like this in your Orleans log:

![](https://cdn-images-1.medium.com/max/1024/1*LUNEWSPH4EmnMcjyeX4KyA.png)<figcaption>Orleans log showing an issue that prevents LoadShedding from working</figcaption>

And this on your dashboard:

![](https://cdn-images-1.medium.com/max/1024/1*nkh0T8cIULk5Qnjh26ecxQ.png)<figcaption>Sad Orleans Dashboard w/o CPU/Memory metrics :(</figcaption>

The whole reason I stumbled across getting these CPU/Memory metrics working on the dashboard, was I was pursuing getting the feature LoadShedding to work — which was apparently dependant on these metrics.

Through some back and forth on the [Orleans Gitter](https://gitter.im/dotnet/orleans) I found out about the needed registered implementation of an IHostEnvironmentStatistics class. One of these classes does exist in the Orleans code, though it’s in a separate package, and an internal only class to that package:

[dotnet/orleans](https://github.com/dotnet/orleans/blob/e2b25a695767ae5746ffe47218c1331427997894/src/TelemetryConsumers/Orleans.TelemetryConsumers.Counters/Statistics/PerfCounterEnvironmentStatistics.cs)

Luckily, there is a SiloHost extension method that registers this implementation of IHostEnvironmentStatistics for use — albeit from a Windows only runtime environment (at least at the time of writing).

To get the CPU/Memory metrics work on our dashboard (and putting us in a position to work in LoadShedding) we need to do a few things:

- Install a new NuGet package
- Register an implementation of IHostEnvironmentStatistics — like the one provided in the NuGet package itself.

#### Install the NuGet Package

The IHostEnvironmentStatistics implementation exists within the Microsoft.Orleans.OrleansTelemetryConsumers.Counters package, install it via the GUI, CLI, etc. The csproj file from the SiloHost project should look something like this when done:

![](https://cdn-images-1.medium.com/max/1024/1*XDZnP9oDOIz96A2XZBOC0A.png)<figcaption>csproj after installing the NuGet package Microsoft.Orleans.OrleansTelemetryConsumers.Counters</figcaption>

#### Registering the implementation of IHostEnvironmentStatistics

As previously mentioned, the new NuGet package has a Windows specific implementation of IHostEnvironmentStatistics contained within it, although it is an internal class. There is however, an extension method that can be used to register that internal class.

Let’s update our `SiloHostBuilder`:

Original

```cs
var builder = new SiloHostBuilder()
 .ConfigureClustering(
  ServiceProvider.GetService<IOptions<OrleansConfig>>(),
  Startup.HostingEnvironment.EnvironmentName
 )
 .Configure<ClusterOptions>(options =>
 {
  options.ClusterId = "dev";
  options.ServiceId = "HelloWorldApp";
 })
 .Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
 .AddMemoryGrainStorage(Constants.OrleansMemoryProvider)
 .ConfigureApplicationParts(parts =>
 {
  parts.AddApplicationPart(typeof(IGrainMarker).Assembly).WithReferences();
 })
 .ConfigureServices(DependencyInjectionHelper.IocContainerRegistration)
 .UseDashboard(options => { })
 .UseInMemoryReminderService()
 .ConfigureLogging(logging => logging.AddConsole());
```

And we just need to add `.UsePerfCounterEnvironmentStatistics()`.

Updated

```cs
var builder = new SiloHostBuilder()
 .ConfigureClustering(
  ServiceProvider.GetService<IOptions<OrleansConfig>>(),
  Startup.HostingEnvironment.EnvironmentName
 )
 .Configure<ClusterOptions>(options =>
 {
  options.ClusterId = "dev";
  options.ServiceId = "HelloWorldApp";
 })
 .Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
 .AddMemoryGrainStorage(Constants.OrleansMemoryProvider)
 .ConfigureApplicationParts(parts =>
 {
  parts.AddApplicationPart(typeof(IGrainMarker).Assembly).WithReferences();
 })
 .ConfigureServices(DependencyInjectionHelper.IocContainerRegistration)
 .UsePerfCounterEnvironmentStatistics() // <- this guy
 .UseDashboard(options => { })
 .UseInMemoryReminderService()
 .ConfigureLogging(logging => logging.AddConsole());
```

That’s all there is to it! Now, we should get our CPU/Memory utilization reported on the Orleans Dashboard, and be in a better position to work in LoadShedding — perhaps for the next post!

Now, looking at our dashboard, we can see:

![](https://cdn-images-1.medium.com/max/1024/1*050BNc2zKDgssiqmx4VSbQ.png)<figcaption>CPU/Memory utilization!</figcaption>

Now, we have even more insight into how our cluster is operating, and additional features such as LoadShedding are made available to us!

#### Related:

- [How to set up Microsoft Orleans’ Reporting Dashboard](https://dev.to/kritner/microsoft-orleansreporting-dashboard-2716)
- [Info on enabling CPU/Memory metrics. by Kritner · Pull Request #212 · OrleansContrib/OrleansDashboard](https://github.com/OrleansContrib/OrleansDashboard/pull/212)

- Code as of post — [https://github.com/Kritner-Blogs/OrleansGettingStarted/releases/tag/v0.57](https://github.com/Kritner-Blogs/OrleansGettingStarted/releases/tag/v0.57)
- [Getting Started with Microsoft Orleans](https://medium.com/@kritner/getting-started-with-microsoft-orleans-882cdac4307f?source=friends_link&sk=1fc3451d71a19dcb49f2c8bbeb6b079e)
- [Microsoft Orleans — Reusing Grains and Grain State](https://medium.com/@kritner/microsoft-orleans-reusing-grains-and-grain-state-136977facd42?source=friends_link&sk=f19cfa3f17665c3d700bfe0df56e27a9)
- [Microsoft Orleans — Reporting Dashboard](https://medium.com/@kritner/microsoft-orleans-reporting-dashboard-16465d255199)
- [Using polymorphism to update Orleans Project to be ready for new Orleans Examples!](https://medium.com/@kritner/updating-orleans-project-to-be-more-ready-for-new-orleans-examples-2105b29a46fd?source=friends_link&sk=61d1f591e5b5c498688439db50ad310e)
- [Microsoft Orleans — Dependency Injection](https://medium.com/@kritner/microsoft-orleans-dependency-injection-6379d52a7169?source=friends_link&sk=6c3883a5213d65eb251b56c717e0e4f2)
- [Microsoft Orleans — Easily switching between “development” and “production” configurations.](https://medium.com/@kritner/microsoft-orleans-easily-switching-between-development-and-production-configurations-20e109be6458?source=friends_link&sk=1e8fc6aa072a5b293d029c00012165b3)
- [.net core console application IOptions<T> configuration](https://medium.com/@kritner/net-core-console-application-ioptions-t-configuration-ae74bfafe1c5?source=friends_link&sk=c5bcab4f7f10c97175ad68fc12cb9cc6)
- [Microsoft Orleans — Observers](https://medium.com/@kritner/microsoft-orleans-observables-5e0040c949cd?source=friends_link&sk=bcb921fdf593bdc97b9c5909b2730f2d)

* * *