Package com.codahale.metrics

Examples of com.codahale.metrics.Timer


    testProfileThisExecutionHelper(2, 4, true);
  }

  private void testProfileThisExecutionHelper(int callStackEveryXRequestsToGroup, long timerCount, boolean callStackExpected) throws Exception {
    when(requestMonitorPlugin.getCallStackEveryXRequestsToGroup()).thenReturn(callStackEveryXRequestsToGroup);
    final Timer timer = mock(Timer.class);
    when(timer.getCount()).thenReturn(timerCount);
    when(registry.timer("request.test.server.time.total")).thenReturn(timer);

    final RequestMonitor.RequestInformation<RequestTrace> monitor = requestMonitor.monitor(createMonitoredRequest());
    if (callStackExpected) {
      assertNotNull(monitor.getRequestTrace().getCallStack());
View Full Code Here


        rollupThread.start();

        Class.forName("com.rackspacecloud.blueflood.service.SingleRollupReadContext"); // Static initializer for the metric

        MetricRegistry registry = Metrics.getRegistry();
        Timer rollupsTimer = registry.getTimers().get(MetricRegistry.name(RollupService.class, "Rollup Execution Timer"));
//        Timer rollupsTimer = (Timer)registry.allMetrics().get(new MetricName("com.rackspacecloud.blueflood.service", "RollupService", "Rollup Execution Timer"));

        Assert.assertNotNull(rollupsTimer);

        // wait up to 120s for those rollups to finish.
        long start = System.currentTimeMillis();
        while (true) {
            try { Thread.currentThread().sleep(1000); } catch (Exception ex) { }
            if (rollupsTimer.getCount() >= locatorsForTestShard)
                break;
            Assert.assertTrue(String.format("rollups:%d", rollupsTimer.getCount()), System.currentTimeMillis() - start < 120000);
        }

        // make sure there were some that were delayed. If not, we need to increase NUM_LOCATORS.
        Assert.assertTrue(rollupsTimer.getCount() > 0);
    }
View Full Code Here

    MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
    assertNotSame(filter, MetricFilter.ALL);
    assertTrue(filter.matches("foo", new Counter()));
    assertTrue(filter.matches("boo", new Counter()));
    assertFalse(filter.matches("foo.bar", new Counter()));
    assertFalse(filter.matches("boo", new Timer()));
    assertTrue(filter.toString().length() > 0);
  }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        this.registry = new MetricRegistry() {
            @Override
            public Timer timer(final String name) {
                return new Timer(new ExponentiallyDecayingReservoir(), new Clock() {

                    private long val = 0;

                    @Override
                    public long getTick() {
View Full Code Here

    private ExtensionResponse tryExecuteGremlinScript(final RexsterResourceContext rexsterResourceContext,
                                                      final Graph graph, final Vertex vertex, final Edge edge,
                                                      final String script) {

        final MetricRegistry metricRegistry = rexsterResourceContext.getMetricRegistry();
        final Timer scriptTimer = metricRegistry.timer(MetricRegistry.name("http", "script-engine"));
        final Counter successfulExecutions = metricRegistry.counter(MetricRegistry.name("http", "script-engine", "success"));
        final Counter failedExecutions = metricRegistry.counter(MetricRegistry.name("http", "script-engine", "fail"));

        ExtensionResponse extensionResponse;

        final JSONObject requestObject = rexsterResourceContext.getRequestObject();

        // can't initialize this statically because the configure() method won't get called before it.
        // need to think a bit on how to best initialized the controller.
        final EngineController engineController = EngineController.getInstance();

        final boolean showTypes = RequestObjectHelper.getShowTypes(requestObject);
        final long offsetStart = RequestObjectHelper.getStartOffset(requestObject);
        final long offsetEnd = RequestObjectHelper.getEndOffset(requestObject);
        final boolean returnTotal = getReturnTotal(requestObject);

        final GraphSONMode mode = showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL;
        final Set<String> returnKeys = RequestObjectHelper.getReturnKeys(requestObject, WILDCARD);

        final String languageToExecuteWith = getLanguageToExecuteWith(requestObject);
        final EngineHolder engineHolder;
        final ScriptEngine scriptEngine;
        try {
            if (!engineController.isEngineAvailable(languageToExecuteWith)) {
                return ExtensionResponse.error("language requested is not available on the server");
            }

            engineHolder = engineController.getEngineByLanguageName(languageToExecuteWith);
            scriptEngine = engineHolder.getEngine();
        } catch (ScriptException se) {
            return ExtensionResponse.error("could not get request script engine");
        }

        final Bindings bindings = createBindings(graph, vertex, edge, scriptEngine);

        // add all keys not defined by this request as bindings to the script engine
        placeParametersOnBinding(requestObject, bindings, showTypes);

        // get the list of "stored procedures" to run
        final RexsterApplicationGraph rag = rexsterResourceContext.getRexsterApplicationGraph();

        final ExtensionMethod extensionMethod = rexsterResourceContext.getExtensionMethod();
        Map configurationMap = null;

        Iterator<String> scriptsToRun = null;
        try {
            final ExtensionConfiguration extensionConfiguration = rag != null ? rag.findExtensionConfiguration(EXTENSION_NAMESPACE, EXTENSION_NAME) : null;
            if (extensionConfiguration != null) {
                configurationMap = extensionConfiguration.tryGetMapFromConfiguration();
                scriptsToRun = getScriptsToRun(requestObject, configurationMap);
            }
        } catch (IOException ioe) {
            return ExtensionResponse.error(ioe,
                    generateErrorJson(extensionMethod.getExtensionApiAsJson()));
        }

        if ((script == null || script.isEmpty()) && scriptsToRun == null) {
            return ExtensionResponse.badRequest(
                    "no scripts provided",
                    generateErrorJson(extensionMethod.getExtensionApiAsJson()));
        }

        final Timer.Context context = scriptTimer.time();
        try {
            // result is either the ad-hoc script on the query string or the last "stored procedure"
            Object result = null;
            if (scriptsToRun != null) {
                while (scriptsToRun.hasNext()) {
View Full Code Here

                    // MetricRegistry registry = SharedMetricRegistries.getOrCreate(MetricsBinder.SHARED_REGISTRY_NAME);
                    MetricRegistry registry = new MetricRegistry();
                    SortedMap<String, Timer> timers = registry.getTimers();

                    Timer firstByteTimer = timers.get(RequestProcessor.FIRST_BYTE_TIMER_NAME);
                    Timer lastByteTimer = timers.get(RequestProcessor.LAST_BYTE_TIMER_NAME);

                    assertNotNull(firstByteTimer);
                    assertNotNull(lastByteTimer);
                    assertEquals(1, firstByteTimer.getCount());
                    assertEquals(1, lastByteTimer.getCount());

                    testComplete();
                })
                .exceptionHandler(t -> fail(t.getMessage()))
                .end();
View Full Code Here

        }

        if (method.getMethod().isAnnotationPresent(Timed.class)) {
            final Timed annotation = method.getMethod().getAnnotation(Timed.class);
            final String name = chooseName(annotation.name(), annotation.absolute(), method);
            final Timer timer = registry.timer(name);
            dispatcher = new TimedRequestDispatcher(dispatcher, timer);
        }

        if (method.getMethod().isAnnotationPresent(Metered.class)) {
            final Metered annotation = method.getMethod().getAnnotation(Metered.class);
View Full Code Here

            }
            batch.addMeter(name, meter);
        }
        for (Map.Entry<String, Timer> entry : timers.entrySet()) {
            String name = entry.getKey();
            Timer timer = entry.getValue();
            if (skipMetric(name, timer)) {
                continue;
            }
            batch.addTimer(name, timer);
        }
View Full Code Here

    private static ConnectionFactory[] instrument(ConnectionFactory[] factories,
                                                  MetricRegistry registry,
                                                  String name) {
        final ConnectionFactory[] instrumented = new ConnectionFactory[factories.length];
        for (int i = 0; i < factories.length; i++) {
            final Timer timer = registry.timer(name(ServerConnector.class, name, "connections"));
            instrumented[i] = new InstrumentedConnectionFactory(factories[i], timer);
        }
        return instrumented;
    }
View Full Code Here

      Histogram metric = this.registry.histogram(name);
      metric.update(longValue);
    }
    else if (name.startsWith("timer")) {
      long longValue = value.getValue().longValue();
      Timer metric = this.registry.timer(name);
      metric.update(longValue, TimeUnit.MILLISECONDS);
    }
    else {
      final double gauge = value.getValue().doubleValue();
      Object lock = null;
      if (this.gaugeLocks.containsKey(name)) {
View Full Code Here

TOP

Related Classes of com.codahale.metrics.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.