Example #1
0
        public void AlternatingTest()
        {
            var path = new GraphitePath("dummy");

            path = path.Chars('a', 'b', 'd').Values("a", "v", "b").Chars('z', 'y', 'x');
            Assert.Equal("dummy[abd]{a,v,b}[zyx]", path.ToString());
        }
Example #2
0
        public void GraphitePath()
        {
            var path = new GraphitePath("metric");

            Assert.Equal("metric", path.Name);
            Assert.Equal("metric", path.ToString());
        }
Example #3
0
        public void CombineNameTest()
        {
            var path = new GraphitePath("metric");

            Assert.Equal("metric", path.ToString());
            path = path.Dot("used");
            Assert.Equal("metric.used", path.ToString());
            path = path.Wildcard();
            Assert.Equal("metric.used*", path.ToString());
            path = path.Wildcard();
            Assert.Equal("metric.used*", path.ToString());
            path = path.DotWildcard();
            Assert.Equal("metric.used*.*", path.ToString());
            path = path.Range('a', 'z');
            Assert.Equal("metric.used*.*[a-z]", path.ToString());
            path = path.Range('0', '9');
            Assert.Equal("metric.used*.*[a-z0-9]", path.ToString());
            path = path.DotRange('0', '9');
            Assert.Equal("metric.used*.*[a-z0-9].[0-9]", path.ToString());
            path = path.Chars('a', 'd', 'f');
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adf]", path.ToString());
            path = path.Chars('q');
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adfq]", path.ToString());
            path = path.DotChars('w');
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adfq].[w]", path.ToString());
            path = path.Values("asdf");
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adfq].[w]{asdf}", path.ToString());
            path = path.Values("qwertz");
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adfq].[w]{asdf,qwertz}", path.ToString());
            path = path.DotValues("01", "02", "03");
            Assert.Equal("metric.used*.*[a-z0-9].[0-9][adfq].[w]{asdf,qwertz}.{01,02,03}", path.ToString());
        }
        public async Task CanQueryLongFormulas()
        {
            var client = new GraphiteClient(GraphiteHost)
            {
                UseSsl = false
            };
            var metrics = new SeriesListBase[768];

            for (int i = 0; i < metrics.Length; i++)
            {
                metrics[i] = new GraphitePath("prefix").Dot("path")
                             .Dot(Guid.NewGuid().ToString().Replace("-", String.Empty))
                             .Dot("category")
                             .Dot(Guid.NewGuid().ToString().Replace("-", String.Empty))
                             .Dot("value")
                             .Alias(i.ToString());
            }
            var metric = metrics.Sum();

            Assert.True(metric.ToString().Length > UInt16.MaxValue, "request too short to fail");
            try
            {
                await client.GetMetricsDataAsync(metric);
            }
            catch (UriFormatException)
            {
                throw;
            }
            catch
            {
                // ignored host may be not reachable
            }
        }
Example #5
0
        public void ApplyByNode()
        {
            var innerCalc = GraphitePath.Parse("%.disk.bytes_free")
                            .DivideSeries(GraphitePath.Parse("%.disk.bytes_*").SumSeriesWithWildcards());
            var applyByNode = GraphitePath.Parse("servers.*.disk.bytes_free").ApplyByNode(1, innerCalc);

            Assert.Equal("applyByNode(servers.*.disk.bytes_free,1,'divideSeries(%.disk.bytes_free,sumSeriesWithWildcards(%.disk.bytes_*))')", applyByNode.ToString());
        }
        public async Task CanExpandMetrics()
        {
            var client  = new GraphiteClient(GraphiteHost);
            var path1   = new GraphitePath("usage").Dot("unittest").Dot("iaas").DotWildcard().DotWildcard().DotWildcard();
            var path2   = new GraphitePath("usage").Dot("unittest").Dot("license").DotWildcard();
            var metrics = await client.ExpandMetricsAsync(path1, path2);

            Assert.NotNull(metrics);
            Assert.NotEmpty(metrics);
            Assert.True(metrics.All(x => x.StartsWith("usage.unittest.")));
            Assert.Contains(metrics, x => x.StartsWith("usage.unittest.iaas."));
            Assert.Contains(metrics, x => x.StartsWith("usage.unittest.license."));
        }
        public async Task CanGetMetricValues()
        {
            var client = new GraphiteClient(GraphiteHost);
            var metric = new GraphitePath("usage").Dot("unittest").Dot("iaas").DotWildcard().Dot("cpu").Dot("max");
            var data   = await client.GetMetricsDataAsync(metric);

            Assert.NotNull(data);
            var series = data.FirstOrDefault();

            Assert.NotNull(series);
            Assert.NotNull(series.Datapoints);
            Assert.NotEmpty(series.Datapoints);
            Assert.Contains(series.Datapoints, x => x.Value.HasValue);
            Assert.True(series.Datapoints.All(x => x.Timestamp < DateTime.Now));
        }
 protected internal PathGraphitePath(string name, GraphitePath previous) : base(name, previous)
 {
 }
 /// <summary>
 /// base class for extended graphite targets
 /// </summary>
 /// <param name="name">name of the extension</param>
 /// <param name="previous">base target</param>
 protected ModifiedGraphitePath(string name, GraphitePath previous) : base(name)
 {
     Previous = previous;
 }
 protected internal WildcardGraphitePath(GraphitePath previous) : base(String.Empty, previous)
 {
 }
Example #11
0
        public void WildcardTest()
        {
            var metric = new GraphitePath("usage").Dot("unittest").DotWildcard().Dot("count");

            Assert.Equal("usage.unittest.*.count", metric.ToString());
        }