示例#1
0
 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)
     {
     }
 }
示例#2
0
        // --------------------------------------------------------- Private Methods
        /// <exception cref="System.IO.IOException"/>
        private void ListBeans(JsonGenerator jg, ObjectName qry, string attribute, HttpServletResponse
                               response)
        {
            Log.Debug("Listing beans for " + qry);
            ICollection <ObjectName> names = null;

            names = mBeanServer.QueryNames(qry, null);
            jg.WriteArrayFieldStart("beans");
            IEnumerator <ObjectName> it = names.GetEnumerator();

            while (it.HasNext())
            {
                ObjectName oname = it.Next();
                MBeanInfo  minfo;
                string     code          = string.Empty;
                object     attributeinfo = null;
                try
                {
                    minfo = mBeanServer.GetMBeanInfo(oname);
                    code  = minfo.GetClassName();
                    string prs = string.Empty;
                    try
                    {
                        if ("org.apache.commons.modeler.BaseModelMBean".Equals(code))
                        {
                            prs  = "modelerType";
                            code = (string)mBeanServer.GetAttribute(oname, prs);
                        }
                        if (attribute != null)
                        {
                            prs           = attribute;
                            attributeinfo = mBeanServer.GetAttribute(oname, prs);
                        }
                    }
                    catch (AttributeNotFoundException e)
                    {
                        // If the modelerType attribute was not found, the class name is used
                        // instead.
                        Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e);
                    }
                    catch (MBeanException e)
                    {
                        // The code inside the attribute getter threw an exception so log it,
                        // and fall back on the class name
                        Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e);
                    }
                    catch (RuntimeException e)
                    {
                        // For some reason even with an MBeanException available to them
                        // Runtime exceptionscan still find their way through, so treat them
                        // the same as MBeanException
                        Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e);
                    }
                    catch (ReflectionException e)
                    {
                        // This happens when the code inside the JMX bean (setter?? from the
                        // java docs) threw an exception, so log it and fall back on the
                        // class name
                        Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e);
                    }
                }
                catch (InstanceNotFoundException)
                {
                    //Ignored for some reason the bean was not found so don't output it
                    continue;
                }
                catch (IntrospectionException e)
                {
                    // This is an internal error, something odd happened with reflection so
                    // log it and don't output the bean.
                    Log.Error("Problem while trying to process JMX query: " + qry + " with MBean " +
                              oname, e);
                    continue;
                }
                catch (ReflectionException e)
                {
                    // This happens when the code inside the JMX bean threw an exception, so
                    // log it and don't output the bean.
                    Log.Error("Problem while trying to process JMX query: " + qry + " with MBean " +
                              oname, e);
                    continue;
                }
                jg.WriteStartObject();
                jg.WriteStringField("name", oname.ToString());
                jg.WriteStringField("modelerType", code);
                if ((attribute != null) && (attributeinfo == null))
                {
                    jg.WriteStringField("result", "ERROR");
                    jg.WriteStringField("message", "No attribute with name " + attribute + " was found."
                                        );
                    jg.WriteEndObject();
                    jg.WriteEndArray();
                    jg.Close();
                    response.SetStatus(HttpServletResponse.ScNotFound);
                    return;
                }
                if (attribute != null)
                {
                    WriteAttribute(jg, attribute, attributeinfo);
                }
                else
                {
                    MBeanAttributeInfo[] attrs = minfo.GetAttributes();
                    for (int i = 0; i < attrs.Length; i++)
                    {
                        WriteAttribute(jg, oname, attrs[i]);
                    }
                }
                jg.WriteEndObject();
            }
            jg.WriteEndArray();
        }