示例#1
0
        public async void Retention_policy_is_used_to_select_retention_policy()
        {
            const string expectedRetentionPolicy = "expectedRetentionPolicy";
            var          options = new InfluxDbObserverOptions("databaseName")
            {
                RetentionPolicySelector = (metric, database) => expectedRetentionPolicy,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag>(), new[] { new Measurement <int>("value", 0) }) });

            await influxDbClient.DidNotReceive().WriteAsync("autogen", Arg.Any <string>(), Arg.Any <IEnumerable <Point> >());

            await influxDbClient.Received(1).WriteAsync(expectedRetentionPolicy, Arg.Any <string>(),
                                                        Arg.Is <IEnumerable <Point> >(x => x.All(y => y.Measurement == "name")));
        }
示例#2
0
        public async void Database_selector_is_used_to_select_database()
        {
            const string expectedDatabase  = "expectedDatabase";
            const string incorrectDatabase = "databaseName";
            var          options           = new InfluxDbObserverOptions(incorrectDatabase)
            {
                DatabaseSelector = _ => expectedDatabase
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag>(), new[] { new Measurement <int>("value", 0) }) });

            await influxDbClient.DidNotReceive().WriteAsync(Arg.Any <string>(), incorrectDatabase, Arg.Any <IEnumerable <Point> >());

            await influxDbClient.Received(1).WriteAsync(Arg.Any <string>(), expectedDatabase, Arg.Is <IEnumerable <Point> >(x => x.All(y => y.Measurement == "name")));
        }
示例#3
0
        public async void Fields_converted_to_double_are_handled_as_float()
        {
            const float expectedValue = 1.0f;
            var         options       = new InfluxDbObserverOptions("databaseName")
            {
                ConvertFieldType = x => Convert.ToDouble(x)
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag>(), new[] { new Measurement <float>("value", expectedValue) }) });

            await influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == "value" && (float)field.Value == expectedValue))));
        }
示例#4
0
        public void Submetrics_are_converted_to_fields_with_the_name_of_the_statistic()
        {
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                new InfluxDbObserverOptions("database"));
            var submetrics = new[]
            {
                new Metric("name", DateTimeOffset.Now, new[] { new Tag("statistic", "max") }, 200, new Metric[0])
            };

            observer.Update(new[]
                            { new Metric("name", DateTimeOffset.UtcNow, Enumerable.Empty <Tag>().ToArray(), 100, submetrics) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.Count() == 1 &&
                                                      points.Any(p => p.Fields.Any(f => f.Key == "max" && (int)f.Value == 200) &&
                                                                 p.Fields.Any(f => f.Key == "value" && (int)f.Value == 100))));
        }
示例#5
0
        public void Tags_can_be_converted_to_string()
        {
            const string tagName  = "tag";
            const string tagValue = "a random string";
            var          options  = new InfluxDbObserverOptions("databaseName")
            {
                TagToFieldSelector = tag => tag.Key == tagName,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new[] { new Tag(tagName, tagValue), }, 0, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == tagName && (string)field.Value == tagValue))));
        }
示例#6
0
        public void Tags_can_be_ignored_as_defined_by_options()
        {
            const string tagName = "tag";
            var          options = new InfluxDbObserverOptions("databaseName")
            {
                TagsToIgnore = new List <string> {
                    tagName
                }
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new[] { new Tag(tagName, "100"), }, 0, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(point => point.Tags.All(tag => tag.Key != tagName))));
        }
示例#7
0
        public async void Tags_can_be_converted_to_boolean()
        {
            const string tagName  = "tag";
            const string tagValue = "true";
            var          options  = new InfluxDbObserverOptions("databaseName")
            {
                TagToFieldSelector = tag => tag.Key == tagName,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag> {
                    new Tag(tagName, tagValue),
                }, new[] { new Measurement <int>("value", 0) }) });

            await influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == tagName && (bool)field.Value == Convert.ToBoolean(tagValue)))));
        }