Esempio n. 1
0
        public ActionResult NetworkJson(int id, long start, long end, bool?summary = false)
        {
            var ni = DashboardData.GetInterfaceById(id);

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

            var traffic = ni.GetUtilization(start.ToDateTime(), end.ToDateTime(), 1000).ToList();

            return(Json(new
            {
                maximums = new
                {
                    main_in = traffic.Max(i => (int)i.InAvgBps.GetValueOrDefault(0)),
                    main_out = traffic.Max(i => (int)i.OutAvgBps.GetValueOrDefault(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()
                                  ? ni.GetUtilization(null, null, 2000).Select(i => new
                {
                    date = i.DateTime.ToEpochTime(true),
                    main_in = (int)(i.InAvgBps.GetValueOrDefault()),
                    main_out = (int)(i.OutAvgBps.GetValueOrDefault())
                })
                                  : null
            }));
        }
Esempio n. 2
0
        public ActionResult InterfaceOutSpark(string direction, int id)
        {
            var i = DashboardData.GetInterfaceById(id);

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

            var chart      = GetSparkChart();
            var dataPoints = i.GetUtilization(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());
        }