private async Task insertContainerMetric(BenchmarkExperiment appTest) { var metricStat = new ContainerMetric(); IProgress <ContainerStatsResponse> progress = new Progress <ContainerStatsResponse>(stats => { //var json = JsonConvert.SerializeObject(stats); metricStat.ContainerId = appTest.AppContainerId; metricStat.ContainerName = appTest.DockerFriendlyName; metricStat.DateTimeCreated = DateTime.UtcNow; metricStat.DockerDateTimestamp = stats.Read; //JsonDockerResponse = json, metricStat.BenchmarkExperiment = appTest; metricStat.MemoryLimit = stats.MemoryStats.Limit; metricStat.MemoryUsage = stats.MemoryStats.Usage; metricStat.SetCPUPercentage(stats.CPUStats, stats.PreCPUStats); metricStat.CalculateNetworks(stats.Networks); metricStat.CalculateBlockIO(stats.BlkioStats); //testList.Add(metricStat); }); await _dockerAppClient.Containers.GetContainerStatsAsync(appTest.AppContainerId, new ContainerStatsParameters { Stream = false }, progress, CancellationToken.None); await _containerMetricRepo.AddAsync(metricStat); }
protected override void EstablishContext() { //Prepare supplied data collections suppliedMetricHirearchy = GetSuppliedMetricHierarchy(); //Set up the mocks //Set expectations }
protected override void EstablishContext() { metricTemplateBinder.Setup(x => x.GetTemplateName(It.IsAny<Dictionary<string, string>>())).Callback<Dictionary<string, string>>(x => postedContextValues.Add(x)).Returns("template name"); metricRenderer.Setup(x => x.Render(It.IsAny<String>(), It.IsAny<MetricBase>(), It.IsAny<int>(), It.IsAny<IDictionary<string, object>>())).Callback((string templateName, object mb, int depth, IDictionary<string, object> dictionary) => postedMetricRenderingValues.Add(new MetricRenderingParameters { TemplateName = templateName, MetricBase = (MetricBase)mb, Depth = depth })); metricBase = GetSuppliedMetricBase(); metricRenderingContextProvider.Setup(x => x.ProvideContext(It.IsAny<MetricBase>(), It.IsAny<IDictionary<string, object>>())).Callback((MetricBase m, IDictionary<string, object> d) => contextDictionary["AggregateMetricId"] = m.MetricId); rootMetric = (ContainerMetric) metricBase; suppliedRenderingMode = RenderingMode.Overview; }
public IEnumerable<KeyValuePair<string, object>> FlattenMetricTree(ContainerMetric metricTreeRootNode) { var model = new List<KeyValuePair<string, object>>(); //We only export metrics that can contain data. var granularMetrics = metricTreeRootNode.DescendantsOrSelf.Where(x => x.MetricType == MetricType.GranularMetric); foreach (dynamic metric in granularMetrics) { var propertyName = Utilities.Metrics.GetMetricName(metric); model.Add(new KeyValuePair<string, object>(propertyName,metric.Value)); } return model; }
private void SetParent(ContainerMetric parent) { foreach (var child in parent.Children) { var container = child as ContainerMetric; if (container != null) SetParent(container); child.Parent = parent; } }
private MetricBase GetSuppliedMetricInstanceTree() { var metricBase = new ContainerMetric { MetricId = 1, MetricNodeId = 1, Name = "Metric One", MetricType = MetricType.ContainerMetric, Children = new List<MetricBase> { new GranularMetric<int> { MetricId = 2, MetricNodeId = 2, Name = "Metric Two", Value = 55, MetricType = MetricType.GranularMetric }, new AggregateMetric { MetricId = 3, MetricNodeId = 3, Name = "Metric Three", MetricType = MetricType.AggregateMetric, Children = new List<MetricBase> { new GranularMetric<int> { MetricId = 4, MetricNodeId = 4, Name = "Metric Four", Value = 2155, MetricType = MetricType.GranularMetric } } } } }; SetParent(metricBase); return metricBase; }
protected virtual void ProcessForChildren(MetricInstanceSetRequestBase metricInstanceSetRequest, MetricMetadataNode metricMetadataNode, MetricDataContainer metricDataContainer, ContainerMetric parentMetric, Dictionary<string, object> initializationActivityData) { // Initialize the list if it's not already initialized if (parentMetric.Children == null) parentMetric.Children = new List<MetricBase>(); // Iterate through the children in the metadata foreach (var node in metricMetadataNode.Children) { // Call recursively to create the tree var newChildMetric = CreateMetric(metricInstanceSetRequest, node, metricDataContainer, parentMetric, initializationActivityData); parentMetric.Children.Add(newChildMetric); } }
protected ContainerMetric GetSuppliedMetricHierarchy() { var hirearchy = new ContainerMetric { MetricNodeId = 1, MetricType = MetricType.ContainerMetric, DisplayName = "Overview Root", Children = new List<MetricBase> { new ContainerMetric { MetricNodeId = 11, MetricType = MetricType.ContainerMetric, DisplayName="Assessments", Children = new List<MetricBase> { new AggregateMetric { MetricNodeId = 111, MetricType = MetricType.AggregateMetric, DisplayName="State Assessments", Children = new List<MetricBase> { new ContainerMetric { MetricNodeId = 1111, MetricType = MetricType.ContainerMetric, DisplayName = "State Assessment one", Children = new List<MetricBase> { new GranularMetric<int> { MetricNodeId = 11111, DisplayName = "Assessment X 11111", Value = 11111, MetricType = MetricType.GranularMetric}, new GranularMetric<int> { MetricNodeId = 11112, DisplayName = "Assessment Y 11112",Value = 11112, MetricType = MetricType.GranularMetric }, new GranularMetric<int> { MetricNodeId = 11113, DisplayName = "Assessment Z 11113",Value = 11113, MetricType = MetricType.GranularMetric } } } } }, new AggregateMetric { MetricNodeId = 112, MetricType = MetricType.AggregateMetric, DisplayName="Other Standard Assessments", Children = new List<MetricBase> { new ContainerMetric { MetricNodeId = 1121, MetricType = MetricType.ContainerMetric, DisplayName = "SAT", Children = new List<MetricBase> { new GranularMetric<int> { MetricNodeId = 11211, DisplayName = "Math 11211", Value = 11211, MetricType = MetricType.GranularMetric }, new GranularMetric<int> { MetricNodeId = 11212, DisplayName = "Science 11212", Value = 11212, MetricType = MetricType.GranularMetric }, new GranularMetric<int> { MetricNodeId = 11213, DisplayName = "Social Studies 11213", Value = 11213, MetricType = MetricType.GranularMetric } } } } }, } }, new ContainerMetric { MetricNodeId = 12, MetricType = MetricType.ContainerMetric, DisplayName = "Attendance & Discipline", Children = new List<MetricBase> { new GranularMetric<int> { MetricNodeId = 121, DisplayName = "Attendance 121", Value = 121, MetricType = MetricType.GranularMetric }, new GranularMetric<int> { MetricNodeId = 122, DisplayName = "Discipline 122", Value = 122, MetricType = MetricType.GranularMetric } } } } }; setParents(hirearchy, null); return hirearchy; }
private MetricBase GetSuppliedMetricBase() { var tree = new ContainerMetric { MetricId = 1, MetricVariantId = 1000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, DomainEntityType = "StudentSchool", Children = new List<MetricBase> { new GranularMetric<int> { MetricId = 2, MetricVariantId = 2000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Value = 5, Enabled = false }, new AggregateMetric { MetricId = 5, MetricVariantId = 5000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Children = new List<MetricBase> { new GranularMetric<decimal> { MetricId = 10, MetricVariantId = 10000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Value = 99, Enabled = true }, new ContainerMetric { MetricId = 11, MetricVariantId = 11000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Children = new List<MetricBase> { new GranularMetric<decimal?> { MetricId = 12, MetricVariantId = 12000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Value = null } } }, new ContainerMetric { MetricId = 13, MetricVariantId = 13000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Children = new List<MetricBase> { new GranularMetric<decimal?> { MetricId = 14, MetricVariantId = 14000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Value = null }, new GranularMetric<decimal?> { MetricId = 15, MetricVariantId = 15000, // This is intentionally MetricId * 1000 MetricVariantType = MetricVariantType.CurrentYear, Value = 3.4m }, new GranularMetric<decimal?> { MetricId = 15, // This is intentionally 15 (matching previous entry), testing the metric variants MetricVariantId = 30000, // This is intentionally MetricId * 2000 MetricVariantType = MetricVariantType.PriorYear, Value = 3.4m } } } } } } }; InitializeParent(tree, tree.Children); return tree; }
private void InitializeParent(ContainerMetric parent, IEnumerable<MetricBase> children ) { foreach (var metric in children) { metric.Parent = parent; var container = metric as ContainerMetric; if (container != null) InitializeParent(container, container.Children); } }