public void InfluxBatch_FormatsTo_LineProtocol()
        {
            var testNow    = new DateTime(2016, 6, 1, 0, 0, 0, DateTimeKind.Utc);
            var testTags   = TagTestCases.Select(tc => tc.Tag);
            var testFields = FieldTestCases.Select(tc => tc.Field);
            var precision  = InfluxConfig.Default.Precision;
            var expTime    = InfluxLineProtocol.FormatTimestamp(testNow, precision);

            // test with empty batch
            InfluxBatch batch = new InfluxBatch();

            batch.ToLineProtocol(precision).Should().BeEmpty();

            // test with single record
            batch.Add(new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) }));
            batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(@"test_name,tag1=value1 field1=123456i");
            batch.Clear();

            // test with multiple records
            batch.Add(new InfluxRecord("test_name1", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) }));
            batch.Add(new InfluxRecord("test_name2", new[] { new InfluxTag("tag2", "value2") }, new[] { new InfluxField("field2", 234561) }));
            batch.Add(new InfluxRecord("test_name3", new[] { new InfluxTag("tag3", "value3") }, new[] { new InfluxField("field3", 345612) }, testNow));
            batch.Add(new InfluxRecord("test_name4", new[] { new InfluxTag("tag4", "value4") }, new[] { new InfluxField("field4", 456123) }, testNow));
            batch.Add(new InfluxRecord("test_name5", new[] { new InfluxTag("tag5", "value5") }, new[] { new InfluxField("field5", 561234) }, testNow));

            String expOutput = String.Join("\n",
                                           $@"test_name1,tag1=value1 field1=123456i",
                                           $@"test_name2,tag2=value2 field2=234561i",
                                           $@"test_name3,tag3=value3 field3=345612i {expTime}",
                                           $@"test_name4,tag4=value4 field4=456123i {expTime}",
                                           $@"test_name5,tag5=value5 field5=561234i {expTime}"
                                           );

            batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(expOutput);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the byte representation of the <see cref="InfluxBatch"/> in LineProtocol syntax using UTF8 encoding.
        /// </summary>
        /// <param name="batch">The batch to get the bytes for.</param>
        /// <returns>The byte representation of the batch.</returns>
        protected override Byte[] GetBatchBytes(InfluxBatch batch)
        {
            var strBatch = batch.ToLineProtocol(config.Precision);
            var bytes    = Encoding.UTF8.GetBytes(strBatch);

            return(bytes);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the byte representation of the <see cref="InfluxBatch"/> in LineProtocol syntax using UTF8 encoding.
        /// </summary>
        /// <param name="batch">The batch to get the bytes for.</param>
        /// <returns>The byte representation of the batch.</returns>
        protected override Byte[] GetBatchBytes(InfluxBatch batch)
        {
            // UDP only supports ns precision
            var strBatch = batch.ToLineProtocol(InfluxPrecision.Nanoseconds);
            var bytes    = Encoding.UTF8.GetBytes(strBatch);

            return(bytes);
        }