Search in sources :

Example 1 with ThreadStateSampler

use of com.newrelic.agent.threads.ThreadStateSampler in project newrelic-java-agent by newrelic.

the class ThreadService method doStart.

@Override
protected void doStart() throws Exception {
    threadNameNormalizer = new ThreadNameNormalizer(ServiceFactory.getConfigService().getDefaultAgentConfig(), this);
    AgentConfig config = ServiceFactory.getConfigService().getDefaultAgentConfig();
    if (config.getValue("thread_sampler.enabled", Boolean.TRUE)) {
        long sampleDelayInSeconds = config.getValue("thread_sampler.sample_delay_in_seconds", 60);
        long samplePeriodInSeconds = config.getValue("thread_sampler.sample_period_in_seconds", 60);
        if (samplePeriodInSeconds > 0) {
            ThreadStateSampler threadStateSampler = new ThreadStateSampler(ManagementFactory.getThreadMXBean(), threadNameNormalizer);
            ServiceFactory.getSamplerService().addSampler(threadStateSampler, sampleDelayInSeconds, samplePeriodInSeconds, TimeUnit.SECONDS);
        } else {
            Agent.LOG.log(Level.FINE, "The thread sampler is disabled because the sample period is {}", samplePeriodInSeconds);
        }
    } else {
        Agent.LOG.log(Level.FINE, "The thread sampler is disabled");
    }
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadStateSampler(com.newrelic.agent.threads.ThreadStateSampler) ThreadNameNormalizer(com.newrelic.agent.threads.ThreadNameNormalizer)

Aggregations

AgentConfig (com.newrelic.agent.config.AgentConfig)1 ThreadNameNormalizer (com.newrelic.agent.threads.ThreadNameNormalizer)1 ThreadStateSampler (com.newrelic.agent.threads.ThreadStateSampler)1