Ejemplo n.º 1
2
        /// <summary>
        /// Creates instances of MBeanClient objects for all open JMX ports on a host within a given port range.
        /// This is accomplished by scanning the range starting from the bottom and stopping when a closed port is encountered, to maintain parity with how Tableau exposes JMX ports.
        /// </summary>
        /// <param name="hostname">The hostname of the remote host to generate clients for.</param>
        /// <param name="startPort">The start of the port range to scan.</param>
        /// <param name="endPort">The end of the port range to scan.</param>
        /// <returns>Collection of MBeanClients for open ports within the given range.</returns>
        public static ICollection<IMBeanClient> CreateClients(string hostname, int startPort, int endPort)
        {
            // Validate port range.
            if (!IsValidPortRange(startPort, endPort))
            {
                throw new ArgumentException("Invalid port range");
            }

            Log.Debug(String.Format("Scanning JMX ports {0}-{1} on {2}..", startPort, endPort, hostname));
            ICollection<IMBeanClient> validClients = new List<IMBeanClient>();

            for (var currentPort = startPort; currentPort <= endPort; currentPort++)
            {
                var connectionInfo = new JmxConnectionInfo(hostname, currentPort);
                var connector = new JmxConnectorProxy(connectionInfo);

                try
                {
                    connector.OpenConnection();
                    IMBeanClient client = new MBeanClient(connector);
                    validClients.Add(client);
                    Log.Debug(String.Format("Created JMX client for {0}", connectionInfo));
                }
                catch (Exception)
                {
                    Log.Debug(String.Format("Encountered closed JMX port ({0}), stopping scan.", currentPort));
                    break;
                }
            }

            return validClients;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates instances of MBeanClient objects for all open JMX ports on a host within a given port range.
        /// This is accomplished by scanning the range starting from the bottom and stopping when a closed port is encountered, to maintain parity with how Tableau exposes JMX ports.
        /// </summary>
        /// <param name="hostname">The hostname of the remote host to generate clients for.</param>
        /// <param name="startPort">The start of the port range to scan.</param>
        /// <param name="endPort">The end of the port range to scan.</param>
        /// <returns>Collection of MBeanClients for open ports within the given range.</returns>
        public static ICollection <IMBeanClient> CreateClients(string hostname, int startPort, int endPort)
        {
            // Validate port range.
            if (!IsValidPortRange(startPort, endPort))
            {
                throw new ArgumentException("Invalid port range");
            }

            Log.Debug(String.Format("Scanning JMX ports {0}-{1} on {2}..", startPort, endPort, hostname));
            ICollection <IMBeanClient> validClients = new List <IMBeanClient>();

            for (var currentPort = startPort; currentPort <= endPort; currentPort++)
            {
                var connectionInfo = new JmxConnectionInfo(hostname, currentPort);
                var connector      = new JmxConnectorProxy(connectionInfo);

                try
                {
                    connector.OpenConnection();
                    IMBeanClient client = new MBeanClient(connector);
                    validClients.Add(client);
                    Log.Debug(String.Format("Created JMX client for {0}", connectionInfo));
                }
                catch (Exception)
                {
                    Log.Debug(String.Format("Encountered closed JMX port ({0}), stopping scan.", currentPort));
                    break;
                }
            }

            return(validClients);
        }
Ejemplo n.º 3
0
        protected override object GetAttributeValue(string attribute)
        {
            // Find MBean object.
            var objectNames = MBeanClient.QueryObjects(JmxDomain, Path);

            // Validated MBean object was found.
            if (objectNames.Count == 0)
            {
                throw new ArgumentException("Unable to query MBean.");
            }

            object result;
            var    obj = objectNames[0];

            // The Java Health counters may be nested as CompositeData objects, so we need to be prepared to handle this.
            if (attribute.Contains(@"\"))
            {
                var pathSegments  = attribute.Split('\\');
                var parent        = pathSegments[0];
                var child         = pathSegments[1];
                var compositeData = MBeanClient.GetAttributeValue(obj, parent) as CompositeData;
                result = compositeData.get(child);
            }
            else
            {
                result = MBeanClient.GetAttributeValue(obj, attribute);
            }

            // Wonky parsing to convert result from Java lang object into C# float.
            return(float.Parse(result.ToString()));
        }
Ejemplo n.º 4
0
        protected override object GetAttributeValue(string attribute)
        {
            // Find MBean object.
            ICollection <ObjectName> objectNames = MBeanClient.QueryObjects(JmxDomain, Path);

            // Validated MBean object was found.
            if (objectNames.Count == 0)
            {
                throw new ArgumentException("Unable to query MBean.");
            }

            ObjectName obj    = objectNames.First();
            object     result = MBeanClient.GetAttributeValue(obj, attribute);

            // Wonky parsing to convert result from Java lang object into C# float.
            return(float.Parse(result.ToString()));
        }
Ejemplo n.º 5
0
        protected override object GetAttributeValue(string attribute)
        {
            // Find MBean object.
            var objectNames = MBeanClient.QueryObjects(JmxDomain, Path);

            // Validated MBean object was found.
            if (objectNames.Count < 1)
            {
                throw new ArgumentException("Unable to query MBean.");
            }

            // Grab associated attributes.
            var attributes = MBeanClient.InvokeMethod(objectNames[0], "getPerformanceMetrics") as CompositeData;

            // Look up the attribute we care about & do some wonky parsing to convert it from Java CompositeData into C# float.
            var result = attributes.get(attribute).ToString();

            return(float.Parse(result));
        }