Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* ApplicationInsights-Java
* Copyright (c) Microsoft Corporation
* All rights reserved.
*
* MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the ""Software""), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package com.microsoft.applicationinsights.internal.jmx;
import com.microsoft.applicationinsights.internal.logger.InternalLogger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import java.lang.management.ManagementFactory;
/**
* A utility class that knows how to fetch JMX data.
*
* Created by gupele on 3/15/2015.
*/
public class JmxDataFetcher {
private static final String COMPOSITE_ATTRIBUTE_TYPE = "COMPOSITE";
private static final String TABULAR_ATTRIBUTE_TYPE = "TABULAR";
enum AttributeType {
TABULAR,
COMPOSITE,
REGULAR
}
/**
* Gets an object name and its attributes to fetch and will return the data.
* @param objectName The object name to search.
* @param attributes The attributes that 'belong' to the object name.
* @return A map that represent each attribute: the key is the displayed name for that attribute
* and the value is a list of values found
* @throws Exception In case the object name is not found.
*/
public static Map> fetch(String objectName, Collection attributes) throws Exception {
Map> result = new HashMap>();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set objects = server.queryNames(new ObjectName(objectName), null);
if (objects.isEmpty()) {
String errorMsg = String.format("Cannot find object name '%s'", objectName);
throw new IllegalArgumentException(errorMsg);
}
for (JmxAttributeData attribute : attributes) {
try {
Collection