@VisibleForTesting DecayingEstimatedHistogramReservoir(boolean considerZeroes, int bucketCount, Clock clock) { if (bucketCount == DEFAULT_BUCKET_COUNT) { if (considerZeroes == true) { bucketOffsets = DEFAULT_WITH_ZERO_BUCKET_OFFSETS; } else { bucketOffsets = DEFAULT_WITHOUT_ZERO_BUCKET_OFFSETS; } } else { bucketOffsets = EstimatedHistogram.newOffsets(bucketCount, considerZeroes); } decayingBuckets = new AtomicLongArray(bucketOffsets.length + 1); buckets = new AtomicLongArray(bucketOffsets.length + 1); this.clock = clock; decayLandmark = clock.getTime(); }
public void onResponseReceived(HttpRequest request, HttpResponse response) { Long startTime = removeObjectProperty(request, START_TIME_PROPERTY_NAME); if (startTime == null) { return; } long t = Clock.defaultClock().getTick() - startTime; String method = request.getRequestLine().getMethod(); int statusCode = response.getStatusLine().getStatusCode(); String metricName = ROOT_NAME.withTags( "method", method, "status", "" + statusCode).toString(); Timer timer = RegistryService.getMetricRegistry().timer(metricName); timer.update(t, TimeUnit.NANOSECONDS); }
public void onGetInputStream(HttpURLConnection urlConnection, int statusCode) { Long startTime = removeObjectProperty(urlConnection, START_TIME_PROPERTY_NAME); if (startTime == null) { return; } long t = Clock.defaultClock().getTick() - startTime; String method = urlConnection.getRequestMethod(); String status = "" + statusCode; Timer timer = timers.computeIfAbsent(status + method, s -> { TagEncodedMetricName metricName = ROOT_NAME.withTags( "method", method, "status", status); return getTimer(metricName); }); timer.update(t, TimeUnit.NANOSECONDS); }
private ElasticsearchReporter(MetricRegistry registry, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, String host, String port, String indexName, String timestampField) { super(registry, "elasticsearch-reporter", filter, rateUnit, durationUnit); this.clock = Clock.defaultClock(); this.connector = new ElasticsearchConnector(host, port, indexName); this.timestampField = timestampField; this.timestampFormat = new SimpleDateFormat(timeStampString); this.localhost = Utils.localHostName(); jsonFactory = new JsonFactory(); indexInitialized = connector.addDefaultMappings(); if (!indexInitialized) { LOGGER.warn("Failed to initialize Elasticsearch index '" + indexName + "' on " + host + ":" + port); } }
HawkularReporter(MetricRegistry registry, HawkularHttpClient hawkularClient, Optional<String> prefix, MetricsDecomposer decomposer, MetricsTagger tagger, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter) { super(registry, "hawkular-reporter", filter, rateUnit, durationUnit); this.prefix = prefix; this.clock = Clock.defaultClock(); this.hawkularClient = hawkularClient; this.decomposer = decomposer; this.tagger = tagger; }
@Test public void testBasic() throws Exception { FileUtil.removeIfExist("build/ServerLogMetricPlugin", false); YaraServiceImpl yaraService = new YaraServiceImpl() ; server.getServiceRegistry().register(YaraService.newReflectiveBlockingService(yaraService)); MetricRegistry server1 = createMetricRegistry("server1") ; MetricRegistry server2 = createMetricRegistry("server2") ; Random rand = new Random() ; for(int i = 0; i < 100000; i++) { long timestamp = Clock.defaultClock().getTick() ; server1.counter("counter").incr() ; server1.timer("timer").update(timestamp, rand.nextInt(1000)) ; server2.counter("counter").incr() ; server2.timer("timer").update(timestamp, rand.nextInt(1000)) ; } Thread.sleep(6000); new ClusterMetricPrinter().print(yaraService.getClusterMetricRegistry()); }
private StorageReporter(MetricRegistry registry, Locale locale, Clock clock, TimeZone timeZone, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, StorageAdapter storageAdapter) { super(registry, "storage-reporter", filter, rateUnit, durationUnit); this.locale = locale; this.clock = clock; this.storageAdapter = storageAdapter; this.dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(timeZone); }
public ReporterV08(MetricRegistry registry, Influxdb influxdb, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, boolean skipIdleMetrics, ScheduledExecutorService executor) { super(registry, "influxdb-reporter", filter, rateUnit, durationUnit, executor); this.skipIdleMetrics = skipIdleMetrics; this.previousValues = new TreeMap<String, Long>(); this.influxdb = influxdb; this.clock = clock; this.prefix = (prefix == null) ? "" : (prefix.trim() + "."); }
protected ElasticsearchReporter(MetricRegistry registry, Clock clock, String elasticsearchIndexPrefix, String timestampFieldName, String metricPrefix, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter) { super(registry, "elasticsearch-reporter", filter, rateUnit, durationUnit); this.clock = clock; this.metricPrefix = metricPrefix; this.timestampFieldName = timestampFieldName; if (elasticsearchIndexPrefix.endsWith("-")) { this.elasticsearchIndexPrefix = elasticsearchIndexPrefix; } else { this.elasticsearchIndexPrefix = elasticsearchIndexPrefix + "-"; } jsonFactory = new JsonFactory(); }
@Before public void setUp() throws Exception { httpClient = mock(HttpClient.class); Clock clock = mock(Clock.class); timestamp = System.currentTimeMillis(); when(clock.getTime()).thenReturn(timestamp); final CorePlugin corePlugin = mock(CorePlugin.class); when(corePlugin.getInfluxDbUrl()).thenReturn(new URL("http://localhost:8086")); when(corePlugin.getInfluxDbDb()).thenReturn("stm"); influxDbReporter = InfluxDbReporter.forRegistry(new Metric2Registry(), corePlugin) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(DURATION_UNIT) .globalTags(singletonMap("app", "test")) .httpClient(httpClient) .clock(clock) .build(); }
public AsyncRequestLog(Clock clock, AppenderAttachableImpl<ILoggingEvent> appenders, final TimeZone timeZone, List<String> cookies) { this.clock = clock; this.cookies = cookies; this.queue = new LinkedBlockingQueue<String>(); this.dispatcher = new Dispatcher(); this.dispatchThread = new Thread(dispatcher); dispatchThread.setName("async-request-log-dispatcher-" + THREAD_COUNTER.incrementAndGet()); dispatchThread.setDaemon(true); this.dateCache = new ThreadLocal<DateCache>() { @Override protected DateCache initialValue() { final DateCache cache = new DateCache("dd/MMM/yyyy:HH:mm:ss Z", Locale.US); cache.setTimeZoneID(timeZone.getID()); return cache; } }; this.appenders = appenders; }
private AbstractConnector configureExternalHttpsConnector() { logger.info("Creating https connector"); final SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias(getConfiguration().getSslConfiguration().getKeyStoreAlias()); sslContextFactory.setKeyStorePath(getConfiguration().getSslConfiguration().getKeyStorePath()); sslContextFactory.setKeyStorePassword(getConfiguration().getSslConfiguration().getKeyStorePassword()); final Integer port = getConfiguration().getSslConfiguration().getPort() != null ? getConfiguration().getSslConfiguration().getPort() : getConfiguration().getPort(); final InstrumentedSslSocketConnector connector = new InstrumentedSslSocketConnector( this.metricRegistry, port, sslContextFactory, Clock.defaultClock()); connector.setName(EXTERNAL_HTTPS_CONNECTOR_NAME); return connector; }
public void onTransactionExec(Transaction tx) { Long startTime = removeObjectProperty(tx, TRANSACTION_START_TIME_PROP_NAME); if (startTime == null) { return; } long t = Clock.defaultClock().getTick() - startTime; txExecTimer.update(t, TimeUnit.NANOSECONDS); }
public void onTransactionDiscard(Transaction tx) { Long startTime = removeObjectProperty(tx, TRANSACTION_START_TIME_PROP_NAME); if (startTime == null) { return; } long t = Clock.defaultClock().getTick() - startTime; txDiscardTimer.update(t, TimeUnit.NANOSECONDS); }
public void onPipelineSync(Pipeline pipeline) { Long startTime = removeObjectProperty(pipeline, TRANSACTION_START_TIME_PROP_NAME); if (startTime == null) { return; } long t = Clock.defaultClock().getTick() - startTime; pipelineSyncTimer.update(t, TimeUnit.NANOSECONDS); }
private Builder(MetricRegistry registry) { this.registry = registry; this.clock = Clock.defaultClock(); this.prefix = null; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; }
public ElasticsearchReporter(MetricRegistry registry, String[] hosts, int timeout, String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname,Map<String,String> context) throws MalformedURLException { super(registry, "elasticsearch-reporter", filter, rateUnit, durationUnit); this.hosts = hosts; this.index = index; this.bulkSize = bulkSize; this.clock = clock; this.prefix = prefix; this.timeout = timeout; if (indexDateFormat != null && indexDateFormat.length() > 0) { this.indexDateFormat = new SimpleDateFormat(indexDateFormat); } if (percolationNotifier != null && percolationFilter != null) { this.percolationFilter = percolationFilter; this.notifier = percolationNotifier; } if (timestampFieldname == null || timestampFieldname.trim().length() == 0) { LOGGER.error("Timestampfieldname {} is not valid, using default @timestamp", timestampFieldname); timestampFieldname = "@timestamp"; } objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.configure(SerializationFeature.CLOSE_CLOSEABLE, false); // auto closing means, that the objectmapper is closing after the first write call, which does not work for bulk requests objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); objectMapper.registerModule(new MetricsElasticsearchModule(rateUnit, durationUnit, timestampFieldname)); writer = objectMapper.writer(); checkForIndexTemplate(); }
private Builder(MetricRegistry registry) { this.registry = registry; this.locale = Locale.getDefault(); this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.clock = Clock.defaultClock(); this.filter = MetricFilter.ALL; }
/** */ private HumanReadableCsvReporter(MetricRegistry registry, File directory, Locale locale, TimeUnit rateUnit, TimeUnit durationUnit, Clock clock, MetricFilter filter) { super(registry, "human-readable-csv-reporter", filter, rateUnit, durationUnit); this.directory = directory; this.locale = locale; this.clock = clock; }
private void setupRateTest() throws InterruptedException { Clock clock = mock(Clock.class); meter = new DelegatingDerivingMeter(new Meter(clock)); when(clock.getTick()).thenReturn(0L); meter.mark(0); meter.mark(2000); // need to 'wait' more than 5 seconds for the Codahale metrics meter to 'tick'. when(clock.getTick()).thenReturn(TimeUnit.NANOSECONDS.convert(6, TimeUnit.SECONDS)); }
private Builder(final MetricRegistry metricRegistry, final AmazonCloudWatchAsync cloudWatchAsyncClient, final String namespace) { this.metricRegistry = metricRegistry; this.cloudWatchAsyncClient = cloudWatchAsyncClient; this.namespace = namespace; this.percentiles = new Percentile[]{Percentile.P75, Percentile.P95, Percentile.P999}; this.metricFilter = MetricFilter.ALL; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.globalDimensions = new LinkedHashSet<>(); this.cwRateUnit = toStandardUnit(rateUnit); this.cwDurationUnit = toStandardUnit(durationUnit); this.clock = Clock.defaultClock(); }
public CustomMeter(final Clock clock, final int periodSec) { final double ps = periodSec > 0 ? periodSec : 10; final int intervalSecs = 1; rateAvg = new EWMA(1 - exp(-intervalSecs / ps), intervalSecs, TimeUnit.SECONDS); this.clock = clock; startTime = clock.getTick(); lastTick.set(startTime); }
public CompositeForwardingTimer(Timer mainDelegate, MetricProvider<Timer> supplementaryMetricProvider) { Preconditions.checkNotNull(mainDelegate); Preconditions.checkNotNull(supplementaryMetricProvider); this.mainDelegate = mainDelegate; this.supplementaryMetricProvider = supplementaryMetricProvider; this.clock = Clock.defaultClock(); }
private CirconusReporter(MetricRegistry metricRegistry, Transport transport, MetricFilter filter, Clock clock, String host, EnumSet<Expansion> expansions, TimeUnit rateUnit, TimeUnit durationUnit, MetricNameFormatter metricNameFormatter, List<String> tags, String prefix, DynamicTagsCallback tagsCallback, Boolean suppress) { super(metricRegistry, "circonus-reporter", filter, rateUnit, durationUnit); if(!(metricRegistry instanceof CirconusMetricRegistryAlaCoda)) { LOG.warn("CirconusReporter started without a CirconusMetricRegistry(AlaCoda) so no real histograms."); } this.clock = clock; this.host = host; this.expansions = expansions; this.metricNameFormatter = metricNameFormatter; this.tags = (tags == null) ? new ArrayList<String>() : tags; this.transport = transport; this.prefix = prefix; this.tagsCallback = tagsCallback; this.suppress_bad_analytics = suppress; }
public Builder(MetricRegistry registry) { this.registry = registry; this.expansions = Expansion.ALL; this.clock = Clock.defaultClock(); this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; this.metricNameFormatter = new DefaultMetricNameFormatter(); this.tags = new ArrayList<String>(); this.suppress_bad_analytics = true; }
protected Builder(MetricRegistry registry) { this.registry = registry; this.output = System.out; this.locale = Locale.getDefault(); this.clock = Clock.defaultClock(); this.timeZone = TimeZone.getDefault(); this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; this.tags = new LinkedHashMap<String, String>(); }
public OperatingSystemGaugeSet( OperatingSystemMXBean osMxBean, int cacheTimeoutValue, TimeUnit cacheTimeoutUnit, Clock cacheTimeoutClock ) { this.osMxBean = osMxBean; this.cacheTimeoutValue = cacheTimeoutValue; this.cacheTimeoutUnit = cacheTimeoutUnit; this.cacheTimeoutClock = cacheTimeoutClock; }
public OperatingSystemInfo( OperatingSystemMXBean osMxBean, long timeout, TimeUnit timeoutUnit, Clock timeoutClock ) { super( Objects.requireNonNull( timeoutClock ), timeout, Objects.requireNonNull( timeoutUnit ) ); this.osMxBean = Objects.requireNonNull( osMxBean ); }
private Builder(MetricRegistry registry) { this.registry = registry; this.output = System.out; this.locale = Locale.getDefault(); this.clock = Clock.defaultClock(); this.timeZone = TimeZone.getDefault(); this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; }
private Builder(MetricRegistry registry) { this.registry = registry; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.clock = Clock.defaultClock(); this.filter = MetricFilter.ALL; }
private DasReporter(MetricRegistry registry, String source, String type, String receiverURL, String authURL, String username, String password, String dataAgentConfigPath, TimeUnit rateUnit, TimeUnit durationUnit, Clock clock, MetricFilter filter) { super(registry, "das-reporter", filter, rateUnit, durationUnit); this.source = source; this.clock = clock; if (source == null || source.trim().isEmpty()) { throw new IllegalArgumentException("Source cannot be null or empty"); } if (type == null || type.trim().isEmpty()) { throw new IllegalArgumentException("Type cannot be null or empty"); } if (receiverURL == null || receiverURL.trim().isEmpty()) { throw new IllegalArgumentException("Data Receiver URL cannot be null or empty"); } if (username == null || username.trim().isEmpty()) { throw new IllegalArgumentException("Username cannot be null or empty"); } if (password == null || password.trim().isEmpty()) { throw new IllegalArgumentException("Password cannot be null or empty"); } if (dataAgentConfigPath != null) { AgentHolder.setConfigPath(dataAgentConfigPath); } try { dataPublisher = new DataPublisher(type, receiverURL, authURL, username, password); } catch (DataEndpointAgentConfigurationException | DataEndpointException | DataEndpointConfigurationException | DataEndpointAuthenticationException | TransportException e) { throw new IllegalStateException("Error when initializing the Data Publisher", e); } }
private Builder(MetricRegistry registry) { this.registry = registry; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.clock = Clock.defaultClock(); this.filter = MetricFilter.ALL; this.timestampUnit = TimeUnit.SECONDS; }
private JdbcReporter(MetricRegistry registry, String source, DataSource dataSource, TimeUnit rateUnit, TimeUnit durationUnit, TimeUnit timestampUnit, Clock clock, MetricFilter filter) { super(registry, "jdbc-reporter", filter, rateUnit, durationUnit); this.source = source; this.dataSource = dataSource; this.timestampUnit = timestampUnit; this.clock = clock; if (source == null || source.trim().isEmpty()) { throw new IllegalArgumentException("Source cannot be null or empty"); } if (dataSource == null) { throw new IllegalArgumentException("Data source cannot be null"); } }
/** * Build a new reservoir. * * @param clock Clock to use as a time source * @param size Number of buckets to maintain * @param step Step between each bucket * @param stepUnit Time unit used in 'step' * @param delegate Delegate reservoir that min/max is being corrected for. */ public MinMaxSlidingTimeReservoir( final Clock clock, final int size, final long step, final TimeUnit stepUnit, final Reservoir delegate ) { this.clock = clock; this.size = size; this.step = stepUnit.toNanos(step); this.delegate = delegate; }
private Builder(MetricRegistry registry) { this.registry = registry; this.clock = Clock.defaultClock(); this.filter = MetricFilter.ALL; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; }
public ExtendedMeter(Clock clock) { super(clock); this.clock = clock; this.lastTick = new AtomicLong(this.clock.getTick()); m30Rate = new EWMA(M30_ALPHA, INTERVAL, TimeUnit.SECONDS); h1Rate = new EWMA(H1_ALPHA, INTERVAL, TimeUnit.SECONDS); h6Rate = new EWMA(H6_ALPHA, INTERVAL, TimeUnit.SECONDS); h12Rate = new EWMA(H12_ALPHA, INTERVAL, TimeUnit.SECONDS); h24Rate = new EWMA(H24_ALPHA, INTERVAL, TimeUnit.SECONDS); }