Example #1
0
 private void ConfigureSinks()
 {
     lock (this)
     {
         sinkConfigs = config.GetInstanceConfigs(SinkKey);
         int confPeriod = 0;
         foreach (KeyValuePair <string, MetricsConfig> entry in sinkConfigs)
         {
             MetricsConfig conf       = entry.Value;
             int           sinkPeriod = conf.GetInt(PeriodKey, PeriodDefault);
             confPeriod = confPeriod == 0 ? sinkPeriod : ArithmeticUtils.Gcd(confPeriod, sinkPeriod
                                                                             );
             string clsName = conf.GetClassName(string.Empty);
             if (clsName == null)
             {
                 continue;
             }
             // sink can be registered later on
             string sinkName = entry.Key;
             try
             {
                 MetricsSinkAdapter sa = NewSink(sinkName, conf.GetString(DescKey, sinkName), conf
                                                 );
                 sa.Start();
                 sinks[sinkName] = sa;
             }
             catch (Exception e)
             {
                 Log.Warn("Error creating sink '" + sinkName + "'", e);
             }
         }
         period = confPeriod > 0 ? confPeriod : config.GetInt(PeriodKey, PeriodDefault);
     }
 }
Example #2
0
        /// <exception cref="System.Exception"/>
        private void TestInstances(MetricsConfig c)
        {
            IDictionary <string, MetricsConfig> map  = c.GetInstanceConfigs("t1");
            IDictionary <string, MetricsConfig> map2 = c.GetInstanceConfigs("t2");

            Assert.Equal("number of t1 instances", 2, map.Count);
            Assert.Equal("number of t2 instances", 1, map2.Count);
            Assert.True("contains t1 instance i1", map.Contains("i1"));
            Assert.True("contains t1 instance 42", map.Contains("42"));
            Assert.True("contains t2 instance i1", map2.Contains("i1"));
            MetricsConfig t1i1  = map["i1"];
            MetricsConfig t1i42 = map["42"];
            MetricsConfig t2i1  = map2["i1"];

            Log.Debug("--- t1 instance i1:" + t1i1);
            Log.Debug("--- t1 instance 42:" + t1i42);
            Log.Debug("--- t2 instance i1:" + t2i1);
            Org.Apache.Commons.Configuration.Configuration t1expected1 = new ConfigBuilder().
                                                                         Add("name", "p1.t1.i1.name").config;
            Org.Apache.Commons.Configuration.Configuration t1expected42 = new ConfigBuilder()
                                                                          .Add("bar", "p1.t1.42.bar").config;
            Org.Apache.Commons.Configuration.Configuration t2expected1 = new ConfigBuilder().
                                                                         Add("foo", "p1.t2.i1.foo").config;
            ConfigUtil.AssertEq(t1expected1, t1i1);
            ConfigUtil.AssertEq(t1expected42, t1i42);
            ConfigUtil.AssertEq(t2expected1, t2i1);
            Log.Debug("asserting foo == default foo");
            // Check default lookups
            Assert.Equal("value of foo in t1 instance i1", "default foo",
                         t1i1.GetString("foo"));
            Assert.Equal("value of bar in t1 instance i1", "p1.t1 default bar"
                         , t1i1.GetString("bar"));
            Assert.Equal("value of foo in t1 instance 42", "default foo",
                         t1i42.GetString("foo"));
            Assert.Equal("value of foo in t2 instance i1", "p1.t2.i1.foo",
                         t2i1.GetString("foo"));
            Assert.Equal("value of bar in t2 instance i1", "p1 default bar"
                         , t2i1.GetString("bar"));
        }