/// <summary>Create a new regex filter with a config object</summary> /// <param name="conf">the config object</param> /// <returns>the filter</returns> public static RegexFilter NewRegexFilter(SubsetConfiguration conf) { RegexFilter f = new RegexFilter(); f.Init(conf); return(f); }
/// <summary>Asserts that filters with the given configuration reject the given record. /// </summary> /// <param name="conf">SubsetConfiguration containing filter configuration</param> /// <param name="record">MetricsRecord to check</param> internal static void ShouldReject(SubsetConfiguration conf, MetricsRecord record) { Assert.True("rejects " + record, !NewGlobFilter(conf).Accepts(record )); Assert.True("rejects " + record, !NewRegexFilter(conf).Accepts( record)); }
/// <summary>Create a new glob filter with a config object</summary> /// <param name="conf">the config object</param> /// <returns>the filter</returns> public static GlobFilter NewGlobFilter(SubsetConfiguration conf) { GlobFilter f = new GlobFilter(); f.Init(conf); return(f); }
/* * Output of "gmetric --help" showing allowable values * -t, --type=STRING * Either string|int8|uint8|int16|uint16|int32|uint32|float|double * -u, --units=STRING Unit of measure for the value e.g. Kilobytes, Celcius * (default='') * -s, --slope=STRING Either zero|positive|negative|both * (default='both') * -x, --tmax=INT The maximum time in seconds between gmetric calls * (default='60') */ // as per libgmond.c // 0 // 1 // 2 // 3 /* * (non-Javadoc) * * @see * org.apache.hadoop.metrics2.MetricsPlugin#init(org.apache.commons.configuration * .SubsetConfiguration) */ public virtual void Init(SubsetConfiguration conf) { Log.Debug("Initializing the GangliaSink for Ganglia metrics."); this.conf = conf; // Take the hostname from the DNS class. if (conf.GetString("slave.host.name") != null) { hostName = conf.GetString("slave.host.name"); } else { try { hostName = DNS.GetDefaultHost(conf.GetString("dfs.datanode.dns.interface", "default" ), conf.GetString("dfs.datanode.dns.nameserver", "default")); } catch (UnknownHostException uhe) { Log.Error(uhe); hostName = "UNKNOWN.example.com"; } } // load the gannglia servers from properties metricsServers = Servers.Parse(conf.GetString(ServersProperty), DefaultPort); multicastEnabled = conf.GetBoolean(MulticastEnabledProperty, DefaultMulticastEnabled ); multicastTtl = conf.GetInt(MulticastTtlProperty, DefaultMulticastTtl); // extract the Ganglia conf per metrics gangliaConfMap = new Dictionary <string, GangliaConf>(); LoadGangliaConf(AbstractGangliaSink.GangliaConfType.units); LoadGangliaConf(AbstractGangliaSink.GangliaConfType.tmax); LoadGangliaConf(AbstractGangliaSink.GangliaConfType.dmax); LoadGangliaConf(AbstractGangliaSink.GangliaConfType.slope); try { if (multicastEnabled) { Log.Info("Enabling multicast for Ganglia with TTL " + multicastTtl); datagramSocket = new MulticastSocket(); ((MulticastSocket)datagramSocket).SetTimeToLive(multicastTtl); } else { datagramSocket = new DatagramSocket(); } } catch (IOException e) { Log.Error(e); } // see if sparseMetrics is supported. Default is false supportSparseMetrics = conf.GetBoolean(SupportSparseMetricsProperty, SupportSparseMetricsDefault ); }
public virtual void Init(SubsetConfiguration conf) { string filename = conf.GetString(FilenameKey); try { writer = filename == null ? System.Console.Out : new TextWriter(new FileOutputStream (new FilePath(filename)), true, "UTF-8"); } catch (Exception e) { throw new MetricsException("Error creating " + filename, e); } }
public virtual void Init(SubsetConfiguration conf) { // Get Graphite host configurations. string serverHost = conf.GetString(ServerHostKey); int serverPort = System.Convert.ToInt32(conf.GetString(ServerPortKey)); // Get Graphite metrics graph prefix. metricsPrefix = conf.GetString(MetricsPrefix); if (metricsPrefix == null) { metricsPrefix = string.Empty; } graphite = new GraphiteSink.Graphite(serverHost, serverPort); graphite.Connect(); }
private static void ShouldAcceptImpl(bool expectAcceptList, SubsetConfiguration conf , IList <MetricsTag> tags, bool[] expectedAcceptedSpec) { MetricsFilter globFilter = NewGlobFilter(conf); MetricsFilter regexFilter = NewRegexFilter(conf); // Test acceptance of the tag list: Assert.Equal("accepts " + tags, expectAcceptList, globFilter.Accepts (tags)); Assert.Equal("accepts " + tags, expectAcceptList, regexFilter. Accepts(tags)); // Test results on each of the individual tags: int acceptedCount = 0; for (int i = 0; i < tags.Count; i++) { MetricsTag tag = tags[i]; bool actGlob = globFilter.Accepts(tag); bool actRegex = regexFilter.Accepts(tag); Assert.Equal("accepts " + tag, expectedAcceptedSpec[i], actGlob ); // Both the filters should give the same result: Assert.Equal(actGlob, actRegex); if (actGlob) { acceptedCount++; } } if (expectAcceptList) { // At least one individual tag should be accepted: Assert.True("No tag of the following accepted: " + tags, acceptedCount > 0); } else { // At least one individual tag should be rejected: Assert.True("No tag of the following rejected: " + tags, acceptedCount < tags.Count); } }
public override void Init(SubsetConfiguration conf) { string patternString = conf.GetString(IncludeKey); if (patternString != null && !patternString.IsEmpty()) { SetIncludePattern(Compile(patternString)); } patternString = conf.GetString(ExcludeKey); if (patternString != null && !patternString.IsEmpty()) { SetExcludePattern(Compile(patternString)); } string[] patternStrings = conf.GetStringArray(IncludeTagsKey); if (patternStrings != null && patternStrings.Length != 0) { foreach (string pstr in patternStrings) { Matcher matcher = tagPattern.Matcher(pstr); if (!matcher.Matches()) { throw new MetricsException("Illegal tag pattern: " + pstr); } SetIncludeTagPattern(matcher.Group(1), Compile(matcher.Group(2))); } } patternStrings = conf.GetStringArray(ExcludeTagsKey); if (patternStrings != null && patternStrings.Length != 0) { foreach (string pstr in patternStrings) { Matcher matcher = tagPattern.Matcher(pstr); if (!matcher.Matches()) { throw new MetricsException("Illegal tag pattern: " + pstr); } SetExcludeTagPattern(matcher.Group(1), Compile(matcher.Group(2))); } } }
// a key with a NULL value means ALL public override void Init(SubsetConfiguration conf) { base.Init(conf); conf.SetListDelimiter(','); IEnumerator <string> it = (IEnumerator <string>)conf.GetKeys(); while (it.HasNext()) { string propertyName = it.Next(); if (propertyName.StartsWith(TagsForPrefixPropertyPrefix)) { string contextName = Runtime.Substring(propertyName, TagsForPrefixPropertyPrefix .Length); string[] tags = conf.GetStringArray(propertyName); bool useAllTags = false; ICollection <string> set = null; if (tags.Length > 0) { set = new HashSet <string>(); foreach (string tag in tags) { tag = tag.Trim(); useAllTags |= tag.Equals("*"); if (tag.Length > 0) { set.AddItem(tag); } } if (useAllTags) { set = null; } } useTagsMap[contextName] = set; } } }
internal static void ShouldReject(SubsetConfiguration conf, string s) { Assert.True("rejects " + s, !NewGlobFilter(conf).Accepts(s)); Assert.True("rejects " + s, !NewRegexFilter(conf).Accepts(s)); }
// Version for multiple tags: internal static void ShouldReject(SubsetConfiguration conf, IList <MetricsTag> tags , bool[] expectedAcceptedSpec) { ShouldAcceptImpl(false, conf, tags, expectedAcceptedSpec); }
// Version for one tag: internal static void ShouldReject(SubsetConfiguration conf, IList <MetricsTag> tags ) { ShouldAcceptImpl(false, conf, tags, new bool[] { false }); }
public abstract void Init(SubsetConfiguration arg1);
public virtual void Init(SubsetConfiguration conf) { }
public virtual void Init(SubsetConfiguration conf) { Log.Debug(MetricsConfig.ToString(conf)); }