Пример #1
0
        public ActionResult CPUJson(int id, long start, long end, bool?summary = false)
        {
            var node = DashboardData.GetNodeById(id);

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

            return(Json(new
            {
                points = node.GetCPUUtilization(start.ToDateTime(), end.ToDateTime(), 1000).Select(p => new
                {
                    date = p.DateTime.ToEpochTime(true),
                    value = p.AvgLoad ?? 0
                }),
                summary = summary.GetValueOrDefault(false) ? node.GetCPUUtilization(null, null, 2000).Select(p => new
                {
                    date = p.DateTime.ToEpochTime(true),
                    value = p.AvgLoad ?? 0
                }) : null,
                builds = !BuildStatus.HasCachePrimed ? null : GetBuilds(id, start, end).Select(b => new
                {
                    date = b.StartDate.ToEpochTime(true),
                    text = GetFlagTooltip(b),
                    link = b.WebUrl
                })
            }));
        }
        public ActionResult PollCPU(int?id = null, string node = null, string range = null)
        {
            var n = id.HasValue ? DashboardData.GetNodeById(id.Value) : DashboardData.GetNodeByName(node);

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

            var data = n.GetCPUUtilization();

            if (data == null || data.Data == null)
            {
                return(JsonNotFound());
            }

            var total = data.Data.FirstOrDefault(c => c.Name == "Total");

            return(Json(new
            {
                duration = data.Duration.TotalMilliseconds,
                cores = data.Data.Where(c => c != total).Select(c => new
                {
                    name = c.Name,
                    utilization = c.Utilization
                }),
                total = total != null ? total.Utilization : 0
            }));
        }
Пример #3
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());
        }
Пример #4
0
        public ActionResult CPUSpark(int id)
        {
            var node = DashboardData.GetNodeById(id);

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

            var chart      = GetSparkChart();
            var dataPoints = node.GetCPUUtilization(start: DateTime.UtcNow.AddHours(-SparkHours),
                                                    end: null,
                                                    pointCount: (int)chart.Width.Value);

            var area   = GetSparkChartArea(100);
            var avgCPU = GetSparkSeries("Avg Load");

            chart.Series.Add(avgCPU);

            foreach (var mp in dataPoints)
            {
                if (mp.AvgLoad.HasValue)
                {
                    avgCPU.Points.Add(new DataPoint(mp.DateTime.ToOADate(), mp.AvgLoad.Value));
                }
            }

            chart.ChartAreas.Add(area);

            return(chart.ToResult());
        }
        public async Task <JsonResult> PollCPU(string id = null, string node = null, string range = null)
        {
            var n = id.HasValue() ? DashboardData.GetNodeById(id) : DashboardData.GetNodeByName(node);

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

            var data = await n.GetCPUUtilization();

            if (data?.Data == null)
            {
                return(JsonNotFound());
            }

            var total = data.Data.FirstOrDefault(c => c.Name == "Total");

            return(Json(new
            {
                duration = data.Duration.TotalMilliseconds,
                cores = data.Data.Where(c => c != total).Select(c => new
                {
                    name = c.Name,
                    utilization = c.Utilization
                }),
                total = total?.Utilization ?? 0
            }));
        }
Пример #6
0
        public ActionResult MemorySpark(int id)
        {
            var node = DashboardData.GetNodeById(id);

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

            var chart      = GetSparkChart();
            var dataPoints = node.GetMemoryUtilization(start: DateTime.UtcNow.AddHours(-SparkHours),
                                                       end: null,
                                                       pointCount: (int)chart.Width.Value).ToList();
            var maxMem = dataPoints.Max(mp => mp.TotalMemory).GetValueOrDefault();
            var maxGB  = (int)Math.Ceiling(maxMem / _gb);

            var area = GetSparkChartArea(maxMem + (maxGB / 8) * _gb);
            var used = GetSparkSeries("Used");

            chart.Series.Add(used);

            foreach (var mp in dataPoints)
            {
                if (mp.AvgMemoryUsed.HasValue)
                {
                    used.Points.Add(new DataPoint(mp.DateTime.ToOADate(), mp.AvgMemoryUsed.Value));
                }
            }
            chart.ChartAreas.Add(area);

            return(chart.ToResult());
        }
Пример #7
0
        public async Task <ActionResult> MemoryJson(string id, long start, long end, bool?summary = false)
        {
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(JsonNotFound());
            }
            var detailPoints = await node.GetMemoryUtilization(start.ToDateTime(), end.ToDateTime(), 1000);

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

            return(Json(new
            {
                points = detailPoints.Select(p => new
                {
                    date = p.DateEpoch,
                    value = (int)(p.Value / 1024 / 1024 ?? 0)
                }),
                summary = summary.GetValueOrDefault(false) ? (await node.GetMemoryUtilization(null, null, 1000)).Select(p => new
                {
                    date = p.DateEpoch,
                    value = (int)(p.Value / 1024 / 1024 ?? 0)
                }) : null,
                builds = !BuildStatus.HasCachePrimed ? null : GetBuilds(id, start, end).Select(b => new
                {
                    date = b.StartDate.ToEpochTime(true),
                    text = GetFlagTooltip(b),
                    link = b.WebUrl
                })
            }));
        }
Пример #8
0
        public async Task <ActionResult> InterfaceSpark(string direction, string id, string iid)
        {
            MiniProfiler.Stop(true);
            var iface = DashboardData.GetNodeById(id)?.GetInterface(iid);

            if (iface == null)
            {
                return(ContentNotFound());
            }
            var points = await iface.GetUtilization(SparkStart, null, SparkPoints);

            if (points.Count == 0)
            {
                return(EmptySparkSVG());
            }

            Func <DoubleGraphPoint, double> getter = p => p.Value.GetValueOrDefault(0);

            if (direction == "out")
            {
                getter = p => p.BottomValue.GetValueOrDefault(0);
            }

            return(SparkSVG(points, Convert.ToInt64(points.Max(getter)), p => getter(p)));
        }
Пример #9
0
        public async Task <ActionResult> NodeGraph(string nodeId, string type, string subId)
        {
            var n  = DashboardData.GetNodeById(nodeId);
            var vd = new NodeGraphModel
            {
                Node = n,
                Type = type
            };

            if (n != null)
            {
                switch (type)
                {
                case NodeGraphModel.KnownTypes.CPU:
                    vd.Title     = "CPU Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                    vd.GraphData = await GraphController.CPUData(n, summary : true);

                    break;

                case NodeGraphModel.KnownTypes.Memory:
                    vd.Title     = "Memory Utilization (" + (n.TotalMemory?.ToSize() ?? "Unknown Max") + ")";
                    vd.GraphData = await GraphController.MemoryData(n, summary : true);

                    break;

                case NodeGraphModel.KnownTypes.Network:
                    if (subId.HasValue())
                    {
                        var i = vd.Node.GetInterface(subId);
                        vd.Interface = i;
                        vd.Title     = "Network Utilization (" + (i?.PrettyName ?? "Unknown") + ")";
                        vd.GraphData = await GraphController.NetworkData(i, summary : true);
                    }
                    else
                    {
                        vd.Title     = "Network Utilization (" + (n.PrettyName ?? "Unknown") + ")";
                        vd.GraphData = await GraphController.NetworkData(n, summary : true);
                    }
                    break;

                case NodeGraphModel.KnownTypes.Volume:
                    var v = vd.Node.GetVolume(subId);
                    vd.Volume = v;
                    vd.Title  = "Volume Usage (" + (v?.PrettyName ?? "Unknown") + ")";
                    break;
                }
            }

            return(View("Node.Graph", vd));
        }
Пример #10
0
        public async Task <ActionResult> NetworkSpark(string id)
        {
            MiniProfiler.Stop(true);
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(ContentNotFound());
            }
            var points = await node.GetNetworkUtilization(SparkStart, null, SparkPoints);

            return(points.Count == 0
                ? EmptySparkSVG()
                : SparkSVG(points, Convert.ToInt64(points.Max(p => p.Value + p.BottomValue).GetValueOrDefault()), p => (p.Value + p.BottomValue).GetValueOrDefault()));
        }
Пример #11
0
        public async Task <ActionResult> MemorySpark(string id)
        {
            MiniProfiler.Stop(true);
            var node = DashboardData.GetNodeById(id);

            if (node?.TotalMemory == null)
            {
                return(ContentNotFound($"Could not determine total memory for '{id}'"));
            }
            var points = await node.GetMemoryUtilization(SparkStart, null, SparkPoints);

            return(points.Count == 0
                ? EmptySparkSVG()
                : SparkSVG(points, Convert.ToInt64(node.TotalMemory.GetValueOrDefault()), p => p.Value.GetValueOrDefault()));
        }
Пример #12
0
        public async Task <ActionResult> CPUSparkSvg(string id)
        {
            MiniProfiler.Stop(true);
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(ContentNotFound());
            }
            var points = await node.GetCPUUtilization(SparkStart, null, SparkPoints);

            return(points.Count == 0
                ? EmptySparkSVG()
                : SparkSVG(points, 100, p => p.Value.GetValueOrDefault()));
        }
Пример #13
0
        public async Task <ActionResult> NetworkSpark(string id)
        {
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(ContentNotFound());
            }
            var chart      = GetSparkChart();
            var dataPoints = await node.GetNetworkUtilization(SparkStart, null, SparkPoints);

            AddPoints(chart, dataPoints, p => (p.Value + p.BottomValue).GetValueOrDefault(0));

            return(chart.ToResult());
        }
Пример #14
0
        public async Task <ActionResult> MemorySpark(string id)
        {
            var node = DashboardData.GetNodeById(id);

            if (node?.TotalMemory == null)
            {
                return(ContentNotFound($"Could not determine total memory for '{id}'"));
            }

            var chart      = GetSparkChart(max: node.TotalMemory);
            var dataPoints = await node.GetMemoryUtilization(SparkStart, null, SparkPoints);

            AddPoints(chart, dataPoints, p => p.Value.GetValueOrDefault(0));

            return(chart.ToResult());
        }
Пример #15
0
        public async Task <ActionResult> MemoryJson(string id, long?start = null, long?end = null, bool?summary = false)
        {
            var node = DashboardData.GetNodeById(id);

            if (node == null)
            {
                return(JsonNotFound());
            }
            var data = await MemoryData(node, start, end, summary);

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

            return(Json(data));
        }
Пример #16
0
        public async Task <ActionResult> NetworkJson(string id, string iid, long?start = null, long?end = null, bool?summary = false)
        {
            var iface = DashboardData.GetNodeById(id)?.GetInterface(iid);

            if (iface == null)
            {
                return(JsonNotFound());
            }
            var data = await NetworkData(iface, start, end, summary);

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

            return(Json(data));
        }
Пример #17
0
        private static IEnumerable <Build> GetBuilds(string id, long startEpoch, long endEpoch)
        {
            if (!Current.Settings.TeamCity.Enabled)
            {
                return(Enumerable.Empty <Build>());
            }

            // only show builds when zoomed in, say 5 days for starters?
            //TODO: Move this to a setting
            if ((endEpoch - startEpoch) > TimeSpan.FromDays(30).TotalSeconds)
            {
                return(new List <Build>());
            }

            var      node = DashboardData.GetNodeById(id);
            DateTime start = startEpoch.ToDateTime(), end = endEpoch.ToDateTime();

            return(BuildStatus.GetBuildsByServer(node.PrettyName).Where(b => b.StartDate >= start && b.StartDate <= end));
        }
Пример #18
0
        public async Task <ActionResult> InterfaceOutSpark(string direction, string id, string iid)
        {
            var iface = DashboardData.GetNodeById(id)?.GetInterface(iid);

            if (iface == null)
            {
                return(ContentNotFound());
            }
            var chart      = GetSparkChart();
            var dataPoints = await iface.GetUtilization(SparkStart, null, SparkPoints);

            Func <DoubleGraphPoint, double> getter = p => p.Value.GetValueOrDefault(0);

            if (direction == "out")
            {
                getter = p => p.BottomValue.GetValueOrDefault(0);
            }
            AddPoints(chart, dataPoints, getter);

            return(chart.ToResult());
        }
Пример #19
0
        public async Task <ActionResult> NetworkJson(string id, string iid, long start, long end, bool?summary = false)
        {
            var iface = DashboardData.GetNodeById(id)?.GetInterface(iid);

            if (iface == null)
            {
                return(JsonNotFound());
            }
            var traffic = await iface.GetUtilization(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.Value.GetValueOrDefault(0)) : 0,
                    main_out = anyTraffic ? traffic.Max(i => (int)i.BottomValue.GetValueOrDefault(0)) : 0
                },
                points = traffic.Select(i => new
                {
                    date = i.DateEpoch,
                    main_in = (int)(i.Value.GetValueOrDefault()),
                    main_out = (int)(i.BottomValue.GetValueOrDefault())
                }),
                summary = summary.GetValueOrDefault()
                                  ? (await iface.GetUtilization(null, null, 2000)).Select(i => new
                {
                    date = i.DateEpoch,
                    main_in = (int)(i.Value.GetValueOrDefault()),
                    main_out = (int)(i.BottomValue.GetValueOrDefault())
                })
                                  : null
            }));
        }