public virtual void TestGangliaMetrics2() { ConfigBuilder cb = new ConfigBuilder().Add("default.period", 10).Add("test.sink.gsink30.context" , "test").Add("test.sink.gsink31.context", "test").Save(TestMetricsConfig.GetTestFilename ("hadoop-metrics2-test")); // filter out only "test" // filter out only "test" MetricsSystemImpl ms = new MetricsSystemImpl("Test"); ms.Start(); TestGangliaMetrics.TestSource s1 = ms.Register("s1", "s1 desc", new TestGangliaMetrics.TestSource ("s1rec")); s1.c1.Incr(); s1.xxx.Incr(); s1.g1.Set(2); s1.yyy.Incr(2); s1.s1.Add(0); int expectedCountFromGanglia30 = expectedMetrics.Length; int expectedCountFromGanglia31 = 2 * expectedMetrics.Length; // Setup test for GangliaSink30 AbstractGangliaSink gsink30 = new GangliaSink30(); gsink30.Init(cb.Subset("test")); TestGangliaMetrics.MockDatagramSocket mockds30 = new TestGangliaMetrics.MockDatagramSocket (this); GangliaMetricsTestHelper.SetDatagramSocket(gsink30, mockds30); // Setup test for GangliaSink31 AbstractGangliaSink gsink31 = new GangliaSink31(); gsink31.Init(cb.Subset("test")); TestGangliaMetrics.MockDatagramSocket mockds31 = new TestGangliaMetrics.MockDatagramSocket (this); GangliaMetricsTestHelper.SetDatagramSocket(gsink31, mockds31); // register the sinks ms.Register("gsink30", "gsink30 desc", gsink30); ms.Register("gsink31", "gsink31 desc", gsink31); ms.PublishMetricsNow(); // publish the metrics ms.Stop(); // check GanfliaSink30 data CheckMetrics(mockds30.GetCapturedSend(), expectedCountFromGanglia30); // check GanfliaSink31 data CheckMetrics(mockds31.GetCapturedSend(), expectedCountFromGanglia31); }
public virtual void TestTagsForPrefix() { ConfigBuilder cb = new ConfigBuilder().Add("test.sink.ganglia.tagsForPrefix.all", "*").Add("test.sink.ganglia.tagsForPrefix.some", "NumActiveSinks, " + "NumActiveSources" ).Add("test.sink.ganglia.tagsForPrefix.none", string.Empty); GangliaSink30 sink = new GangliaSink30(); sink.Init(cb.Subset("test.sink.ganglia")); IList <MetricsTag> tags = new AList <MetricsTag>(); tags.AddItem(new MetricsTag(MsInfo.Context, "all")); tags.AddItem(new MetricsTag(MsInfo.NumActiveSources, "foo")); tags.AddItem(new MetricsTag(MsInfo.NumActiveSinks, "bar")); tags.AddItem(new MetricsTag(MsInfo.NumAllSinks, "haa")); tags.AddItem(new MetricsTag(MsInfo.Hostname, "host")); ICollection <AbstractMetric> metrics = new HashSet <AbstractMetric>(); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long)1, tags, metrics ); StringBuilder sb = new StringBuilder(); sink.AppendPrefix(record, sb); Assert.Equal(".NumActiveSources=foo.NumActiveSinks=bar.NumAllSinks=haa" , sb.ToString()); tags.Set(0, new MetricsTag(MsInfo.Context, "some")); sb = new StringBuilder(); sink.AppendPrefix(record, sb); Assert.Equal(".NumActiveSources=foo.NumActiveSinks=bar", sb.ToString ()); tags.Set(0, new MetricsTag(MsInfo.Context, "none")); sb = new StringBuilder(); sink.AppendPrefix(record, sb); Assert.Equal(string.Empty, sb.ToString()); tags.Set(0, new MetricsTag(MsInfo.Context, "nada")); sb = new StringBuilder(); sink.AppendPrefix(record, sb); Assert.Equal(string.Empty, sb.ToString()); }