public virtual void TestPurgeOldMetrics() { // create test source with a single metric counter of value 1 TestMetricsSourceAdapter.PurgableSource source = new TestMetricsSourceAdapter.PurgableSource (this); MetricsSourceBuilder sb = MetricsAnnotations.NewSourceBuilder(source); MetricsSource s = sb.Build(); IList <MetricsTag> injectedTags = new AList <MetricsTag>(); MetricsSourceAdapter sa = new MetricsSourceAdapter("tst", "tst", "testdesc", s, injectedTags , null, null, 1, false); MBeanInfo info = sa.GetMBeanInfo(); bool sawIt = false; foreach (MBeanAttributeInfo mBeanAttributeInfo in info.GetAttributes()) { sawIt |= mBeanAttributeInfo.GetName().Equals(source.lastKeyName); } Assert.True("The last generated metric is not exported to jmx", sawIt); Thread.Sleep(1000); // skip JMX cache TTL info = sa.GetMBeanInfo(); sawIt = false; foreach (MBeanAttributeInfo mBeanAttributeInfo_1 in info.GetAttributes()) { sawIt |= mBeanAttributeInfo_1.GetName().Equals(source.lastKeyName); } Assert.True("The last generated metric is not exported to jmx", sawIt); }
public override void Run() { try { MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); // Metrics that belong to "FSNamesystem", these are metrics that // come from hadoop metrics framework for the class FSNamesystem. ObjectName mxbeanNamefsn = new ObjectName("Hadoop:service=NameNode,name=FSNamesystem" ); // Metrics that belong to "FSNamesystemState". // These are metrics that FSNamesystem registers directly with MBeanServer. ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); // Metrics that belong to "NameNodeInfo". // These are metrics that FSNamesystem registers directly with MBeanServer. ObjectName mxbeanNameNni = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); ICollection <ObjectName> mbeans = new HashSet <ObjectName>(); mbeans.AddItem(mxbeanNamefsn); mbeans.AddItem(mxbeanNameFsns); mbeans.AddItem(mxbeanNameNni); foreach (ObjectName mbean in mbeans) { MBeanInfo attributes = mbs.GetMBeanInfo(mbean); foreach (MBeanAttributeInfo attributeInfo in attributes.GetAttributes()) { mbs.GetAttribute(mbean, attributeInfo.GetName()); } } succeeded = true; } catch (Exception) { } }
/// <summary>print all attributes' values</summary> /// <exception cref="System.Exception"/> public virtual void PrintAllValues() { Err("List of all the available keys:"); object val = null; foreach (ObjectName oname in hadoopObjectNames) { Err(">>>>>>>>jmx name: " + oname.GetCanonicalKeyPropertyListString()); MBeanInfo mbinfo = mbsc.GetMBeanInfo(oname); MBeanAttributeInfo[] mbinfos = mbinfo.GetAttributes(); foreach (MBeanAttributeInfo mb in mbinfos) { val = mbsc.GetAttribute(oname, mb.GetName()); System.Console.Out.Format(format, mb.GetName(), (val == null) ? string.Empty : val .ToString()); } } }
/// <exception cref="System.Exception"/> public virtual void PrintAllMatchedAttributes(string attrRegExp) { Err("List of the keys matching " + attrRegExp + " :"); object val = null; Sharpen.Pattern p = Sharpen.Pattern.Compile(attrRegExp); foreach (ObjectName oname in hadoopObjectNames) { Err(">>>>>>>>jmx name: " + oname.GetCanonicalKeyPropertyListString()); MBeanInfo mbinfo = mbsc.GetMBeanInfo(oname); MBeanAttributeInfo[] mbinfos = mbinfo.GetAttributes(); foreach (MBeanAttributeInfo mb in mbinfos) { if (p.Matcher(mb.GetName()).LookingAt()) { val = mbsc.GetAttribute(oname, mb.GetName()); System.Console.Out.Format(format, mb.GetName(), (val == null) ? string.Empty : val .ToString()); } } } }