Java Code Examples for com.yammer.metrics.Metrics#newTimer()

The following examples show how to use com.yammer.metrics.Metrics#newTimer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitLogMetrics.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public CommitLogMetrics(final AbstractCommitLogService service, final CommitLogSegmentManager allocator)
{
    completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
    {
        public Long value()
        {
            return service.getCompletedTasks();
        }
    });
    pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>()
    {
        public Long value()
        {
            return service.getPendingTasks();
        }
    });
    totalCommitLogSize = Metrics.newGauge(factory.createMetricName("TotalCommitLogSize"), new Gauge<Long>()
    {
        public Long value()
        {
            return allocator.bytesUsed();
        }
    });
    waitingOnSegmentAllocation = Metrics.newTimer(factory.createMetricName("WaitingOnSegmentAllocation"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
    waitingOnCommit = Metrics.newTimer(factory.createMetricName("WaitingOnCommit"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
}
 
Example 2
Source File: Indexer.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
Indexer(String indexerName, IndexerConf conf, String tableName, ResultToSolrMapper mapper, Sharder sharder,
        SolrInputDocumentWriter solrWriter) {
    this.indexerName = indexerName;
    this.conf = conf;
    this.tableName = tableName;
    this.mapper = mapper;
    try {
        this.uniqueKeyFormatter = conf.getUniqueKeyFormatterClass().newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Problem instantiating the UniqueKeyFormatter.", e);
    }
    ConfigureUtil.configure(uniqueKeyFormatter, conf.getGlobalParams());
    this.sharder = sharder;
    this.solrWriter = solrWriter;
    this.indexingTimer = Metrics.newTimer(metricName(getClass(),
            "Index update calculation timer", indexerName),
            TimeUnit.MILLISECONDS, TimeUnit.SECONDS);

}
 
Example 3
Source File: LatencyMetrics.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Create LatencyMetrics with given group, type, prefix to append to each metric name, and scope.
 *
 * @param factory MetricName factory to use
 * @param namePrefix Prefix to append to each metric name
 */
public LatencyMetrics(MetricNameFactory factory, String namePrefix)
{
    this.factory = factory;
    this.namePrefix = namePrefix;

    latency = Metrics.newTimer(factory.createMetricName(namePrefix + "Latency"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
    totalLatency = Metrics.newCounter(factory.createMetricName(namePrefix + "TotalLatency"));
}
 
Example 4
Source File: IndexManager.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public IndexManager(IndexServer indexServer, ClusterStatus clusterStatus, BlurFilterCache filterCache,
    int maxHeapPerRowFetch, int fetchCount, int threadCount, int mutateThreadCount, int facetThreadCount,
    DeepPagingCache deepPagingCache, MemoryAllocationWatcher memoryAllocationWatcher, QueryStatusManager statusManager) {
  _statusManager = statusManager;
  _memoryAllocationWatcher = memoryAllocationWatcher;
  _deepPagingCache = deepPagingCache;
  _indexServer = indexServer;
  _clusterStatus = clusterStatus;
  _filterCache = filterCache;

  MetricName metricName1 = new MetricName(ORG_APACHE_BLUR, BLUR, "External Queries/s");
  MetricName metricName2 = new MetricName(ORG_APACHE_BLUR, BLUR, "Internal Queries/s");
  MetricName metricName3 = new MetricName(ORG_APACHE_BLUR, BLUR, "Fetch Timer");

  _queriesExternalMeter = Metrics.newMeter(metricName1, "External Queries/s", TimeUnit.SECONDS);
  _queriesInternalMeter = Metrics.newMeter(metricName2, "Internal Queries/s", TimeUnit.SECONDS);
  _fetchTimer = Metrics.newTimer(metricName3, TimeUnit.MICROSECONDS, TimeUnit.SECONDS);

  if (threadCount == 0) {
    throw new RuntimeException("Thread Count cannot be 0.");
  }
  _threadCount = threadCount;
  if (mutateThreadCount == 0) {
    throw new RuntimeException("Mutate Thread Count cannot be 0.");
  }
  _mutateThreadCount = mutateThreadCount;
  _fetchCount = fetchCount;
  _maxHeapPerRowFetch = maxHeapPerRowFetch;

  _executor = Executors.newThreadPool("index-manager", _threadCount);
  _mutateExecutor = Executors.newThreadPool("index-manager-mutate", _mutateThreadCount);
  if (facetThreadCount < 1) {
    _facetExecutor = null;
  } else {
    _facetExecutor = Executors.newThreadPool(new SynchronousQueue<Runnable>(), "facet-execution", facetThreadCount);
  }

  LOG.info("Init Complete");

}
 
Example 5
Source File: FilteringSubscriber.java    From chancery with Apache License 2.0 5 votes vote down vote up
protected FilteringSubscriber(String filter) {
    this.filter = new RefFilter(filter);
    exceptionMeter = Metrics.newMeter(getClass(),
            "triggered-exception", "callbacks",
            TimeUnit.HOURS);
    filteredOutMeter = Metrics.newMeter(getClass(),
            "filtered-out", "callbacks",
            TimeUnit.HOURS);
    handledTimer = Metrics.newTimer(getClass(),
            "handled-callbacks",
            TimeUnit.SECONDS, TimeUnit.SECONDS);
}
 
Example 6
Source File: Indexer.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
public RowBasedIndexer(String indexerName, IndexerConf conf, String tableName, ResultToSolrMapper mapper,
                       Connection tablePool,
                       Sharder sharder, SolrInputDocumentWriter solrWriter) {
    super(indexerName, conf, tableName, mapper, sharder, solrWriter);
    this.tablePool = tablePool;
    rowReadTimer = Metrics.newTimer(metricName(getClass(), "Row read timer", indexerName), TimeUnit.MILLISECONDS,
            TimeUnit.SECONDS);
}
 
Example 7
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 3 votes vote down vote up
/**
 *
 * Return an existing timer if
 *  (a) A timer already exist with the same metric name.
 * Otherwise, creates a new timer and registers
 *
 * @param registry MetricsRegistry
 * @param name metric name
 * @param durationUnit TimeUnit for duration
 * @param rateUnit TimeUnit for rate determination
 * @return Timer
 */
public static Timer newTimer(MetricsRegistry registry, MetricName name, TimeUnit durationUnit, TimeUnit rateUnit) {
  if (registry != null) {
    return registry.newTimer(name, durationUnit, rateUnit);
  } else {
    return Metrics.newTimer(name, durationUnit, rateUnit);
  }
}
 
Example 8
Source File: BcryptCommandTest.java    From usergrid with Apache License 2.0 2 votes vote down vote up
/**
 * Tests bcrypt hashing with a default number of rounds.  Note that via the console output, this test should take
 * about 5 seconds to run since we want to force 500 ms per authentication attempt with bcrypt
 */
@Test
public void testHashRoundSpeed() throws UnsupportedEncodingException {

    int cryptIterations = 2 ^ 11;
    int numberOfTests = 10;

    BcryptCommand command = new BcryptCommand();
    command.setDefaultIterations( cryptIterations );

    String baseString = "I am a test password for hashing";

    CredentialsInfo info = new CredentialsInfo();


    UUID user = UUID.randomUUID();
    UUID applicationId = UUID.randomUUID();

    byte[] result = command.hash( baseString.getBytes( "UTF-8" ), info, user, applicationId );


    String stringResults = encodeBase64URLSafeString( result );

    info.setSecret( stringResults );

    Timer timer = Metrics.newTimer( BcryptCommandTest.class, "hashtimer" );

    for ( int i = 0; i < numberOfTests; i++ ) {
        TimerContext timerCtx = timer.time();

        //now check we can auth with the same phrase
        byte[] authed = command.auth( baseString.getBytes( "UTF-8" ), info, user, applicationId );

        timerCtx.stop();


        assertArrayEquals( result, authed );
    }

    /**
     * Print out the data
     */
    ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), System.out, MetricPredicate.ALL );

    reporter.run();
}