Search in sources :

Example 1 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class BaseOutputWriterTests method booleanValuesAreNotTransformedToNumber.

@Test
public void booleanValuesAreNotTransformedToNumber() throws Exception {
    final ArrayList<Result> processedResults = Lists.newArrayList();
    BaseOutputWriter outputWriter = new BaseOutputWriter(ImmutableList.<String>of(), false, false, Maps.<String, Object>newHashMap()) {

        @Override
        protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
            processedResults.addAll(results);
        }

        @Override
        public void validateSetup(Server server, Query query) throws ValidationException {
        }
    };
    Result result = new Result(0, "", "", "", "", "", ImmutableMap.<String, Object>of("true", true, "false", false));
    outputWriter.doWrite(null, null, ImmutableList.of(result));
    assertThat(processedResults).hasSize(1);
    Result processedResult = processedResults.get(0);
    assertThat(processedResult.getValues().get("true")).isEqualTo(true);
    assertThat(processedResult.getValues().get("false")).isEqualTo(false);
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ImmutableList(com.google.common.collect.ImmutableList) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 2 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class JsonUtilsTest method loadFromFile.

private void loadFromFile(String file) throws URISyntaxException, IOException, MalformedObjectNameException {
    File input = new File(JsonUtilsTest.class.getResource("/" + file).toURI());
    JmxProcess process = jsonUtils.parseProcess(input);
    assertThat(process.getName()).isEqualTo(file);
    Server server = process.getServers().get(0);
    assertThat(server.getPort()).isEqualTo("1099");
    assertThat(server.getNumQueryThreads()).isEqualTo(2);
    Optional<Query> queryOptional = from(server.getQueries()).firstMatch(new ByObj("java.lang:type=Memory"));
    assertThat(queryOptional.isPresent()).isTrue();
    assertThat(queryOptional.get().getAttr().get(0)).isEqualTo("HeapMemoryUsage");
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess) File(java.io.File)

Example 3 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class JmxTransformer method scheduleJob.

private void scheduleJob(Server server) throws ParseException, SchedulerException {
    String name = server.getHost() + ":" + server.getPort() + "-" + System.currentTimeMillis() + "-" + RandomStringUtils.randomNumeric(10);
    JobDetail jd = new JobDetail(name, "ServerJob", ServerJob.class);
    JobDataMap map = new JobDataMap();
    map.put(Server.class.getName(), server);
    jd.setJobDataMap(map);
    Trigger trigger;
    if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
        trigger = new CronTrigger();
        ((CronTrigger) trigger).setCronExpression(server.getCronExpression());
        trigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        trigger.setStartTime(computeSpreadStartDate(configuration.getRunPeriod()));
    } else {
        int runPeriod = configuration.getRunPeriod();
        if (server.getRunPeriodSeconds() != null)
            runPeriod = server.getRunPeriodSeconds();
        Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(runPeriod);
        minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        minuteTrigger.setStartTime(computeSpreadStartDate(runPeriod));
        trigger = minuteTrigger;
    // TODO replace Quartz with a ScheduledExecutorService
    }
    serverScheduler.scheduleJob(jd, trigger);
    if (log.isDebugEnabled()) {
        log.debug("Scheduled job: " + jd.getName() + " for server: " + server);
    }
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server)

Example 4 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ConfigurationParser method mergeServerLists.

/**
 * Merges two lists of servers (and their queries). Based on the equality of
 * both sets of objects. Public for testing purposes.
 * @param secondList
 * @param firstList
 */
// FIXME: the params for this method should be Set<Server> as there are multiple assumptions that they are unique
@CheckReturnValue
@VisibleForTesting
ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) {
    ImmutableList.Builder<Server> results = ImmutableList.builder();
    List<Server> toProcess = new ArrayList<>(secondList);
    for (Server firstServer : firstList) {
        if (toProcess.contains(firstServer)) {
            Server found = toProcess.get(secondList.indexOf(firstServer));
            results.add(merge(firstServer, found));
            // remove server as it is already merged
            toProcess.remove(found);
        } else {
            results.add(firstServer);
        }
    }
    // add servers from the second list that are not in the first one
    results.addAll(toProcess);
    return results.build();
}
Also used : Server(com.googlecode.jmxtrans.model.Server) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) CheckReturnValue(javax.annotation.CheckReturnValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ServerSchedulerTest method testScheduleWhenRunFails.

@Test
public void testScheduleWhenRunFails() throws InterruptedException {
    // Given
    Server server = Server.builder().setRunPeriodSeconds(2).setPid("2").setPool(mock(KeyedObjectPool.class)).addQueries(sampleQueries()).build();
    ThreadPoolExecutor executor = queryExecutorRepository.initExecutor(server);
    when(executor.submit(any(Runnable.class))).thenThrow(new IllegalStateException("Command failed"));
    // When
    serverScheduler.schedule(server);
    // Then
    verify(executor, timeout(6000L).atLeast(2)).submit(any(Runnable.class));
}
Also used : KeyedObjectPool(org.apache.commons.pool.KeyedObjectPool) Server(com.googlecode.jmxtrans.model.Server) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ManagedThreadPoolExecutor(com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor) Test(org.junit.Test)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)38 Test (org.junit.Test)26 Query (com.googlecode.jmxtrans.model.Query)21 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)13 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)9 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)6 Result (com.googlecode.jmxtrans.model.Result)6 IntegrationTest (com.googlecode.jmxtrans.test.IntegrationTest)6 File (java.io.File)6 ArrayList (java.util.ArrayList)5 MBeanServer (javax.management.MBeanServer)5 Field (java.lang.reflect.Field)4 BlazePool (stormpot.BlazePool)4 LifecycledPool (stormpot.LifecycledPool)4 ImmutableList (com.google.common.collect.ImmutableList)3 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 ManagedThreadPoolExecutor (com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor)3 IOException (java.io.IOException)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3