public void StringWithDimensionsList()
        {
            var parser = new EventMessageParser("A tick! Dimensions: (InstanceID: qwerty, Fruit: apple) Value: 4.5 Seconds");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(2, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("InstanceID", r.MetricData[0].Dimensions[0].Name);
                Assert.AreEqual("qwerty", r.MetricData[0].Dimensions[0].Value);
                Assert.AreEqual("Fruit", r.MetricData[0].Dimensions[1].Name);
                Assert.AreEqual("apple", r.MetricData[0].Dimensions[1].Value);

                Assert.AreEqual("Seconds", r.MetricData[0].Unit);
                Assert.AreEqual(4.5, r.MetricData[0].Value);

                passes++;
            }

            Assert.AreEqual(1, passes);

            //Not plural, should work anyway
            parser = new EventMessageParser("A tick! Dimension: (InstanceID: qwerty, Fruit: apple)");
            parser.Parse();

            foreach (var r in parser)
                Assert.AreEqual(2, r.MetricData[0].Dimensions.Count);
        }
        public void StringWithDimensionsList_Empties()
        {
            var parser = new EventMessageParser("A tick! Dimensions: (InstanceID: , Fruit: ) Value: 4.5 Seconds");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(0, r.MetricData[0].Dimensions.Count);

                Assert.AreEqual("Seconds", r.MetricData[0].Unit);
                Assert.AreEqual(4.5, r.MetricData[0].Value);

                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithTimestamp_Override()
        {
            var parser = new EventMessageParser("A tick! Timestamp: 2012-09-06 17:55:55 +02:00")
                             {
                                 DefaultTimestamp = DateTimeOffset.Parse("2012-09-06 12:55:55 +02:00")
                             };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(DateTime.Parse("2012-09-06 10:55:55"), r.MetricData[0].Timestamp);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithTimestamp()
        {
            var parser = new EventMessageParser("A tick! Timestamp: 2012-09-06 17:55:55 +02:00");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(DateTime.Parse("2012-09-06 15:55:55"), r.MetricData[0].Timestamp);
                passes++;
            }

            Assert.AreEqual(1, passes);

            parser = new EventMessageParser("A tick! Timestamp: 2012-09-06 15:55:55");
            parser.Parse();

            foreach (var r in parser)
                Assert.AreEqual(DateTime.Parse("2012-09-06 15:55:55"), r.MetricData[0].Timestamp);
        }
        public void StringWithStatistics_Overrides()
        {
            var parser =
                new EventMessageParser(
                    "A tick! SampleCount: 3000, Minimum: 1.3 Gigabits/Second, Maximum: 127.9 Gigabits/Second, Sum: 15000.1 Gigabits/Second")
                    {
                        DefaultSampleCount = 4000,
                        DefaultMinimum = 1.2,
                        DefaultMaximum = 130.5,
                        DefaultSum = 16000.5
                    };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("Gigabits/Second", r.MetricData[0].Unit);
                Assert.AreEqual(1.2, r.MetricData[0].StatisticValues.Minimum);
                Assert.AreEqual(130.5, r.MetricData[0].StatisticValues.Maximum);
                Assert.AreEqual(16000.5, r.MetricData[0].StatisticValues.Sum);
                Assert.AreEqual(4000, r.MetricData[0].StatisticValues.SampleCount);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithStatistics()
        {
            var parser = new EventMessageParser("A tick! SampleCount: 3000, Minimum: 1.3 Gigabits/Second, Maximum: 127.9 Gigabits/Second, Sum: 15000.5 Gigabits/Second");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("Gigabits/Second", r.MetricData[0].Unit);
                Assert.AreEqual(1.3, r.MetricData[0].StatisticValues.Minimum);
                Assert.AreEqual(127.9, r.MetricData[0].StatisticValues.Maximum);
                Assert.AreEqual(15000.5, r.MetricData[0].StatisticValues.Sum);
                Assert.AreEqual(3000, r.MetricData[0].StatisticValues.SampleCount);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithSingleValueAndUnit_Overrides()
        {
            var parser = new EventMessageParser("A tick! Value: 3.0 Kilobytes/Second")
                             {
                                 DefaultValue = 4.0,
                                 DefaultUnit = "Megabytes/Second"
                             };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("Megabytes/Second", r.MetricData[0].Unit);
                Assert.AreEqual(4.0, r.MetricData[0].Value);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithDimensionsList_Overrides_Empties()
        {
            var parser = new EventMessageParser("A tick! Dimensions: (InstanceID: qwerty, Fruit: , Nuts: walnuts) Value: 4.5 Seconds")
                             {
                                 DefaultDimensions = new Dictionary<string, Dimension>
                                                         {
                                                             {"InstanceID", new Dimension{Name="InstanceID", Value = "asdfg"}},
                                                             {"Cake", new Dimension{Name="Cake", Value = "chocolate"}},
                                                             {"Nuts", new Dimension{Name="Nuts", Value = ""}}
                                                         }
                             };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(2, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("InstanceID", r.MetricData[0].Dimensions[0].Name);
                Assert.AreEqual("asdfg", r.MetricData[0].Dimensions[0].Value);
                Assert.AreEqual("Cake", r.MetricData[0].Dimensions[1].Name);
                Assert.AreEqual("chocolate", r.MetricData[0].Dimensions[1].Value);

                Assert.AreEqual("Seconds", r.MetricData[0].Unit);
                Assert.AreEqual(4.5, r.MetricData[0].Value);

                passes++;
            }

            Assert.AreEqual(1, passes);
        }
        public void StringWithSingleDimension()
        {
            var parser = new EventMessageParser("A tick! Dimension: InstanceID: qwerty Value: 4.5 Seconds");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(1, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("InstanceID", r.MetricData[0].Dimensions[0].Name);
                Assert.AreEqual("qwerty", r.MetricData[0].Dimensions[0].Value);

                Assert.AreEqual("Seconds", r.MetricData[0].Unit);
                Assert.AreEqual(4.5, r.MetricData[0].Value);

                passes++;
            }

            Assert.AreEqual(1, passes);
        }
Exemplo n.º 10
0
        public void StringWithNothingRecognizableShouldProduceCount1()
        {
            var parser = new EventMessageParser("A tick");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("CloudWatchAppender", r.Namespace);
                Assert.AreEqual(1, r.MetricData.Count);
                Assert.AreEqual(0, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("CloudWatchAppender", r.MetricData[0].MetricName);
                Assert.AreEqual("Count", r.MetricData[0].Unit);
                Assert.AreEqual(1.0, r.MetricData[0].Value);

                passes++;
            }
            Assert.AreEqual(1, passes);
        }
Exemplo n.º 11
0
        public void StringWithNameSpace()
        {
            var parser = new EventMessageParser("A tick! NameSpace: NewNameSpace");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("NewNameSpace", r.Namespace);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
Exemplo n.º 12
0
        public void StringWithMetricNameAndNameSpace_Overrides()
        {
            var parser = new EventMessageParser("A tick! Name: NewName NameSpace: NewNameSpace")
                             {
                                 DefaultMetricName = "DefaultMetricName",
                                 DefaultNameSpace = "DefaultNameSpace"
                             };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("DefaultMetricName", r.MetricData[0].MetricName);
                Assert.AreEqual("DefaultNameSpace", r.Namespace);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
Exemplo n.º 13
0
        public void StringWithMetricName()
        {
            var parser = new EventMessageParser("A tick! MetricName: NewName");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("NewName", r.MetricData[0].MetricName);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
Exemplo n.º 14
0
        public void StringWithDimensionUnfinishedParenthsTriesToParseAsDimensionSkippingUnit()
        {
            //Plural, with unended parenths, should work anyway
            var parser = new EventMessageParser("A tick! Dimensions: (InstanceID: qwerty Value: 4.5 Seconds");
            parser.Parse();

            foreach (var r in parser)
            {
                Assert.AreEqual(2, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("InstanceID", r.MetricData[0].Dimensions[0].Name);
                Assert.AreEqual("qwerty", r.MetricData[0].Dimensions[0].Value);
                Assert.AreEqual("Value", r.MetricData[0].Dimensions[1].Name);
                Assert.AreEqual("4.5", r.MetricData[0].Dimensions[1].Value);

                Assert.AreEqual("Count", r.MetricData[0].Unit);
                Assert.AreEqual(1.0, r.MetricData[0].Value);
            }
        }
Exemplo n.º 15
0
        public void StringWithSingleValueAndUnit()
        {
            var parser = new EventMessageParser("A tick! Value: 3.0 Kilobytes/Second");
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual("Kilobytes/Second", r.MetricData[0].Unit);
                Assert.AreEqual(3.0, r.MetricData[0].Value);
                passes++;
            }

            Assert.AreEqual(1, passes);
        }
Exemplo n.º 16
0
        public void StringWithDimensionsList_Overrides()
        {
            var parser = new EventMessageParser("A tick! Dimensions: (InstanceID: qwerty, Fruit: apple) Value: 4.5 Seconds")
                             {
                                 DefaultDimensions = new Dictionary<string, Dimension>
                                                         {
                                                             {"InstanceID", new Dimension{Name="InstanceID", Value = "asdfg"}},
                                                             {"Cake", new Dimension{Name="Cake", Value = "chocolate"}}
                                                         }
                             };
            parser.Parse();

            var passes = 0;
            foreach (var r in parser)
            {
                Assert.AreEqual(3, r.MetricData[0].Dimensions.Count);
                Assert.AreEqual("InstanceID", r.MetricData[0].Dimensions[0].Name);
                Assert.AreEqual("asdfg", r.MetricData[0].Dimensions[0].Value);
                Assert.AreEqual("Cake", r.MetricData[0].Dimensions[1].Name);
                Assert.AreEqual("chocolate", r.MetricData[0].Dimensions[1].Value);
                Assert.AreEqual("Fruit", r.MetricData[0].Dimensions[2].Name);
                Assert.AreEqual("apple", r.MetricData[0].Dimensions[2].Value);

                Assert.AreEqual("Seconds", r.MetricData[0].Unit);
                Assert.AreEqual(4.5, r.MetricData[0].Value);

                passes++;
            }

            Assert.AreEqual(1, passes);

            //Not plural, should work anyway
            parser = new EventMessageParser("A tick! Dimension: (InstanceID: qwerty, Fruit: apple)");
            parser.Parse();

            foreach (var r in parser)
                Assert.AreEqual(2, r.MetricData[0].Dimensions.Count);
        }
        protected override void Append(LoggingEvent loggingEvent)
        {
            System.Diagnostics.Debug.WriteLine("Appending");

            if (!_eventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                System.Diagnostics.Debug.WriteLine("Appending denied due to event saturation.");
                return;
            }

            if (Layout == null)
                Layout = new PatternLayout("%message");

            var renderedString = RenderLoggingEvent(loggingEvent);

            var patternParser = new PatternParser(loggingEvent);

            if (renderedString.Contains("%"))
                renderedString = patternParser.Parse(renderedString);

            System.Diagnostics.Debug.WriteLine(string.Format("RenderedString: {0}", renderedString));

            ParseProperties(patternParser);

            var parser = new EventMessageParser(renderedString, ConfigOverrides)
                        {
                            DefaultMetricName = _defaultMetricName,
                            DefaultNameSpace = _parsedNamespace,
                            DefaultUnit = _parsedUnit,
                            DefaultDimensions = _parsedDimensions,
                            DefaultTimestamp = _dateTimeOffset
                        };

            if (!string.IsNullOrEmpty(Value) && ConfigOverrides)
                parser.DefaultValue = Double.Parse(Value, CultureInfo.InvariantCulture);

            parser.Parse();

            foreach (var putMetricDataRequest in parser)
                SendItOff(putMetricDataRequest);
        }