Example #1
0
        public async Task <ActionResult> InterfaceOutSpark(string direction, string id)
        {
            var chart      = GetSparkChart();
            var dataPoints = (await DashboardData.GetInterfaceUtilization(id,
                                                                          start: DateTime.UtcNow.AddHours(-SparkHours),
                                                                          end: null,
                                                                          pointCount: (int)chart.Width.Value))
                             .OrderBy(dp => dp.DateTime);

            var area   = GetSparkChartArea();
            var series = GetSparkSeries("Bytes");

            chart.Series.Add(series);

            foreach (var np in dataPoints)
            {
                series.Points.Add(new DataPoint(np.DateTime.ToOADate(),
                                                direction == "out"
                                                    ? np.OutAvgBps.GetValueOrDefault(0)
                                                    : np.InAvgBps.GetValueOrDefault(0)));
            }
            chart.ChartAreas.Add(area);

            return(chart.ToResult());
        }
Example #2
0
        public async Task <ActionResult> NetworkSpark(string id)
        {
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(ContentNotFound());
            }

            var chart      = GetSparkChart();
            var pointTasks = node.PrimaryInterfaces.Select(
                ni => DashboardData.GetInterfaceUtilization(ni.Id,
                                                            start: DateTime.UtcNow.AddHours(-SparkHours),
                                                            end: null,
                                                            pointCount: (int)chart.Width.Value));
            var dataPoints = (await Task.WhenAll(pointTasks)).SelectMany(t => t).OrderBy(t => t.DateTime);

            var area   = GetSparkChartArea();
            var series = GetSparkSeries("Total");

            series.ChartType = SeriesChartType.StackedArea;
            chart.Series.Add(series);

            foreach (var np in dataPoints)
            {
                series.Points.Add(new DataPoint(np.DateTime.ToOADate(), np.InAvgBps.GetValueOrDefault(0) + np.OutAvgBps.GetValueOrDefault(0)));
            }
            chart.DataManipulator.Group("SUM", 2, IntervalType.Minutes, series);

            chart.ChartAreas.Add(area);

            return(chart.ToResult());
        }
Example #3
0
        public async Task <ActionResult> NetworkJson(string id, long start, long end, bool?summary = false)
        {
            var traffic = await DashboardData.GetInterfaceUtilization(id, start.ToDateTime(), end.ToDateTime(), 1000);

            if (traffic == null)
            {
                return(JsonNotFound());
            }

            var anyTraffic = traffic.Any();

            return(Json(new
            {
                maximums = new
                {
                    main_in = anyTraffic ? traffic.Max(i => (int)i.InAvgBps.GetValueOrDefault(0)) : 0,
                    main_out = anyTraffic ? traffic.Max(i => (int)i.OutAvgBps.GetValueOrDefault(0)) : 0
                },
                points = traffic.Select(i => new
                {
                    date = i.DateTime.ToEpochTime(true),
                    main_in = (int)(i.InAvgBps.GetValueOrDefault()),
                    main_out = (int)(i.OutAvgBps.GetValueOrDefault())
                }),
                summary = summary.GetValueOrDefault()
                                  ? (await DashboardData.GetInterfaceUtilization(id, null, null, 2000)).Select(i => new
                {
                    date = i.DateTime.ToEpochTime(true),
                    main_in = (int)(i.InAvgBps.GetValueOrDefault()),
                    main_out = (int)(i.OutAvgBps.GetValueOrDefault())
                })
                                  : null
            }));
        }