Search in sources :

Example 76 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project indy by Commonjava.

the class ReporterIntializer method initZabbixReporterForHealthCheckMetric.

private void initZabbixReporterForHealthCheckMetric(MetricRegistry metrics, IndyMetricsConfig config) {
    IndyZabbixReporter reporter = initZabbixReporter(metrics, config).filter((name, metric) -> {
        if (!name.contains(FILTER_SIMPLE) && name.contains(FILTER_HEALTHCHECK)) {
            return true;
        }
        return false;
    }).build(initZabbixSender());
    reporter.start(config.getZabbixHealthcheckPeriod(), TimeUnit.SECONDS);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) ZabbixCacheStorage(org.commonjava.indy.metrics.zabbix.cache.ZabbixCacheStorage) IndyMetricsConfig(org.commonjava.indy.metrics.conf.IndyMetricsConfig) IndyZabbixSender(org.commonjava.indy.metrics.zabbix.sender.IndyZabbixSender) Graphite(com.codahale.metrics.graphite.Graphite) InetSocketAddress(java.net.InetSocketAddress) IndyHttpProvider(org.commonjava.indy.subsys.http.IndyHttpProvider) Inject(javax.inject.Inject) TimeUnit(java.util.concurrent.TimeUnit) IndyZabbixReporter(org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter) IndyMetricsNamed(org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyZabbixReporter(org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter)

Example 77 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project indy by Commonjava.

the class ReporterIntializer method initGraphiteReporterForSimpleMetric.

private void initGraphiteReporterForSimpleMetric(MetricRegistry metrics, IndyMetricsConfig config) {
    final Graphite graphite = new Graphite(new InetSocketAddress(config.getGrphiterHostName(), config.getGrphiterPort()));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(metrics).prefixedWith(config.getGrphiterPrefix()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter((name, metric) -> {
        if (name.contains(FILTER_SIMPLE)) {
            return true;
        }
        return false;
    }).build(graphite);
    reporter.start(config.getGrphiterSimplePriod(), TimeUnit.SECONDS);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) ZabbixCacheStorage(org.commonjava.indy.metrics.zabbix.cache.ZabbixCacheStorage) IndyMetricsConfig(org.commonjava.indy.metrics.conf.IndyMetricsConfig) IndyZabbixSender(org.commonjava.indy.metrics.zabbix.sender.IndyZabbixSender) Graphite(com.codahale.metrics.graphite.Graphite) InetSocketAddress(java.net.InetSocketAddress) IndyHttpProvider(org.commonjava.indy.subsys.http.IndyHttpProvider) Inject(javax.inject.Inject) TimeUnit(java.util.concurrent.TimeUnit) IndyZabbixReporter(org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter) IndyMetricsNamed(org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) ApplicationScoped(javax.enterprise.context.ApplicationScoped) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Graphite(com.codahale.metrics.graphite.Graphite)

Example 78 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project opennms by OpenNMS.

the class EventExpanderTest method testAfterPropertiesSetWithNoEventConfDao.

@Test
public void testAfterPropertiesSetWithNoEventConfDao() {
    m_mocks.replayAll();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("property eventConfDao must be set"));
    EventExpander expander = new EventExpander(new MetricRegistry());
    try {
        expander.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 79 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project opennms by OpenNMS.

the class StressCommand method execute.

@Override
public Object execute() throws Exception {
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
    // Create metrics to capture the results
    final MetricRegistry metrics = new MetricRegistry();
    final Histogram responseTimes = metrics.histogram("response-times");
    final Counter successes = metrics.counter("successes");
    final Counter failures = metrics.counter("failures");
    // Build and issue the requests
    System.out.printf("Executing %d requests.\n", count);
    final String message = Strings.repeat("*", messageSize);
    final CountDownLatch doneSignal = new CountDownLatch(count);
    long beforeExec = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        client.execute(buildRequest(message)).whenComplete((r, e) -> {
            if (e != null) {
                failures.inc();
            } else {
                responseTimes.update(System.currentTimeMillis() - r.getId());
                successes.inc();
            }
            doneSignal.countDown();
        });
    }
    long afterExec = System.currentTimeMillis();
    // Wait for the responses...
    System.out.printf("Waiting for responses.\n");
    while (true) {
        try {
            if (doneSignal.await(1, TimeUnit.SECONDS)) {
                // Done!
                System.out.printf("\nDone!\n");
                break;
            }
        } catch (InterruptedException e) {
            System.out.println("\nInterrupted!");
            break;
        }
        System.out.print(".");
        System.out.flush();
    }
    long afterResponse = System.currentTimeMillis();
    System.out.println();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    reporter.close();
    System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
    System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
    System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
    return null;
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 80 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project opennms by OpenNMS.

the class Nms4335IT method doMessageTest.

/**
 * Send a raw syslog message and expect a given event as a result
 *
 * @param testPDU The raw syslog message as it would appear on the wire (just the UDP payload)
 * @param expectedHost The host from which the event should be resolved as originating
 * @param expectedUEI The expected UEI of the resulting event
 * @param expectedLogMsg The expected contents of the logmsg for the resulting event
 *
 * @throws UnknownHostException
 * @throws InterruptedException
 * @throws ExecutionException
 */
private List<Event> doMessageTest(String testPDU, String expectedHost, String expectedUEI, String expectedLogMsg) throws UnknownHostException, InterruptedException, ExecutionException {
    SyslogdTestUtils.startSyslogdGracefully(m_syslogd);
    final EventBuilder expectedEventBldr = new EventBuilder(expectedUEI, "syslogd");
    expectedEventBldr.setInterface(addr(expectedHost));
    expectedEventBldr.setLogDest("logndisplay");
    expectedEventBldr.setLogMessage(expectedLogMsg);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
    final SyslogSinkConsumer syslogSinkConsumer = new SyslogSinkConsumer(new MetricRegistry());
    syslogSinkConsumer.setDistPollerDao(m_distPollerDao);
    syslogSinkConsumer.setSyslogdConfig(m_config);
    syslogSinkConsumer.setEventForwarder(m_eventIpcManager);
    final SyslogSinkModule syslogSinkModule = syslogSinkConsumer.getModule();
    final SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, addr("127.0.0.1"));
    final DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, testPDU);
    final SyslogMessageLogDTO messageLog = syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    syslogSinkConsumer.handleMessage(messageLog);
    m_eventIpcManager.getEventAnticipator().verifyAnticipated(5000, 0, 0, 0, 0);
    final Event receivedEvent = m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived().get(0);
    assertEquals("Log messages do not match", expectedLogMsg, receivedEvent.getLogmsg().getContent());
    return m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived();
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) DatagramPacket(java.net.DatagramPacket) Event(org.opennms.netmgt.xml.event.Event) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15