Search in sources :

Example 1 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxGet method toString.

/**
 * String representation of this JmxGet.
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("object_name: ").append(getObjectNameString());
    sb.append(" attributes: [");
    Iterator<JmxMetric> it = metrics.iterator();
    while (it.hasNext()) {
        JmxMetric metric = it.next();
        sb.append(metric.getAttributeMetricName()).append(" type: ").append(metric.getType().getYmlName());
        if (it.hasNext()) {
            sb.append(", ");
        }
    }
    sb.append("]");
    return sb.toString();
}
Also used : JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric)

Example 2 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMultiMBeanGet method recordStats.

@Override
public void recordStats(StatsEngine statsEngine, Map<ObjectName, Map<String, Float>> resultingMetricToValue, MBeanServer server) {
    String actualRootMetricName;
    Map<ObjectName, String> rootMetricNames = new HashMap<>();
    for (JmxMetric currentMetric : getJmxMetrics()) {
        Map<String, Float> mbeansWithValues = new HashMap<>();
        for (Entry<ObjectName, Map<String, Float>> currentMBean : resultingMetricToValue.entrySet()) {
            actualRootMetricName = rootMetricNames.get(currentMBean.getKey());
            if (actualRootMetricName == null) {
                actualRootMetricName = getRootMetricName(currentMBean.getKey(), server);
            }
            currentMetric.applySingleMBean(actualRootMetricName, currentMBean.getValue(), mbeansWithValues);
        }
        currentMetric.recordMultMBeanStats(statsEngine, mbeansWithValues);
    }
}
Also used : HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) Map(java.util.Map) HashMap(java.util.HashMap) ObjectName(javax.management.ObjectName)

Example 3 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class TomcatJmxValues method createMetrics.

private void createMetrics(String name) {
    /*
         * Only used by 7.0. The manager bean provides information about sessions. sessionCounter is the total number of
         * sessions created by this manager. ActiveSessions is the number of active sessions at this moment.
         * expiredSesions is the number of sessions that have expired. RejectedSessions is the number of sessions
         * rejected due to maxActive being reached. SessionAverageAliveTime is the average time an expired session had
         * been alive.
         */
    metrics.add(new BaseJmxValue(name + ":type=Manager,context=*,host=*,*", MetricNames.JMX_SESSION + "{context}/", new JmxMetric[] { ACTIVE_SESSIONS, EXPIRED_SESSIONS, REJECTED_SESSIONS, SESSION_ALIVE_TIME }));
    /* This is for 6.0 and 5.5. */
    metrics.add(new BaseJmxValue(name + ":type=Manager,path=*,host=*", MetricNames.JMX_SESSION + "{path}/", new JmxMetric[] { ACTIVE_SESSIONS, EXPIRED_SESSIONS, REJECTED_SESSIONS, SESSION_ALIVE_TIME }));
    /*
         * Provides information about the thread pool. The current thread count and the current number of threads which
         * are busy.
         */
    metrics.add(new BaseJmxValue(name + ":type=ThreadPool,name=*", MetricNames.JMX_THREAD_POOL + "{name}/", new JmxMetric[] { CURRENT_ACTIVE_COUNT, CURRENT_IDLE_COUNT, CURRENT_MAX_COUNT }));
    /*
         * Provides information about the data source by finding the number of active and idle connections and the max connections. 
         * In Tomcat 7, the number of max connections is represented by the maxActive attribute. In tomcat 8
         * this was changed to maxTotal, hence the two CONNECTIONS_MAX metrics.
         */
    metrics.add(new BaseJmxValue(name + ":type=DataSource,context=*,host=*," + "class=javax.sql.DataSource,name=*", MetricNames.JMX_DATASOURCES + "{name}/", new JmxMetric[] { CONNECTIONS_ACTIVE, CONNECTIONS_IDLE, CONNECTIONS_MAX, CONNECTIONS_MAX_TOMCAT_8 }));
    /*
         * Provides information about the data source when the customer is using JNDI GlobalNamingResources, which do 
         * not have a context or a host.
         */
    metrics.add(new BaseJmxValue(name + ":type=DataSource," + "class=javax.sql.DataSource,name=*", MetricNames.JMX_DATASOURCES + "{name}/", new JmxMetric[] { CONNECTIONS_ACTIVE, CONNECTIONS_IDLE, CONNECTIONS_MAX, CONNECTIONS_MAX_TOMCAT_8 }));
}
Also used : BaseJmxValue(com.newrelic.agent.jmx.metrics.BaseJmxValue) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric)

Example 4 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsChangeNameMono.

@Test
public void jmxMetricRecordStatsChangeNameMono() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create("hello", "theHello", JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("hello", 5f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(5f, stats.getStats("Jmx/Sample/theHello").getTotal(), 0);
    values.clear();
    values.put("hello", 7f);
    metric.recordSingleMBeanStats(stats, "Jmx/Sample/", values);
    Assert.assertEquals(2, stats.getStats("Jmx/Sample/theHello").getCallCount());
    Assert.assertEquals(7f, stats.getStats("Jmx/Sample/theHello").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 5 with JmxMetric

use of com.newrelic.agent.jmx.metrics.JmxMetric in project newrelic-java-agent by newrelic.

the class JmxMetricTest method jmxMetricRecordStatsSubTypeMonoMultiAdd.

@Test
public void jmxMetricRecordStatsSubTypeMonoMultiAdd() {
    StatsEngine stats = new StatsEngineImpl();
    JmxMetric metric = JmxMetric.create(new String[] { "first", "second" }, "theDiffe", JmxAction.SUBTRACT_ALL_FROM_FIRST, JmxType.MONOTONICALLY_INCREASING);
    Map<String, Float> values = new HashMap<>();
    values.put("first", 10f);
    values.put("second", 7f);
    Map<String, Float> actual = new HashMap<>();
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    Assert.assertEquals(0, stats.getStats("Jmx/Sample/theDiffe").getCallCount());
    values.clear();
    values.put("first", 12f);
    values.put("second", 5f);
    metric.applySingleMBean("Jmx/Sample/", values, actual);
    metric.recordMultMBeanStats(stats, actual);
    Assert.assertEquals(1, stats.getStats("Jmx/Sample/theDiffe").getCallCount());
    Assert.assertEquals(10f, stats.getStats("Jmx/Sample/theDiffe").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) HashMap(java.util.HashMap) JmxMetric(com.newrelic.agent.jmx.metrics.JmxMetric) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)32 Test (org.junit.Test)29 HashMap (java.util.HashMap)21 StatsEngine (com.newrelic.agent.stats.StatsEngine)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)20 ObjectName (javax.management.ObjectName)12 ArrayList (java.util.ArrayList)11 MBeanServer (javax.management.MBeanServer)5 Map (java.util.Map)3 BaseJmxValue (com.newrelic.agent.jmx.metrics.BaseJmxValue)1