public HistogramLineIngester(Collection<ChannelHandler> handlers, int port) { this.handlers = new ArrayList<>(handlers); this.port = port; this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
public HistogramLineIngester(Collection<ChannelHandler> handlers, int port) { this.handlers = new ArrayList<>(handlers); this.port = port; this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
private void initMetrics(int port) { this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
private void initMetrics(int port) { this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
private ChannelInitializer createInitializer(ChannelHandler channelHandler, String strPort) { ChannelHandler idleStateEventHandler = new IdleStateEventHandler( Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", strPort))); ChannelHandler connectionTracker = new ConnectionTrackingHandler( Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", strPort)), Metrics.newCounter(new TaggedMetricName("listeners", "connections.active", "port", strPort))); return new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipeline.addFirst("idlehandler", new IdleStateHandler(listenerIdleConnectionTimeout, 0, 0)); pipeline.addLast("idlestateeventhandler", idleStateEventHandler); pipeline.addLast("connectiontracker", connectionTracker); pipeline.addLast(new PlainTextOrHttpFrameDecoder(channelHandler, pushListenerMaxReceivedLength, pushListenerHttpBufferSize)); } }; }
private ChannelInitializer createInitializer(ChannelHandler channelHandler, String strPort) { ChannelHandler idleStateEventHandler = new IdleStateEventHandler( Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", strPort))); ChannelHandler connectionTracker = new ConnectionTrackingHandler( Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", strPort)), Metrics.newCounter(new TaggedMetricName("listeners", "connections.active", "port", strPort))); return new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipeline.addFirst("idlehandler", new IdleStateHandler(listenerIdleConnectionTimeout, 0, 0)); pipeline.addLast("idlestateeventhandler", idleStateEventHandler); pipeline.addLast("connectiontracker", connectionTracker); pipeline.addLast(new PlainTextOrHttpFrameDecoder(channelHandler, pushListenerMaxReceivedLength, pushListenerHttpBufferSize)); } }; }
public String getString(String key, String defaultValue, @Nullable Function<String, String> converter) { String s = prop.getProperty(key, defaultValue); if (s == null || s.trim().isEmpty()) { reportGauge(0, new MetricName("config", "", key)); } else { reportGauge(1, new TaggedMetricName("config", key, "value", converter == null ? s : converter.apply(s))); } return s; }
public String getString(String key, String defaultValue, @Nullable Function<String, String> converter) { String s = prop.getProperty(key, defaultValue); if (s == null || s.trim().isEmpty()) { reportGauge(0, new MetricName("config", "", key)); } else { reportGauge(1, new TaggedMetricName("config", key, "value", converter == null ? s : converter.apply(s))); } return s; }
/** * Constructor. * * @param pointLineWhiteListRegex the white list regular expression. * @param pointLineBlackListRegex the black list regular expression * @param portName the port used as metric name (validationRegex.point-rejected [port=portName]) */ public MetricWhiteBlackList(@Nullable final String pointLineWhiteListRegex, @Nullable final String pointLineBlackListRegex, final String portName) { if (!StringUtils.isBlank(pointLineWhiteListRegex)) { this.pointLineWhiteList = Pattern.compile(pointLineWhiteListRegex); } else { this.pointLineWhiteList = null; } if (!StringUtils.isBlank(pointLineBlackListRegex)) { this.pointLineBlackList = Pattern.compile(pointLineBlackListRegex); } else { this.pointLineBlackList = null; } this.regexRejects = Metrics.newCounter( new TaggedMetricName("validationRegex", "points-rejected", "port", portName)); }
public RawLogsIngester(LogsIngester logsIngester, int port, Supplier<Long> now) { this.logsIngester = logsIngester; this.port = port; this.now = now; this.received = Metrics.newCounter(new MetricName("logsharvesting", "", "raw-received")); this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
public RawLogsIngester(LogsIngester logsIngester, int port, Supplier<Long> now) { this.logsIngester = logsIngester; this.port = port; this.now = now; this.received = Metrics.newCounter(new MetricName("logsharvesting", "", "raw-received")); this.connectionsAccepted = Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", String.valueOf(port))); this.connectionsIdleClosed = Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", String.valueOf(port))); }
/** * Constructor. * * @param pointLineWhiteListRegex the white list regular expression. * @param pointLineBlackListRegex the black list regular expression * @param portName the port used as metric name (validationRegex.point-rejected [port=portName]) */ public MetricWhiteBlackList(@Nullable final String pointLineWhiteListRegex, @Nullable final String pointLineBlackListRegex, final String portName) { if (!StringUtils.isBlank(pointLineWhiteListRegex)) { this.pointLineWhiteList = Pattern.compile(pointLineWhiteListRegex); } else { this.pointLineWhiteList = null; } if (!StringUtils.isBlank(pointLineBlackListRegex)) { this.pointLineBlackList = Pattern.compile(pointLineBlackListRegex); } else { this.pointLineBlackList = null; } this.regexRejects = Metrics.newCounter( new TaggedMetricName("validationRegex", "points-rejected", "port", portName)); }
/** * Create new instance. * * @param tokenAuthenticator tokenAuthenticator for incoming requests. * @param handle handle/port number. */ public PortUnificationHandler(@Nonnull TokenAuthenticator tokenAuthenticator, @Nullable final String handle, boolean plaintextEnabled, boolean httpEnabled) { this.tokenAuthenticator = tokenAuthenticator; this.handle = firstNonNull(handle, "unknown"); this.plaintextEnabled = plaintextEnabled; this.httpEnabled = httpEnabled; this.httpRequestHandleDuration = lazySupplier(() -> Metrics.newHistogram(new TaggedMetricName("listeners", "http-requests.duration-nanos", "port", this.handle))); this.requestsDiscarded = lazySupplier(() -> Metrics.newCounter(new TaggedMetricName("listeners", "http-requests.discarded", "port", this.handle))); this.pointsDiscarded = lazySupplier(() -> Metrics.newCounter(new TaggedMetricName("listeners", "items-discarded", "port", this.handle))); }
/** * Create new instance. * * @param tokenAuthenticator tokenAuthenticator for incoming requests. * @param handle handle/port number. */ public PortUnificationHandler(@Nonnull TokenAuthenticator tokenAuthenticator, @Nullable final String handle, boolean plaintextEnabled, boolean httpEnabled) { this.tokenAuthenticator = tokenAuthenticator; this.handle = firstNonNull(handle, "unknown"); this.plaintextEnabled = plaintextEnabled; this.httpEnabled = httpEnabled; this.httpRequestHandleDuration = lazySupplier(() -> Metrics.newHistogram(new TaggedMetricName("listeners", "http-requests.duration-nanos", "port", this.handle))); this.requestsDiscarded = lazySupplier(() -> Metrics.newCounter(new TaggedMetricName("listeners", "http-requests.discarded", "port", this.handle))); this.pointsDiscarded = lazySupplier(() -> Metrics.newCounter(new TaggedMetricName("listeners", "items-discarded", "port", this.handle))); }
@VisibleForTesting protected DataDogPortUnificationHandler(final String handle, final ReportableEntityHandler<ReportPoint> pointHandler, final boolean processSystemMetrics, final boolean processServiceChecks, @Nullable final HttpClient requestRelayClient, @Nullable final String requestRelayTarget, @Nullable final ReportableEntityPreprocessor preprocessor) { super(TokenAuthenticatorBuilder.create().setTokenValidationMethod(TokenValidationMethod.NONE).build(), handle, false, true); this.pointHandler = pointHandler; this.processSystemMetrics = processSystemMetrics; this.processServiceChecks = processServiceChecks; this.requestRelayClient = requestRelayClient; this.requestRelayTarget = requestRelayTarget; this.preprocessor = preprocessor; this.jsonParser = new ObjectMapper(); this.httpRequestSize = Metrics.newHistogram(new TaggedMetricName("listeners", "http-requests.payload-points", "port", handle)); Metrics.newGauge(new TaggedMetricName("listeners", "tags-cache-size", "port", handle), new Gauge<Long>() { @Override public Long value() { return tagsCache.estimatedSize(); } }); }
@VisibleForTesting protected DataDogPortUnificationHandler(final String handle, final ReportableEntityHandler<ReportPoint> pointHandler, final boolean processSystemMetrics, final boolean processServiceChecks, @Nullable final HttpClient requestRelayClient, @Nullable final String requestRelayTarget, @Nullable final ReportableEntityPreprocessor preprocessor) { super(TokenAuthenticatorBuilder.create().setTokenValidationMethod(TokenValidationMethod.NONE).build(), handle, false, true); this.pointHandler = pointHandler; this.processSystemMetrics = processSystemMetrics; this.processServiceChecks = processServiceChecks; this.requestRelayClient = requestRelayClient; this.requestRelayTarget = requestRelayTarget; this.preprocessor = preprocessor; this.jsonParser = new ObjectMapper(); this.httpRequestSize = Metrics.newHistogram(new TaggedMetricName("listeners", "http-requests.payload-points", "port", handle)); Metrics.newGauge(new TaggedMetricName("listeners", "tags-cache-size", "port", handle), new Gauge<Long>() { @Override public Long value() { return tagsCache.estimatedSize(); } }); }
public static void main(String[] args) throws IOException, InterruptedException { // Parse inputs. System.out.println("Args: " + Joiner.on(", ").join(args)); if (args.length != 2) { System.out.println("Usage: java -jar this.jar <metricsPort> <histogramsPort>"); return; } int port = Integer.parseInt(args[0]); int histoPort = Integer.parseInt(args[1]); // Set up periodic reporting. MetricsRegistry metricsRegistry = new MetricsRegistry(); WavefrontYammerMetricsReporter wavefrontYammerMetricsReporter = new WavefrontYammerMetricsReporter(metricsRegistry, "wavefrontYammerMetrics", "localhost", port, histoPort, System::currentTimeMillis); wavefrontYammerMetricsReporter.start(5, TimeUnit.SECONDS); // Populate test metrics. Counter counter = metricsRegistry.newCounter(new TaggedMetricName("group", "mycounter", "tag1", "value1")); Histogram histogram = metricsRegistry.newHistogram(new TaggedMetricName("group2", "myhisto"), false); WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group", "mywavefronthisto", "tag2", "value2")); while (true) { counter.inc(); histogram.update(counter.count()); wavefrontHistogram.update(counter.count()); Thread.sleep(1000); } }
/** * Base constructor. * * @param entityType entity type that dictates the data processing flow. * @param handle handle (usually port number), that serves as an identifier for the metrics pipeline. * @param threadId thread number * @param itemsPerBatch max points per flush. * @param memoryBufferLimit max points in task's memory buffer before queueing. */ AbstractSenderTask(String entityType, String handle, int threadId, @Nullable final AtomicInteger itemsPerBatch, @Nullable final AtomicInteger memoryBufferLimit) { this.entityType = entityType; this.handle = handle; this.threadId = threadId; this.itemsPerBatch = itemsPerBatch == null ? new AtomicInteger(40000) : itemsPerBatch; this.memoryBufferLimit = memoryBufferLimit == null ? new AtomicInteger(32 * 40000) : memoryBufferLimit; this.scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("submitter-" + entityType + "-" + handle + "-" + String.valueOf(threadId))); this.flushExecutor = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.MINUTES, new SynchronousQueue<>(), new NamedThreadFactory("flush-" + entityType + "-" + handle + "-" + String.valueOf(threadId))); this.attemptedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "sent")); this.queuedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "queued")); this.blockedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "blocked")); this.receivedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "received")); this.bufferFlushCounter = Metrics.newCounter(new TaggedMetricName("buffer", "flush-count", "port", handle)); }
/** * Base constructor. * * @param entityType entity type that dictates the data processing flow. * @param handle handle (usually port number), that serves as an identifier for the metrics pipeline. * @param threadId thread number * @param itemsPerBatch max points per flush. * @param memoryBufferLimit max points in task's memory buffer before queueing. */ AbstractSenderTask(String entityType, String handle, int threadId, @Nullable final AtomicInteger itemsPerBatch, @Nullable final AtomicInteger memoryBufferLimit) { this.entityType = entityType; this.handle = handle; this.threadId = threadId; this.itemsPerBatch = itemsPerBatch == null ? new AtomicInteger(40000) : itemsPerBatch; this.memoryBufferLimit = memoryBufferLimit == null ? new AtomicInteger(32 * 40000) : memoryBufferLimit; this.scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("submitter-" + entityType + "-" + handle + "-" + String.valueOf(threadId))); this.flushExecutor = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.MINUTES, new SynchronousQueue<>(), new NamedThreadFactory("flush-" + entityType + "-" + handle + "-" + String.valueOf(threadId))); this.attemptedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "sent")); this.queuedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "queued")); this.blockedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "blocked")); this.receivedCounter = Metrics.newCounter(new MetricName(entityType + "." + handle, "", "received")); this.bufferFlushCounter = Metrics.newCounter(new TaggedMetricName("buffer", "flush-count", "port", handle)); }
@Override public void processTimer(MetricName name, Timer timer, Void context) throws Exception { MetricName samplingName, rateName; if (name instanceof TaggedMetricName) { TaggedMetricName taggedMetricName = (TaggedMetricName) name; samplingName = new TaggedMetricName( taggedMetricName.getGroup(), taggedMetricName.getName() + ".duration", taggedMetricName.getTags()); rateName = new TaggedMetricName( taggedMetricName.getGroup(), taggedMetricName.getName() + ".rate", taggedMetricName.getTags()); } else { samplingName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".duration"); rateName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".rate"); } writeSummarizable(samplingName, timer); writeSampling(samplingName, timer); writeMetered(rateName, timer); if (clear) timer.clear(); }