Example #1
0
        public void Render(TextWriter textWriter)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            textWriter.Write(LineProtocolSyntax.EscapeName(_measurement));

            if (_tags != null)
            {
                foreach (KeyValuePair <string, string> tag in _tags.OrderBy(t => t.Key))
                {
                    if (string.IsNullOrEmpty(tag.Value))
                    {
                        continue;
                    }

                    textWriter.Write(',');
                    textWriter.Write(LineProtocolSyntax.EscapeName(tag.Key));
                    textWriter.Write('=');
                    textWriter.Write(LineProtocolSyntax.EscapeName(tag.Value));
                }
            }

            char fieldDelim = ' ';

            foreach (KeyValuePair <string, object> field in _fields)
            {
                textWriter.Write(fieldDelim);
                fieldDelim = ',';
                textWriter.Write(LineProtocolSyntax.EscapeName(field.Key));
                textWriter.Write('=');
                textWriter.Write(LineProtocolSyntax.FormatValue(field.Value));
            }

            if (_utcTimestamp != null)
            {
                textWriter.Write(' ');
                textWriter.Write(LineProtocolSyntax.FormatTimestamp(_utcTimestamp.Value));
            }
        }
Example #2
0
 public void Can_format_value(object value, string expected)
 {
     LineProtocolSyntax.FormatValue(value).Should().Be(expected);
 }
Example #3
0
        public void Can_format_timespan()
        {
            var value = TimeSpan.FromMinutes(1);

            LineProtocolSyntax.FormatValue(value).Should().Be("60000");
        }
Example #4
0
        public void Can_format_timestamp()
        {
            var dateTime = new DateTime(2017, 01, 01, 1, 1, 1, DateTimeKind.Utc);

            LineProtocolSyntax.FormatTimestamp(dateTime).Should().Be("1483232461000000000");
        }
Example #5
0
 public void Can_escape_name(string nameOrKey, string expected)
 {
     LineProtocolSyntax.EscapeName(nameOrKey).Should().Be(expected);
 }