static StatsDEmitter of(StatsDEmitterConfig config, ObjectMapper mapper) { NonBlockingStatsDClient client = new NonBlockingStatsDClient( config.getPrefix(), config.getHostname(), config.getPort(), config.isDogstatsd() ? config.getDogstatsdConstantTags().toArray(new String[0]) : EMPTY_ARRAY, new StatsDClientErrorHandler() { private int exceptionCount = 0; @Override public void handle(Exception exception) { if (exceptionCount % 1000 == 0) { log.error(exception, "Error sending metric to StatsD."); } exceptionCount += 1; } } ); return new StatsDEmitter(config, mapper, client); }
tagArray[i++] = e.getKey() + ':' + e.getValue(); mStatsDClient.recordGaugeValue(metricName, value, tagArray); } else { StringBuilder builder = new StringBuilder(); .append(tags.get(Stat.STAT_KEYS.PARTITION.getName())) .toString(); mStatsDClient.recordGaugeValue(metricName, value);
/** * {@inheritDoc} */ @Override public void recordDistributionValue(final String aspect, final double value, final double sampleRate, final String... tags) { if(isInvalidSample(sampleRate)) { return; } /* Intentionally using %s rather than %f here to avoid * padding with extra 0s to represent precision */ send(new StringBuilder(prefix).append(aspect).append(":").append(NUMBER_FORMATTERS.get().format(value)).append("|d|@").append(SAMPLE_RATE_FORMATTERS.get().format(sampleRate)).append(tagString(tags)).toString()); }
/** * Records the latest fixed value for the specified named gauge. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the gauge * @param value * the new reading of the gauge * @param tags * array of tags to be added to the data */ @Override public void recordGaugeValue(final String aspect, final long value, final String... tags) { send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|g").append(tagString(tags)).toString()); }
/** * Records an event * * <p>This method is a DataDog extension, and may not work with other servers.</p> * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param event * The event to record * @param tags * array of tags to be added to the data * * @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events-1">http://docs.datadoghq.com/guides/dogstatsd/#events-1</a> */ @Override public void recordEvent(final Event event, final String... tags) { final String title = escapeEventString(prefix + event.getTitle()); final String text = escapeEventString(event.getText()); send(new StringBuilder("_e{").append(title.length()).append(",").append(text.length()).append("}:").append(title) .append("|").append(text).append(eventMap(event)).append(tagString(tags)).toString()); }
/** * StatsD supports counting unique occurrences of events between flushes, Call this method to records an occurrence * of the specified named event. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the set * @param eventName * the value to be added to the set */ @Override public void recordSetEvent(String aspect, String eventName) { send(messageFor(aspect, eventName, "s")); }
/** * Records a run status for the specified named service check. * * <p>This method is a DataDog extension, and may not work with other servers.</p> * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param sc * the service check object */ @Override public void recordServiceCheckRun(final ServiceCheck sc) { send(toStatsDString(sc)); }
static Callable<SocketAddress> staticAddressResolver(final String host, final int port) { try { return NonBlockingStatsDClient.staticAddressResolution(host, port); } catch(final Exception e) { LOG.error("Error during constructing statsd address resolver.", e); throw new RuntimeException(e); } }
/** * {@inheritDoc} */ @Override public void recordExecutionTime(final String aspect, final long timeInMs, final double sampleRate, final String... tags) { if(isInvalidSample(sampleRate)) { return; } send(new StringBuilder(prefix).append(aspect).append(":").append(timeInMs).append("|ms|@").append(SAMPLE_RATE_FORMATTERS.get().format(sampleRate)).append(tagString(tags)).toString()); }
/** * Records a value for the specified named histogram. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the histogram * @param value * the value to be incorporated in the histogram * @param tags * array of tags to be added to the data */ @Override public void recordHistogramValue(final String aspect, final long value, final String... tags) { send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|h").append(tagString(tags)).toString()); }
/** * Records an event * * <p>This method is a DataDog extension, and may not work with other servers.</p> * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param event * The event to record * @param tags * array of tags to be added to the data * * @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events-1">http://docs.datadoghq.com/guides/dogstatsd/#events-1</a> */ @Override public void recordEvent(final Event event, final String... tags) { final String title = escapeEventString(prefix + event.getTitle()); final String text = escapeEventString(event.getText()); send(new StringBuilder("_e{").append(title.length()).append(",").append(text.length()).append("}:").append(title) .append("|").append(text).append(eventMap(event)).append(tagString(tags)).toString()); }
/** * Records an execution time in milliseconds for the specified named operation. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the timed operation * @param timeInMs * the time in milliseconds */ @Override public void recordExecutionTime(String aspect, long timeInMs, double sampleRate) { send(messageFor(aspect, Long.toString(timeInMs), "ms", sampleRate)); }
/** * Records a run status for the specified named service check. * * <p>This method is a DataDog extension, and may not work with other servers.</p> * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param sc * the service check object */ @Override public void recordServiceCheckRun(final ServiceCheck sc) { send(toStatsDString(sc)); }
private static Callable<SocketAddress> staticStatsDAddressResolution(final String hostname, final int port) throws StatsDClientException { try { return staticAddressResolution(hostname, port); } catch (final Exception e) { throw new StatsDClientException("Failed to lookup StatsD host", e); } } }
public StatsdMetricsReporterService(Map<String, Object> props, String name) { StatsdMetricsReporterServiceConfig config = new StatsdMetricsReporterServiceConfig(props); _name = name; _metricNames = config.getList(StatsdMetricsReporterServiceConfig.REPORT_METRICS_CONFIG); _reportIntervalSec = config.getInt(StatsdMetricsReporterServiceConfig.REPORT_INTERVAL_SEC_CONFIG); _executor = Executors.newSingleThreadScheduledExecutor(); _statsdClient = new NonBlockingStatsDClient(config.getString(StatsdMetricsReporterServiceConfig.REPORT_STATSD_PREFIX), config.getString(StatsdMetricsReporterServiceConfig.REPORT_STATSD_HOST), config.getInt(StatsdMetricsReporterServiceConfig.REPORT_STATSD_PORT)); }
/** * {@inheritDoc} */ @Override public void count(final String aspect, final long delta, final double sampleRate, final String...tags) { if(isInvalidSample(sampleRate)) { return; } send(new StringBuilder(prefix).append(aspect).append(":").append(delta).append("|c|@").append(SAMPLE_RATE_FORMATTERS.get().format(sampleRate)).append(tagString(tags)).toString()); }
/** * Records the latest fixed value for the specified named gauge. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the gauge * @param value * the new reading of the gauge * @param tags * array of tags to be added to the data */ @Override public void recordGaugeValue(final String aspect, final long value, final String... tags) { send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|g").append(tagString(tags)).toString()); }
/** * {@inheritDoc} */ @Override public void gauge(final String aspect, final long value, final double sampleRate, final String... tags) { recordGaugeValue(aspect, value, sampleRate, tags); }
/** * Adjusts the specified counter by a given delta. * * <p>This method is non-blocking and is guaranteed not to throw an exception.</p> * * @param aspect * the name of the counter to adjust * @param delta * the amount to adjust the counter by * @param sampleRate * the sampling rate being employed. For example, a rate of 0.1 would tell StatsD that this counter is being sent * sampled every 1/10th of the time. */ @Override public void count(String aspect, long delta, double sampleRate) { send(messageFor(aspect, Long.toString(delta), "c", sampleRate)); }
private static Callable<SocketAddress> staticStatsDAddressResolution(final String hostname, final int port) throws StatsDClientException { try { return staticAddressResolution(hostname, port); } catch (final Exception e) { throw new StatsDClientException("Failed to lookup StatsD host", e); } } }