Beispiel #1
0
 private Metrics GetInterSiloMetrics(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot, string sourceSilo, string destinationSilo)
 {
     return(new Metrics()
     {
         normal = 100, danger = 1, warning = 1
     });
 }
Beispiel #2
0
        private void AddReplaceSiloStatsToMetrics(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot)
        {
            var siloRecord = CreateSiloRecords(snapshot, previousSnapshot, _silos);

            siloRecord.Item1.nodes.Add(new Node
            {
                name = "INTERNET",
            });
            if (_rootDataObject.nodes.Exists(n => n.name == snapshot.Source))
            {
                _rootDataObject.nodes.Remove(_rootDataObject.nodes.Single(n => n.name == snapshot.Source));
            }
            _rootDataObject.nodes.Add(siloRecord.Item1);

            _rootDataObject.connections.Where(c => c.source == snapshot.Source || (c.target == snapshot.Source && c.source == "INTERNET")).ToList().ForEach(c => _rootDataObject.connections.Remove(c));
            _rootDataObject.connections.AddRange(siloRecord.Item2);


            if (_silos.Any(s => s.name != siloRecord.Item1.name))
            {
                _silos.Add(siloRecord.Item1);
                _snapshotHistoryCache.Add(snapshot.Source, snapshot);
            }

            _snapshotHistoryCache[snapshot.Source] = snapshot;
        }
Beispiel #3
0
 private Metrics GetClientGrainCalls(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot)
 {
     return(new Metrics
     {
         normal = AggregatedMetricValue(snapshot, previousSnapshot, "GrainMethodCall"),
         danger = AggregatedMetricValue(snapshot, previousSnapshot, "GrainException"),
         warning = AggregatedMetricValue(snapshot, previousSnapshot, "GrainInvokeTimeout"),
     });
 }
Beispiel #4
0
 private Metrics GetMetricsForGrainType(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot, string grainTypeName)
 {
     return(new Metrics()
     {
         normal =
             AggregatedMetricValue(snapshot, previousSnapshot,
                                   $"GrainMethodCall:{grainTypeName}"),
         danger = AggregatedMetricValue(snapshot, previousSnapshot, $"GrainException:{grainTypeName}"),
         warning = AggregatedMetricValue(snapshot, previousSnapshot, $"GrainInvokeTimeout:{grainTypeName}"),
     });
 }
Beispiel #5
0
 private double AggregatedMetricValue(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot, string metricPrefix, string[] excluding = null)
 {
     if (previousSnapshot == null)
     {
         return(snapshot.Metrics.Where(m => m.Key.StartsWith(metricPrefix)).Sum(m => m.Value));
     }
     // We should really be caching the resultant summing from the previous snapshots, some low hanging fruit for the future.
     if (excluding == null)
     {
         return(snapshot.Metrics.Where(m => m.Key.StartsWith(metricPrefix)).Sum(m => m.Value) - previousSnapshot.Metrics.Where(m => m.Key.StartsWith(metricPrefix)).Sum(m => m.Value));
     }
     return
         (snapshot.Metrics.Where(m => m.Key.StartsWith(metricPrefix) && !excluding.Contains(m.Key))
          .Sum(m => m.Value) - previousSnapshot.Metrics.Where(m => m.Key.StartsWith(metricPrefix) && !excluding.Contains(m.Key))
          .Sum(m => m.Value));
 }
Beispiel #6
0
        private IEnumerable <Node> ExtractGrainSpecificMetrics(MetricsSnapshot snapshot)
        {
            var grainTypesInSnapshot =
                snapshot.Metrics.Keys.Where(k => k.StartsWith("GrainMethodCall")).GroupBy(k => k.Split(':')[1], k => k);

            foreach (var grainType in grainTypesInSnapshot)
            {
                yield return(new Node
                {
                    name = grainType.Key,
                    metadata = new Metadata(),
                    @class = "normal",
                    updated = DateTime.UtcNow.Ticks,
                });
            }
        }
Beispiel #7
0
        private Tuple <Node, List <Connection> > CreateSiloRecords(MetricsSnapshot snapshot, MetricsSnapshot previousSnapshot, List <Node> silos)
        {
            var grainCalls = ExtractGrainSpecificMetrics(snapshot).ToList();

            var node = new Node
            {
                renderer    = "region",
                name        = snapshot.Source,
                updated     = DateTime.UtcNow.Ticks,
                @class      = "normal",
                maxVolume   = 10000,
                nodes       = grainCalls,
                connections = grainCalls.Select(g => new Connection()
                {
                    source  = "INTERNET",
                    target  = g.name,
                    metrics = GetMetricsForGrainType(snapshot, previousSnapshot, g.name),
                    @class  = "normal",
                    notices = new List <Notice>()
                }).ToList(),
            };
            var connections =
                silos.Select(
                    s =>
                    new Connection()
            {
                source  = snapshot.Source,
                target  = s.name,
                metrics = GetInterSiloMetrics(snapshot, previousSnapshot, snapshot.Source, s.name),
                @class  = "normal"
            }).ToList();

            connections.Add(new Connection
            {
                source  = "INTERNET",
                target  = snapshot.Source,
                metrics = GetClientGrainCalls(snapshot, previousSnapshot),
                @class  = "normal",
            });

            return(new Tuple <Node, List <Connection> >(node, connections));
        }
Beispiel #8
0
 static async Task OnNewMetricSnapshot(MetricsSnapshot snapshot, StreamSequenceToken token)
 {
     Console.WriteLine(snapshot);
 }
Beispiel #9
0
        static Task OnNewMetricSnapshot(MetricsSnapshot snapshot, StreamSequenceToken token)
        {
            Console.WriteLine(snapshot);

            return(Task.CompletedTask);
        }