com.signalfx.metrics.flush.AggregateMetricSender Java Examples
The following examples show how to use
com.signalfx.metrics.flush.AggregateMetricSender.
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: SignalFxMetricExporterTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { endpoint = new URI("http://example.com"); Mockito.when( factory.create( Mockito.any(URI.class), Mockito.anyString(), Mockito.any(OnSendErrorHandler.class))) .thenAnswer( new Answer<AggregateMetricSender>() { @Override public AggregateMetricSender answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); AggregateMetricSender sender = SignalFxMetricsSenderFactory.DEFAULT.create( (URI) args[0], (String) args[1], (OnSendErrorHandler) args[2]); AggregateMetricSender spy = Mockito.spy(sender); doReturn(session).when(spy).createSession(); return spy; } }); }
Example #2
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 6 votes |
AggregateMetricSenderSessionWrapper( AggregateMetricSender.Session metricSenderSession, Set<SignalFxReporter.MetricDetails> detailsToAdd, MetricMetadata metricMetadata, String defaultSourceName, String sourceDimension, boolean injectCurrentTimestamp, Map<String, DimensionInclusion> defaultDimensions) { this.metricSenderSession = metricSenderSession; this.detailsToAdd = detailsToAdd; this.metricMetadata = metricMetadata; this.defaultSourceName = defaultSourceName; this.sourceDimension = sourceDimension; this.injectCurrentTimestamp = injectCurrentTimestamp; this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions); }
Example #3
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 6 votes |
AggregateMetricSenderSessionWrapper( AggregateMetricSender.Session metricSenderSession, Set<SignalFxReporter.MetricDetails> detailsToAdd, MetricMetadata metricMetadata, String defaultSourceName, String sourceDimension, boolean injectCurrentTimestamp, boolean sendExtraMetricDimensions, ImmutableMap<String, String> defaultDimensions) { this.metricSenderSession = metricSenderSession; this.detailsToAdd = detailsToAdd; this.metricMetadata = metricMetadata; this.defaultSourceName = defaultSourceName; this.sourceDimension = sourceDimension; this.injectCurrentTimestamp = injectCurrentTimestamp; this.sendExtraMetricDimensions = sendExtraMetricDimensions; this.defaultDimensions = defaultDimensions; }
Example #4
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
public SignalFxReporter build() { AggregateMetricSender aggregateMetricSender = new AggregateMetricSender( defaultSourceName, dataPointReceiverFactory, authToken, onSendErrorHandlerCollection); return new SignalFxReporter(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd, metricMetadata, useLocalTime, defaultDimensions.build()); }
Example #5
Source File: SignalFxMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
@Override protected void publish() { final long timestamp = clock.wallTime(); AggregateMetricSender metricSender = new AggregateMetricSender(this.config.source(), this.dataPointReceiverFactory, this.eventReceiverFactory, new StaticAuthToken(this.config.accessToken()), this.onSendErrorHandlerCollection); for (List<Meter> batch : MeterPartition.partition(this, config.batchSize())) { try (AggregateMetricSender.Session session = metricSender.createSession()) { batch.stream() .map(meter -> meter.match( this::addGauge, this::addCounter, this::addTimer, this::addDistributionSummary, this::addLongTaskTimer, this::addTimeGauge, this::addFunctionCounter, this::addFunctionTimer, this::addMeter)) .flatMap(builders -> builders.map(builder -> builder.setTimestamp(timestamp).build())) .forEach(session::setDatapoint); logger.debug("successfully sent {} metrics to SignalFx.", batch.size()); } catch (Throwable e) { logger.warn("failed to send metrics", e); } } }
Example #6
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
public SignalFxReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata, boolean useLocalTime, Map<String, DimensionInclusion> defaultDimensions) { super(registry, name, filter, rateUnit, durationUnit); this.aggregateMetricSender = aggregateMetricSender; this.useLocalTime = useLocalTime; this.detailsToAdd = detailsToAdd; this.metricMetadata = metricMetadata; this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions); }
Example #7
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
protected SignalFxReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata) { this(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd, metricMetadata, false, Collections.<String, DimensionInclusion> emptyMap()); }
Example #8
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 5 votes |
AggregateMetricSenderSessionWrapper( AggregateMetricSender.Session metricSenderSession, Set<SignalFxReporter.MetricDetails> detailsToAdd, MetricMetadata metricMetadata, String defaultSourceName, String sourceDimension) { this(metricSenderSession, detailsToAdd, metricMetadata, defaultSourceName, sourceDimension, false, Collections.<String, DimensionInclusion> emptyMap()); }
Example #9
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
public SignalFxReporter build() { AggregateMetricSender aggregateMetricSender = new AggregateMetricSender( defaultSourceName, dataPointReceiverFactory, authToken, onSendErrorHandlerCollection); return new SignalFxReporter(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd, metricMetadata, useLocalTime, sendExtraMetricDimensions, defaultDimensions.build()); }
Example #10
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
public SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata, boolean useLocalTime, boolean sendExtraMetricDimensions, Map<String, String> defaultDimensions) { super(registry, name, filter, rateUnit, durationUnit); this.aggregateMetricSender = aggregateMetricSender; this.useLocalTime = useLocalTime; this.detailsToAdd = detailsToAdd; this.metricMetadata = metricMetadata; this.sendExtraMetricDimensions = sendExtraMetricDimensions; this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions); }
Example #11
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
protected SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata) { this(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd, metricMetadata, false, false, Collections.<String, String> emptyMap()); }
Example #12
Source File: SignalFxMetricsSenderFactory.java From opencensus-java with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("nullness") public AggregateMetricSender create( URI endpoint, String token, OnSendErrorHandler errorHandler) { SignalFxEndpoint sfx = new SignalFxEndpoint(endpoint.getScheme(), endpoint.getHost(), endpoint.getPort()); return new AggregateMetricSender( null, new HttpDataPointProtobufReceiverFactory(sfx).setVersion(2), new HttpEventProtobufReceiverFactory(sfx), new StaticAuthToken(token), Collections.singleton(errorHandler)); }
Example #13
Source File: SendMetrics.java From signalfx-java with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.load(new FileInputStream("auth.properties")); String token = Preconditions.checkNotNull(prop.getProperty("auth"), "No auth token set"); String host = Preconditions.checkNotNull(prop.getProperty("host"), "No endpoint set"); URL hostUrl = new URL(host); System.out.printf("Sending metrics to %s (X-SF-Token: %s) ...%n", hostUrl, token); SignalFxReceiverEndpoint endpoint = new SignalFxEndpoint( hostUrl.getProtocol(), hostUrl.getHost(), hostUrl.getPort()); OnSendErrorHandler errorHandler = new OnSendErrorHandler() { @Override public void handleError(MetricError metricError) { System.err.printf("Error %s sending data: %s%n", metricError.getMetricErrorType(), metricError.getMessage()); metricError.getException().printStackTrace(System.err); } }; AggregateMetricSender mf = new AggregateMetricSender( "test.SendMetrics", new HttpDataPointProtobufReceiverFactory(endpoint).setVersion(2), new StaticAuthToken(token), Collections.singletonList(errorHandler)); while (true) { Thread.sleep(250); AggregateMetricSender.Session i = mf.createSession(); try { i.setDatapoint(SignalFxProtocolBuffers.DataPoint.newBuilder() .setMetric("curtime") .setValue(SignalFxProtocolBuffers.Datum.newBuilder() .setIntValue(System.currentTimeMillis())) .addDimensions( SignalFxProtocolBuffers.Dimension.newBuilder() .setKey("source") .setValue("java")).build()); } finally { System.out.printf("Sending data at %s%n", new Date()); i.close(); } } }
Example #14
Source File: ProtobufExample.java From signalfx-java with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.load(new FileInputStream("auth.properties")); final String auth_token = prop.getProperty("auth"); final String hostUrlStr = prop.getProperty("host"); final URL hostUrl = new URL(hostUrlStr); System.out.println("Auth=" + auth_token + " .. host=" + hostUrl); SignalFxReceiverEndpoint signalFxEndpoint = new SignalFxEndpoint(hostUrl.getProtocol(), hostUrl.getHost(), hostUrl.getPort()); AggregateMetricSender mf = new AggregateMetricSender("test.SendMetrics", new HttpDataPointProtobufReceiverFactory(signalFxEndpoint).setVersion(2), new HttpEventProtobufReceiverFactory(signalFxEndpoint), new StaticAuthToken(auth_token), Collections.<OnSendErrorHandler> singleton(new OnSendErrorHandler() { @Override public void handleError(MetricError metricError) { System.out.println("Unable to POST metrics: " + metricError.getMessage()); } })); int j = 0; while(true) { // session should be recreated after every sessionObj.close(). AggregateMetricSender.Session i = mf.createSession(); System.out.println("Setting datapoint " + (j)); i.setDatapoint( SignalFxProtocolBuffers.DataPoint.newBuilder() .setMetric("test.cpu") .setMetricType(SignalFxProtocolBuffers.MetricType.GAUGE) .setValue( SignalFxProtocolBuffers.Datum.newBuilder() .setIntValue(j%3)) .addDimensions(getDimensionAsProtobuf("host", "myhost")) .addDimensions(getDimensionAsProtobuf("service", "myservice")) .build()); if(j%3 == 0){ System.out.println("Setting Event " + j/3); i.setEvent( SignalFxProtocolBuffers.Event.newBuilder() .setEventType("Deployments") .setCategory(SignalFxProtocolBuffers.EventCategory.USER_DEFINED) .setTimestamp(System.currentTimeMillis()) .addDimensions(getDimensionAsProtobuf("host", "myhost")) .addDimensions(getDimensionAsProtobuf("service", "myservice")) .addProperties(getPropertyAsProtobuf("version", j/3)) .build()); } System.out.println("Flushing set datapoints and events"); i.close(); // close session resource to flush the set datapoints and events j++; Thread.sleep(500); } }
Example #15
Source File: SignalFxOutputPlugin.java From ffwd with Apache License 2.0 | 4 votes |
@Override public Module module(final Key<PluginSink> key, final String id) { return new OutputPluginModule(id) { @Provides Supplier<AggregateMetricSender> sender() { final Collection<OnSendErrorHandler> handlers = ImmutableList.of(metricError -> { log.error(metricError.toString()); }); return () -> { final SignalFxEndpoint endpoint = new SignalFxEndpoint(); final HttpDataPointProtobufReceiverFactory dataPoints = new HttpDataPointProtobufReceiverFactory(endpoint).setVersion(2); BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(); SocketConfig socketConfigWithSoTimeout = SocketConfig .copy(connectionManager.getSocketConfig()) .setSoTimeout(soTimeout) .build(); connectionManager.setSocketConfig(socketConfigWithSoTimeout); dataPoints.setHttpClientConnectionManager(connectionManager); final EventReceiverFactory events = new HttpEventProtobufReceiverFactory(endpoint); final AuthToken auth = new StaticAuthToken(authToken); return new AggregateMetricSender(sourceName, dataPoints, events, auth, handlers); }; } @Override protected void configure() { final Key<SignalFxPluginSink> sinkKey = Key.get(SignalFxPluginSink.class, Names.named("signalfxSink")); bind(sinkKey).to(SignalFxPluginSink.class).in(Scopes.SINGLETON); install(wrapPluginSink(sinkKey, key)); expose(key); } }; }
Example #16
Source File: SignalFxPluginSink.java From ffwd with Apache License 2.0 | 4 votes |
@Override public AsyncFuture<Void> sendMetrics(final Collection<Metric> metrics) { final AsyncFuture<Void> future = async.call(() -> { try (AggregateMetricSender.Session i = senderSupplier.get().createSession()) { for (Metric metric : metrics) { final SignalFxProtocolBuffers.DataPoint.Builder datapointBuilder = SignalFxProtocolBuffers.DataPoint .newBuilder() .setMetric(composeMetricIdentity(metric)) .setMetricType(getMetricType(metric)) .setValue(SignalFxProtocolBuffers.Datum .newBuilder() .setDoubleValue(metric.getValue())) .setTimestamp(metric.getTime().getTime()); metric .getTags() .entrySet() .stream() .map(attribute -> SignalFxProtocolBuffers.Dimension .newBuilder() .setKey(attribute.getKey()) .setValue(composeDimensionValue(attribute.getValue())) .build()) .forEach(datapointBuilder::addDimensions); metric .getResource() .entrySet() .stream() .map(attribute -> SignalFxProtocolBuffers.Dimension .newBuilder() .setKey(attribute.getKey()) .setValue(composeDimensionValue(attribute.getValue())) .build()) .forEach(datapointBuilder::addDimensions); // TODO: Why is this here? When we loop above all the tags above. final String host = metric.getTags().get("host"); if (host != null) { datapointBuilder.addDimensions(SignalFxProtocolBuffers.Dimension .newBuilder() .setKey("host") .setValue(host) .build()); } final SignalFxProtocolBuffers.DataPoint dataPoint = datapointBuilder.build(); i.setDatapoint(dataPoint); } } return null; }, executorService); future.on((FutureFailed) throwable -> log.error("Failed to send metrics", throwable)); return future; }
Example #17
Source File: SignalFxMetricsSenderFactory.java From opencensus-java with Apache License 2.0 | 2 votes |
/** * Creates a new SignalFx metrics sender instance. * * @param endpoint The SignalFx ingest endpoint URL. * @param token The SignalFx ingest token. * @param errorHandler An {@link OnSendErrorHandler} through which errors when sending data to * SignalFx will be communicated. * @return The created {@link AggregateMetricSender} instance. */ AggregateMetricSender create(URI endpoint, String token, OnSendErrorHandler errorHandler);