示例#1
0
        protected List <IngestElement> ConvertMetricsAttributesAndRelationsToIngestElements(List <CollectableValue> metricsAttributes)
        {
            List <IngestElement> ieList = new List <IngestElement>();

            foreach (CollectableValue value in metricsAttributes)
            {
                string        elementType = (value.ElementType == null) ? _defaultElementType : value.ElementType;
                IngestElement ie          = new IngestElement(value.HostName, value.HostName, elementType, _location);

                if (value is MetricValue)
                {
                    List <IngestMetric> outMetrics = null;
                    List <IngestSample> outSamples = null;
                    GetIngestMetrics((MetricValue)value, out outMetrics, out outSamples);

                    ie.addMetrics(outMetrics);
                    ie.addSamples(outSamples);
                }
                else if (value is AttributeValue)
                {
                    List <IngestAttribute> outAttributes = null;
                    GetIngestAttributes((AttributeValue)value, out outAttributes);
                    ie.addAttributes(outAttributes);
                }
                else if (value is RelationValue)
                {
                    List <IngestRelation> outRelation = null;
                    GetIngestRelations((RelationValue)value, out outRelation);
                    ie.addRelations(outRelation);
                }
                ieList.Add(ie);
            }

            return(ieList);
        }
示例#2
0
        protected List <IngestElement> MergeIngestElements(List <IngestElement> ieList)
        {
            // Merge elements of the same Id together subject to max payload size
            List <IngestElement> mergedList = new List <IngestElement>();
            IngestElement        current    = null;
            int payloadSize = 0;
            int counter     = 0;

            foreach (IngestElement element in ieList)
            {
                counter++;
                if (current != null && element.id.Equals(current.id) && payloadSize < _payloadSize && counter < ieList.Count)
                {
                    // This element is the same as the current one - merge them
                    current.mergeWith(element);
                    payloadSize += element.getPayloadSize();
                }
                else
                {
                    // This is a different element - add this to the list and start a new
                    if (current != null)
                    {
                        mergedList.Add(current);
                    }

                    current     = element;
                    payloadSize = element.getPayloadSize();
                }
            }
            return(mergedList);
        }
        public List <IngestElement> ExtractElementsFromCollectables(Queue <CollectableValue> values)
        {
            List <IngestElement> elements =
                values
                .OfType <IngestValue>()
                .Select(value =>
            {
                string elementType    = (value.ElementType == null) ? _defaultElementType : value.ElementType;
                IngestElement element = new IngestElement(value.HostName, value.HostName, elementType, _location);

                if (value is MetricValue)
                {
                    AddMetrics((MetricValue)value, element);
                }
                else if (value is AttributeValue)
                {
                    element.addAttribute(new IngestAttribute(((AttributeValue)value).Name, ((AttributeValue)value).Value));
                }
                else if (value is RelationValue)
                {
                    element.addRelation(new IngestRelation(((RelationValue)value).Fqn));
                }
                else if (value is TagValue)
                {
                    element.addTag(new IngestTag(((TagValue)value).Name, ((TagValue)value).Value));
                }
                return(element);
            })
                .OrderBy(ingestElement => ingestElement.id).ToList();

            return(elements);
        }
        /**
         * Merge elements of the same Id together subject to max payload size
         */
        protected List <IngestElement> MergeElements(List <IngestElement> ieList)
        {
            List <IngestElement> mergedList = new List <IngestElement>();
            IngestElement        current    = null;
            int payloadSize = 0;

            foreach (IngestElement element in ieList)
            {
                if (current != null && element.id.Equals(current.id) && payloadSize < _payloadSize)
                {
                    // This element is the same as the current one - merge them
                    current.mergeWith(element);
                    payloadSize += element.getPayloadSize();
                }
                else
                {
                    // This is a different element - add this to the list and start a new
                    if (current != null)
                    {
                        mergedList.Add(current);
                    }

                    current     = element;
                    payloadSize = element.getPayloadSize();
                }
            }
            // Add the final working element
            if (current != null)
            {
                mergedList.Add(current);
            }

            return(mergedList);
        }
        public void AddMetrics(MetricValue metric, IngestElement element)
        {
            string metricId = metric.PluginName;

            if (metric.PluginInstanceName.Length > 0)
            {
                metricId += "." + metric.PluginInstanceName;
            }
            if (metric.TypeInstanceName.Length > 0)
            {
                metricId += "." + metric.TypeInstanceName;
            }

            IList <DataSource> dsList = DataSetCollection.Instance.GetDataSource(metric.TypeName);
            var dsNames = new List <string>();
            var dsTypes = new List <string>();

            if (dsList == null)
            {
                Logger.Error("Invalid type : {0}, not found in types.db", metric.TypeName);
                return;
            }
            else
            {
                foreach (DataSource ds in dsList)
                {
                    dsNames.Add(ds.Name);
                    dsTypes.Add(ds.Type.ToString().ToLower());
                }
            }

            metricId = Regex.Replace(metricId, "[ ]", "_");              // Keep spaces as underscores
            metricId = Regex.Replace(metricId, "[^a-zA-Z0-9\\._-]", ""); // Remove punctuation
            if (metric.Values.Length == 1)
            {
                // Simple case - just one metric in type
                string friendlyName = metric.FriendlyNames == null ? metricId : metric.FriendlyNames[0];
                element.addMetric(new IngestMetric(metricId, friendlyName, metric.TypeName, dsTypes[0]));
                element.addSample(new IngestSample(metricId, (long)metric.Timestamp * 1000, metric.Values[0]));
            }
            else if (metric.Values.Length > 1)
            {
                // Compound type with multiple metrics
                int ix = 0;
                foreach (DataSource ds in dsList)
                {
                    // Include the Types.db suffix in the metric name
                    string friendlyName = metric.FriendlyNames == null ? metricId : metric.FriendlyNames[ix];

                    element.addMetric(new IngestMetric(metricId + "." + ds.Name, friendlyName, metric.TypeName, dsTypes[ix]));
                    element.addSample(new IngestSample(metricId + "." + ds.Name, (long)metric.Timestamp * 1000, metric.Values[ix]));
                    ix++;
                }
            }
        }
示例#6
0
        public void mergeWith(IngestElement that)
        {
            if (!this.id.Equals(that.id))
            {   // shouldn't happen
                throw new Exception("Bad merge operation");
            }

            this.addMetrics(that.metrics);
            this.addSamples(that.samples);
            this.addAttributes(that.attributes);
            this.addRelations(that.relations);
        }
        public void mergeWith(IngestElement that)
        {
            if (!this.id.Equals(that.id))
            {   // shouldn't happen
                throw new Exception("Bad merge operation");
            }

            this.addMetrics(that.metrics);
            this.addSamples(that.samples);
            this.addAttributes(that.attributes);
            this.addRelations(that.relations);
        }
        protected List<IngestElement> ConvertMetricsAttributesAndRelationsToIngestElements(List<CollectableValue> metricsAttributes)
        {
            List<IngestElement> ieList = new List<IngestElement>();
            foreach (CollectableValue value in metricsAttributes)
            {
                string elementType = (value.ElementType == null) ? _defaultElementType : value.ElementType;
                IngestElement ie = new IngestElement(value.HostName, value.HostName, elementType, _location);

                if (value is MetricValue)
                {
                    List<IngestMetric> outMetrics = null;
                    List<IngestSample> outSamples = null;
                    GetIngestMetrics((MetricValue)value, out outMetrics, out outSamples);

                    ie.addMetrics(outMetrics);
                    ie.addSamples(outSamples);
                }
                else if (value is AttributeValue)
                {
                    List<IngestAttribute> outAttributes = null;
                    GetIngestAttributes((AttributeValue)value, out outAttributes);
                    ie.addAttributes(outAttributes);
                }
                else if (value is RelationValue)
                {
                    List<IngestRelation> outRelation = null;
                    GetIngestRelations((RelationValue)value, out outRelation);
                    ie.addRelations(outRelation);

                }
                ieList.Add(ie);
            }

            return ieList;
        }