public void Format_WithTagContainingEqualSign_IsSuccessful()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name = "cpu",
                Timestamp = DateTime.Parse("2015-10-26 13:48Z")
            };
            m.AddField("alarm", false).AddField("Message", "Testing messages").AddTag("token","5#4g==");

            string expectedFormat = "cpu,token=5#4g\\=\\= alarm=false,Message=\"Testing messages\" 1445867280000000000";
            string retval = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual<string>(expectedFormat, retval);
        }
        public void Format_WithNoTags_IsSuccessful()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name = "cpu",
                Timestamp = DateTime.Parse("10/26/2015 13:48Z")
            };
            m.AddField("alarm", false).AddField("Message", "Testing messages");

            string expectedFormat = "cpu alarm=false,Message=\"Testing messages\" 1445867280000000000";
            string retval = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual<string>(expectedFormat, retval);
        }
        public void Format_WithTagContainingEqualSign_IsSuccessful()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name      = "cpu",
                Timestamp = DateTime.Parse("2015-10-26 13:48Z")
            };

            m.AddField("alarm", false).AddField("Message", "Testing messages").AddTag("token", "5#4g==");

            string expectedFormat = "cpu,token=5#4g\\=\\= alarm=false,Message=\"Testing messages\" 1445867280000000000";
            string retval         = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual <string>(expectedFormat, retval);
        }
        public void Format_WithValidMeasurement_IsSuccessful()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name = "cpu",
                Timestamp = DateTime.Parse("2015-10-26 13:48Z")
            };
            m.AddTag("host", "server01").AddTag("region", "us-west");
            m.AddField("alarm", false).AddField("Message", "Testing messages");

            string expectedFormat = "cpu,host=server01,region=us-west alarm=false,Message=\"Testing messages\" 1445867280000000000";
            string retval = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual<string>(expectedFormat, retval);
        }
Esempio n. 5
0
        public void Integer64bit()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name      = "foo",
                Timestamp = DateTime.Parse("2020-02-21 08:27Z")
            };

            m.AddField("int_max", int.MaxValue).AddField("long_max", long.MaxValue);

            string expectedFormat = "foo int_max=2147483647i,long_max=9223372036854775807i 1582273620000000000";
            string retval         = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual <string>(expectedFormat, retval);
        }
        public void Format_WithValidMeasurement_IsSuccessful()
        {
            //  Arrange
            Measurement m = new Measurement()
            {
                Name      = "cpu",
                Timestamp = DateTime.Parse("2015-10-26 13:48Z")
            };

            m.AddTag("host", "server01").AddTag("region", "us-west");
            m.AddField("alarm", false).AddField("Message", "Testing messages");

            string expectedFormat = "cpu,host=server01,region=us-west alarm=false,Message=\"Testing messages\" 1445867280000000000";
            string retval         = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual <string>(expectedFormat, retval);
        }
        public void Float64bit()
        {
            // Make sure correct decimal symbol is used in test case
            System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            //  Arrange
            Measurement m = new Measurement()
            {
                Name      = "foo",
                Timestamp = DateTime.Parse("2020-01-02 16:08Z")
            };

            m.AddField("float_max", float.MaxValue).AddField("double_max", double.MaxValue);

            string expectedFormat = "foo float_max=3.40282346638529E+38,double_max=1.79769313486232E+308 1577981280000000000"; // TODO Variant
            string retval         = string.Empty;

            //  Act
            retval = LineProtocol.Format(m);

            //  Assert
            Assert.AreEqual <string>(expectedFormat, retval);
        }
Esempio n. 8
0
        private void SmartCheckMapFields(Measurement measurement, List <FieldItem> fields)
        {
            foreach (var field in fields)
            {
                var fieldIndex = measurement.FindFieldIndex(field.Name);
                if (fieldIndex == -1)
                {
                    field.Index = measurement.AddField(field.Name);
                }

                var map = measurement.MappingTable.FindBySource(field.Name);
                if (map == null)
                {
                    map = new Mapping
                    {
                        Source = field.Name,
                        Target = field.Name,
                        Type   = field.Type,
                        Unit   = field.Unit
                    };
                    measurement.MappingTable.Mappings.Add(map);
                }
            }
        }
Esempio n. 9
0
        public static Measurement buildMeasurement(String measurement, Dictionary <String, object> fields, Dictionary <String, String> tags, DateTime timestamp)
        {
            Measurement m = new Measurement(measurement);

            if (timestamp != null)
            {
                int milliRotate = random.Next(0, 999);
                int minRotate   = random.Next(0, 59);
                int secRotate   = random.Next(0, 59);
                int hrRotate    = random.Next(0, 59);
                rotate++;
                if (rotate % 1000 == 0 || (milliRotate + rotate) >= 1000)
                {
                    rotate = 0;
                }

                DateTime iTimeStamp = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, DateTime.Now.Hour, minRotate, secRotate, milliRotate + rotate);
                m.Timestamp = iTimeStamp;

                if (stampList.Contains(iTimeStamp))
                {
                    log.Error("Duplicate time stamp detected: " + ++count + " time: " + timestamp);
                }
                stampList.Add(iTimeStamp);
            }
            if (fields != null)
            {
                foreach (KeyValuePair <String, object> item in fields)
                {
                    if (item.Value is int)
                    {
                        m.AddField(item.Key, (int)item.Value);
                    }
                    else if (item.Value is float)
                    {
                        m.AddField(item.Key, (float)item.Value);
                    }
                    else if (item.Value is string)
                    {
                        m.AddField(item.Key, (string)item.Value);
                    }
                }
            }
            if (tags != null)
            {
                foreach (KeyValuePair <String, String> item in tags)
                {
                    String itemValue = item.Value;
                    if (String.IsNullOrEmpty(itemValue) || String.IsNullOrWhiteSpace(itemValue))
                    {
                        itemValue = "<empty>";
                    }
                    else if (itemValue.Contains(System.Environment.NewLine))
                    {
                        itemValue = itemValue.Replace(System.Environment.NewLine, "");
                    }

                    m.AddTag(item.Key, itemValue);
                }
            }
            return(m);
        }