Java Code Examples for com.twitter.ostrich.stats.Stats#addMetric()
The following examples show how to use
com.twitter.ostrich.stats.Stats#addMetric() .
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: HFileReader.java From terrapin with Apache License 2.0 | 6 votes |
/** * Issues an HFile lookup on the underlying HFile.Reader. This is protected * for testing. */ protected Pair<ByteBuffer, Pair<ByteBuffer, Throwable>> getValueFromHFile(ByteBuffer key) { try { HFileScanner scanner = reader.getScanner(true, true, false); KeyValue kv = buildKeyValueForLookup( BytesUtil.readBytesFromByteBufferWithoutConsume(key)); int code = scanner.seekTo(kv.getKey()); ByteBuffer value = null; if (code == 0) { value = ByteBuffer.wrap(scanner.getKeyValue().getValue()); if (this.sizeStatsKey != null) { Stats.addMetric(this.sizeStatsKey, value.remaining()); } Stats.addMetric("value-size", value.remaining()); } else { Stats.incr("not-found"); if (this.notFoundStatsKey != null) { Stats.incr(this.notFoundStatsKey); } } return new ImmutablePair(key, new ImmutablePair(value, null)); } catch (Throwable t) { return new ImmutablePair(key, new ImmutablePair(null, t)); } }
Example 2
Source File: HealthCheckJob.java From soundwave with Apache License 2.0 | 6 votes |
private void checkQueueLength() { try { GetQueueAttributesResult result = sqsClient.getQueueAttributes(queueUrl, Arrays.asList(QUEUELENGTHATTR, QUEUEINVISIBLEATTR)); Map<String, String> attrs = result.getAttributes(); if (attrs.containsKey(QUEUELENGTHATTR)) { Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_length"), Integer.parseInt(attrs.get(QUEUELENGTHATTR))); logger.info("Ec2 queue length is {}", attrs.get(QUEUELENGTHATTR)); } if (attrs.containsKey(QUEUEINVISIBLEATTR)) { Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_in_processing"), Integer.parseInt(attrs.get("ApproximateNumberOfMessagesNotVisible"))); logger.info("Ec2 queue in processing length is {}", attrs.get(QUEUEINVISIBLEATTR)); } } catch (Exception ex) { logger.warn(ExceptionUtils.getRootCauseMessage(ex)); logger.warn(ExceptionUtils.getFullStackTrace(ex)); } }
Example 3
Source File: OperationStats.java From soundwave with Apache License 2.0 | 6 votes |
public void failed(Map<String, String> additionalTags) { this.watch.stop(); if (tags == null) { this.tags = additionalTags; } else { this.tags.putAll(additionalTags); } Stats .incr(StatsUtil .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.FAILURE, tags)); Stats.addMetric( StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags), (int) watch.getTime()); }
Example 4
Source File: OperationStats.java From soundwave with Apache License 2.0 | 6 votes |
public void succeed(Map<String, String> additionalTags) { this.watch.stop(); if (tags == null) { this.tags = additionalTags; } else { this.tags.putAll(additionalTags); } Stats .incr(StatsUtil .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.SUCCESS, tags)); Stats.addMetric( StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags), (int) watch.getTime()); }
Example 5
Source File: OstrichMetricCollectorTest.java From secor with Apache License 2.0 | 5 votes |
@Test public void metric() throws Exception { metricCollector.metric("expectedLabel", 42.0, "ignored"); PowerMockito.verifyStatic(Stats.class); Stats.addMetric("expectedLabel", 42); }
Example 6
Source File: StatTrackingEventListener.java From pinlater with Apache License 2.0 | 5 votes |
@Override public void onSuccess(T t) { // Counts can be derived from the metric's count. Stats.addMetric( String.format("%s.success", statPrefix), (int) (TimeUtils.millisTime() - startTime)); String tagsString = getTagsString(); if (!Strings.isNullOrEmpty(tagsString)) { Stats.addMetric( String.format("%s.success.withtags%s", statPrefix, tagsString), (int) (TimeUtils.millisTime() - startTime)); } }
Example 7
Source File: OperationStats.java From soundwave with Apache License 2.0 | 5 votes |
public void failed() { this.watch.stop(); Stats .incr(StatsUtil .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.FAILURE, tags)); Stats.addMetric( StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags), (int) watch.getTime()); }
Example 8
Source File: OperationStats.java From soundwave with Apache License 2.0 | 5 votes |
public void succeed() { this.watch.stop(); Stats .incr(StatsUtil .getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.SUCCESS, tags)); Stats.addMetric( StatsUtil.getStatsName(this.methodName, this.statsName, StatsUtil.StatsType.TIME, tags), (int) watch.getTime()); }
Example 9
Source File: DefaultLogMonitor.java From singer with Apache License 2.0 | 5 votes |
/** * Monitor all SingerLogs configured. * <p> * This method is NOT thread-safe. It should be called from one thread at any time. * * @throws LogMonitorException when fail to monitor one of the SingerLogs. */ public void monitorLogs() throws LogMonitorException { LOG.info("Start monitoring cycle."); long monitorCycleStartTime = System.currentTimeMillis(); Collection<LogStream> logStreams = LogStreamManager.getLogStreams(); for (LogStream logStream : logStreams) { String logStreamName = logStream.getLogStreamName(); boolean success = false; try { LogStreamProcessor logStreamProcessor = processedLogStreams.get(logStream); if (logStreamProcessor == null) { LogStreamProcessor processor = createLogStreamProcessor( logStream.getSingerLog().getSingerLogConfig(), logStream); processor.start(); processedLogStreams.put(logStream, processor); LOG.info("Start processing log stream: {} in log: {}", logStream, logStreamName); } else { // refresh the latest modification time. LOG.info("Log stream: {} in log: {} is being processed.", logStream, logStreamName); // set last completed latency in LogStream object so we don't have to look-up // processor for logstream logStream.setLastCompletedCycleTime(logStreamProcessor.getLastCompleteCycleTime()); } success = true; } catch (Exception e) { LOG.error("Exception in monitorLogs for " + logStream, e); Stats.incr("singer.monitor.unexpected_exception"); } if (!success) { Stats.incr("singer.monitor.processor_creation_failure"); LOG.error("Failed to create log monitor for {}", logStream); } } Stats.addMetric("singer.monitor.monitor_cycle_time", (int) (System.currentTimeMillis() - monitorCycleStartTime)); Stats.setGauge(SingerMetrics.NUM_LOGSTREAMS, processedLogStreams.size()); }
Example 10
Source File: EC2LocalityInfoProvider.java From singer with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, String> conf) throws IllegalArgumentException, IOException { // check if EC2 AZ info is working try { EC2MetadataUtils.getAvailabilityZone(); // cache locality info to avoid service based lookups cachedLocality = EC2MetadataUtils.getAvailabilityZone(); } catch (Exception e) { LOG.error("Failed to get AZ info", e); Stats.addMetric(SingerMetrics.LOCALITY_MISSING, 1); cachedLocality = LOCALITY_NOT_AVAILABLE; } }
Example 11
Source File: Ec2InstanceUpdateHandler.java From soundwave with Apache License 2.0 | 4 votes |
private MessageProcessingResult ensureInstanceCreated(NotificationEvent event) throws Exception { String instanceId = event.getDetail().getInstanceId(); StopWatch watch = new StopWatch(); watch.start(); MessageProcessingResult result = new MessageProcessingResult(event); result.setSucceed(true); try { //Get EC2 instance Instance inst = cloudInstanceStore.getInstance(instanceId); if (inst != null) { //Create the corresponding EsInstance EsInstance esInstance = esInstanceFactory.createFromEC2(inst); long version = cmdbInstanceStore.updateOrInsertInstance(esInstance); if (version == 0) { logger.info("Instance {} is created", instanceId); //Created in ES DateTime utcNow = DateTime.now(DateTimeZone.UTC); DateTime enqueueTime = new DateTime(event.getSqsSentTime(), DateTimeZone.UTC); int sinceEnqueued = Seconds.secondsBetween(enqueueTime, utcNow).getSeconds(); int sinceLaunched = Seconds.secondsBetween(new DateTime(esInstance.getAwsLaunchTime()), utcNow) .getSeconds(); //First time instance created Stats.addMetric(StatsUtil.getStatsName("ec2_creation", "since_enqueued"), sinceEnqueued > 0 ? sinceEnqueued : 0); Stats.addMetric(StatsUtil.getStatsName("ec2_creation", "since_launched"), sinceLaunched > 0 ? sinceLaunched : 0); } else { logger.info("Instance {} is updated", instanceId); } logger.info("Create Instance {} in ElasticSearch", instanceId); onInstanceCreation(esInstance, result); Tag nameTag = AwsUtilities.getAwsTag(inst, "Name"); if (nameTag == null) { result.setError(MessageProcessingResult.MessageProcessingError.NO_NAME_TAG); } else if (State.PENDING.name().equalsIgnoreCase(esInstance.getState())) { //Still pending. Put back to the queue and wait it into running result.setError(MessageProcessingResult.MessageProcessingError.STILL_PENDING); } else { onInstanceCreation(esInstance, result); } try { syncWithDailySnapshot(event, esInstance); } catch (Exception ex) { logger.error("Failed to sync with daily snapshot {} with error {}", instanceId, ex.getMessage()); } } else { result.setError(MessageProcessingResult.MessageProcessingError.NOT_EXIST_IN_EC_2); } return result; } finally { watch.stop(); result.setDuration(watch.getTime()); } }
Example 12
Source File: OpenTsdbMetricConverter.java From doctorkafka with Apache License 2.0 | 4 votes |
public static void addMetric(String name, int value) { Stats.addMetric(name, value); }
Example 13
Source File: OpenTsdbMetricConverter.java From doctorkafka with Apache License 2.0 | 4 votes |
public static void addMetric(String name, int value, String... tags) { Stats.addMetric(nameMetric(name, tags), value); }
Example 14
Source File: OpenTsdbMetricConverter.java From singer with Apache License 2.0 | 4 votes |
public static void addGranularMetric(String name, int value, String... tags) { if (!enableGranularMetrics) { return; } Stats.addMetric(nameMetric(name, tags), value); }
Example 15
Source File: OpenTsdbMetricConverter.java From singer with Apache License 2.0 | 4 votes |
public static void addMetric(String name, int value, String... tags) { Stats.addMetric(nameMetric(name, tags), value); }
Example 16
Source File: OstrichMetricCollector.java From secor with Apache License 2.0 | 4 votes |
@Override public void metric(String label, double value, String topic) { Stats.addMetric(label, (int) value); }
Example 17
Source File: OpenTsdbMetricConverter.java From singer with Apache License 2.0 | 4 votes |
public static void addMetric(String name, int value) { Stats.addMetric(name, value); }