I'm trying to dynamically report the load against all the instances of my stateless service. The goal is to read the reported values from the code later on. So far I have the code to report some metrics and read them with FabricClient, but the numbers I get are always 0 no matter what I do. So here is how service is configured -
<StatelessService ServiceTypeName="MySvcType" InstanceCount="-1">
<SingletonPartition />
<LoadMetrics>
<LoadMetric Name="MemoryInMb" />
<LoadMetric Name="CPU" />
</LoadMetrics>
</StatelessService>
The code that reports the metrics -
protected override async Task RunAsync(CancellationToken cancellationToken)
{
await base.RunAsync(cancellationToken);
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
this.Partition.ReportLoad(new List<LoadMetric> { new LoadMetric("MemoryInMb", (int)ramCounter.NextValue()), new LoadMetric("CPU", (int)cpuCounter.NextValue()) });
await Task.Delay(5000);
}
}
And here is the code I have to pull out those metrics -
var partitions = await fabricClient.QueryManager.GetPartitionListAsync(new Uri("fabric:/MyApp/MySvc"));
foreach (var partition in partitions)
{
var partitionLoad = await fabricClient.QueryManager.GetPartitionLoadInformationAsync(partition.PartitionInformation.Id);
var replicas = new List<Replica>();
ServiceReplicaList replicaList = await fabricClient.QueryManager.GetReplicaListAsync(partition.PartitionInformation.Id);
replicas.AddRange(replicaList);
while (!string.IsNullOrEmpty(replicaList.ContinuationToken))
{
replicaList = await fabricClient.QueryManager.GetReplicaListAsync(partition.PartitionInformation.Id, replicaList.ContinuationToken);
replicas.AddRange(replicaList);
}
foreach(var replica in replicas)
{
var replicaLoad = await fabricClient.QueryManager.GetReplicaLoadInformationAsync(partition.PartitionInformation.Id, replica.Id);
var memoryReports = replicaLoad.LoadMetricReports.Where(r => r.Name == "MemoryInMb");
var cpuReports = replicaLoad.LoadMetricReports.Where(r => r.Name == "CPU");
}
}
So I get back only one report per each metric I've defined and value is always 0. Any thoughts on what should I do to start retrieving the values that are reported in my stateless service?