/** User needs to provide eventhub properties */ public EventhubDataWriter(Properties properties) { PasswordManager manager = PasswordManager.getInstance(properties); namespaceName = properties.getProperty(BatchedEventhubDataWriter.EVH_NAMESPACE); eventHubName = properties.getProperty(BatchedEventhubDataWriter.EVH_HUBNAME); sasKeyName = properties.getProperty(BatchedEventhubDataWriter.EVH_SAS_KEYNAME); String encodedSasKey = properties.getProperty(BatchedEventhubDataWriter.EVH_SAS_KEYVALUE); sasKey = manager.readPassword(encodedSasKey); targetURI = "https://" + namespaceName + ".servicebus.windows.net/" + eventHubName + "/messages"; httpclient = HttpClients.createDefault(); metricContext = Instrumented.getMetricContext(new State(properties),EventhubDataWriter.class); recordsAttempted = this.metricContext.meter(EventhubMetricNames.EventhubDataWriterMetrics.RECORDS_ATTEMPTED_METER); recordsSuccess = this.metricContext.meter(EventhubMetricNames.EventhubDataWriterMetrics.RECORDS_SUCCESS_METER); recordsFailed = this.metricContext.meter(EventhubMetricNames.EventhubDataWriterMetrics.RECORDS_FAILED_METER); bytesWritten = this.metricContext.meter(EventhubMetricNames.EventhubDataWriterMetrics.BYTES_WRITTEN_METER); writeTimer = this.metricContext.timer(EventhubMetricNames.EventhubDataWriterMetrics.WRITE_TIMER); }
@Override public void report() { if (this.filter.isPresent()) { report(this.context.getGauges(this.filter.get()), this.context.getCounters(this.filter.get()), this.context.getHistograms(this.filter.get()), this.context.getMeters(this.filter.get()), this.context.getTimers(this.filter.get())); } else { report(this.context.getGauges(), this.context.getCounters(), this.context.getHistograms(), this.context.getMeters(), this.context.getTimers()); } }
public JobCatalogBase(Optional<Logger> log, Optional<MetricContext> parentMetricContext, boolean instrumentationEnabled) { this.log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); this.listeners = new JobCatalogListenersList(log); if (instrumentationEnabled) { MetricContext realParentCtx = parentMetricContext.or(Instrumented.getMetricContext(new gobblin.configuration.State(), getClass())); this.metricContext = realParentCtx.childBuilder(JobCatalog.class.getSimpleName()).build(); this.metrics = new StandardMetrics(this); } else { this.metricContext = null; this.metrics = null; } }
public static Map<String, Long> dumpMetrics(MetricContext context) { Map<String, Long> output = new HashMap<>(); for (Map.Entry<String, Meter> entry : context.getMeters().entrySet()) { output.put(entry.getKey(), entry.getValue().getCount()); } for (Map.Entry<String, Timer> entry : context.getTimers().entrySet()) { output.put(entry.getKey(), entry.getValue().getCount()); } return output; }
/** * Get a {@link Timer} with the given name prefix and suffixes. * * @param prefix the given name prefix * @param suffixes the given name suffixes * @return a {@link Timer} with the given name prefix and suffixes */ public Timer getTimer(String prefix, String... suffixes) { return this.metricContext.timer(MetricRegistry.name(prefix, suffixes)); }
/** * Get a {@link Meter} with the given name prefix and suffixes. * * @param prefix the given name prefix * @param suffixes the given name suffixes * @return a {@link Meter} with the given name prefix and suffixes */ public Meter getMeter(String prefix, String... suffixes) { return this.metricContext.meter(MetricRegistry.name(prefix, suffixes)); }
@Override public void run() { Counter totalRecordsCounter = this.context.contextAwareCounter(TOTAL_RECORDS); Meter recordProcessRateMeter = this.context.contextAwareMeter(RECORD_PROCESS_RATE); Timer recordProcessTimeTimer = this.context.contextAwareTimer(RECORD_PROCESS_TIME); Histogram recordSizesHistogram = this.context.contextAwareHistogram(RECORD_SIZES); } finally{ try { this.context.close(); } catch (IOException ioe) { LOGGER.error("Failed to close context: " + this.context.getName(), ioe); } finally { this.countDownLatch.countDown();
MetricArray metricArray = new MetricArray(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getCounters() .entrySet()) { Metric counter = new Metric(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getMeters() .entrySet()) { Metric meter = new Metric(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : jobMetrics.getMetricContext().getGauges() .entrySet()) { Metric gauge = new Metric();
private synchronized ExecutorService getExecutorService() { if(!this.executorServiceOptional.isPresent()) { this.executorServiceOptional = Optional.of(MoreExecutors.getExitingExecutorService( (ThreadPoolExecutor) Executors.newCachedThreadPool(ExecutorsUtils.newThreadFactory(Optional.of(LOG), Optional.of("MetricContext-" + getName() + "-%d"))), 5, TimeUnit.MINUTES)); } return this.executorServiceOptional.get(); }
/** * Instantiates {@link com.codahale.metrics.Metric}s. Called once in {@link #startUp()}. Subclasses should override * this method to instantiate their own metrics. */ protected void createMetrics() { this.messagesRead = this.metricContext.counter(RuntimeMetrics.GOBBLIN_KAFKA_HIGH_LEVEL_CONSUMER_MESSAGES_READ); }
? gobblinMetrics.get().getMetricContext().childBuilder(klazz.getCanonicalName() + "." + randomId) : MetricContext.builder(klazz.getCanonicalName() + "." + randomId); return builder.addTags(generatedTags).addTags(tags).build();
@Override public Policy get(String resourceId) { try { ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy) this.broker.getSharedResource(new ThrottlingPolicyFactory(), new SharedLimiterKey(resourceId)); Policy restliPolicy = new Policy(); restliPolicy.setPolicyName(throttlingPolicy.getClass().getSimpleName()); restliPolicy.setResource(resourceId); restliPolicy.setParameters(new StringMap(throttlingPolicy.getParameters())); restliPolicy.setPolicyDetails(throttlingPolicy.getDescription()); MetricContext resourceContext = (MetricContext) broker.getSharedResource(new MetricContextFactory(), new SubTaggedMetricContextKey(resourceId, ImmutableMap.of(RESOURCE_ID_TAG, resourceId))); StringMap metrics = new StringMap(); for (Map.Entry<String, Meter> meter : resourceContext.getMeters().entrySet()) { metrics.put(meter.getKey(), Double.toString(meter.getValue().getOneMinuteRate())); } restliPolicy.setMetrics(metrics); return restliPolicy; } catch (NotConfiguredException nce) { throw new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Policy not found for resource " + resourceId); } } }
/** * Get a new {@link MetricContext.Builder} for building child {@link MetricContext}s. * * @param name name of the child {@link MetricContext} to be built * @return a new {@link MetricContext.Builder} for building child {@link MetricContext}s */ public Builder childBuilder(String name) { return builder(name).hasParent(this); }
@VisibleForTesting protected void shutdownMetrics() throws IOException { if (this.metricContext != null) { this.metricContext.close(); } }
public MetricsFileSystemInstrumentation(FileSystem underlying) { super(underlying); this.closer = Closer.create(); this.metricContext = new MetricContext.Builder(underlying.getUri() + "_metrics").build(); this.metricContext = this.closer.register(metricContext); this.listStatusTimer = this.metricContext.timer("listStatus"); this.listFilesTimer = this.metricContext.timer("listFiles"); this.globStatusTimer = this.metricContext.timer("globStatus"); this.mkdirTimer = this.metricContext.timer("mkdirs"); this.renameTimer = this.metricContext.timer("rename"); this.deleteTimer = this.metricContext.timer("delete"); this.createTimer = this.metricContext.timer("create"); this.openTimer = this.metricContext.timer("open"); this.setOwnerTimer = this.metricContext.timer("setOwner"); this.getFileStatusTimer = this.metricContext.timer("getFileStatus"); this.setPermissionTimer = this.metricContext.timer("setPermission"); this.setTimesTimer = this.metricContext.timer("setTimes"); this.appendTimer = this.metricContext.timer ("append"); this.concatTimer = this.metricContext.timer ("concat"); this.allTimers = ImmutableList.<ContextAwareTimer>builder().add( this.listStatusTimer, this.listFilesTimer, this.globStatusTimer, this.mkdirTimer, this.renameTimer, this.deleteTimer, this.createTimer, this.openTimer, this.setOwnerTimer, this.getFileStatusTimer, this.setPermissionTimer, this.setTimesTimer, this.appendTimer, this.concatTimer ).build(); }
/** * Generates metrics for the instrumentation of this class. */ protected void regenerateMetrics() { if (isInstrumentationEnabled()) { this.datasetsCleanFailureMeter = Optional.of(this.metricContext.meter(DatasetCleanerMetrics.DATASETS_CLEAN_FAILURE)); this.datasetsCleanSuccessMeter = Optional.of(this.metricContext.meter(DatasetCleanerMetrics.DATASETS_CLEAN_SUCCESS)); } }
MetricArray metricArray = new MetricArray(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getCounters() .entrySet()) { Metric counter = new Metric(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getMeters() .entrySet()) { Metric meter = new Metric(); for (Map.Entry<String, ? extends com.codahale.metrics.Metric> entry : taskMetrics.getMetricContext().getGauges() .entrySet()) { Metric gauge = new Metric();
@Override public String toString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("InnerMetricContext Name: "); stringBuilder.append(this.name); if (this.getParent().isPresent()) { stringBuilder.append(", Parent Name: "); stringBuilder.append(this.getParent().get().getName()); } else { stringBuilder.append(", No Parent Context"); } stringBuilder.append(", Number of Children: "); stringBuilder.append(this.getChildContextsAsMap().size()); stringBuilder.append(", Tags: "); stringBuilder.append(Joiner.on(", ").withKeyValueSeparator(" : ").useForNull("NULL").join(this.getTagMap())); return stringBuilder.toString(); } }
/** * Get a {@link Counter} with the given name prefix and suffixes. * * @param prefix the given name prefix * @param suffixes the given name suffixes * @return a {@link Counter} with the given name prefix and suffixes */ public Counter getCounter(String prefix, String... suffixes) { return this.metricContext.counter(MetricRegistry.name(prefix, suffixes)); }
public ReporterExampleBase(ContextAwareScheduledReporter.Builder reporterBuilder, int tasks, long totalRecords) { this.executor = Executors.newFixedThreadPool(10); this.context = MetricContext.builder("Job") .addTag(new Tag<String>(JobEvent.METADATA_JOB_NAME, "ExampleJob")) .addTag(new Tag<String>(JobEvent.METADATA_JOB_ID, JOB_NAME + "_" + System.currentTimeMillis())) .build(); this.reporterBuilder = reporterBuilder; this.tasks = tasks; this.totalRecords = totalRecords; }