com.signalfx.metrics.connection.HttpDataPointProtobufReceiverFactory Java Examples

The following examples show how to use com.signalfx.metrics.connection.HttpDataPointProtobufReceiverFactory. 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: SignalFxMeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public SignalFxMeterRegistry(SignalFxConfig config, Clock clock, ThreadFactory threadFactory) {
    super(config, clock);
    this.config = config;

    URI apiUri = URI.create(config.uri());
    int port = apiUri.getPort();
    if (port == -1) {
        if ("http" .equals(apiUri.getScheme())) {
            port = 80;
        } else if ("https" .equals(apiUri.getScheme())) {
            port = 443;
        }
    }

    SignalFxReceiverEndpoint signalFxEndpoint = new SignalFxEndpoint(apiUri.getScheme(), apiUri.getHost(), port);
    this.dataPointReceiverFactory = new HttpDataPointProtobufReceiverFactory(signalFxEndpoint);
    this.eventReceiverFactory = new HttpEventProtobufReceiverFactory(signalFxEndpoint);

    config().namingConvention(new SignalFxNamingConvention());

    start(threadFactory);
}
 
Example #2
Source File: SignalFxMetricsSenderFactory.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setEndpoint(SignalFxReceiverEndpoint endpoint) {
    this.endpoint = endpoint;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setTimeoutMs(this.timeoutMs)
                    .setVersion(this.version);
    return this;
}
 
Example #4
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setTimeoutMs(int timeoutMs) {
    this.timeoutMs = timeoutMs;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setVersion(this.version)
                    .setTimeoutMs(this.timeoutMs);
    return this;
}
 
Example #5
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setVersion(int version) {
    this.version = version;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setVersion(this.version)
                    .setTimeoutMs(this.timeoutMs);
    return this;
}
 
Example #6
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setEndpoint(SignalFxReceiverEndpoint endpoint) {
    this.endpoint = endpoint;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setTimeoutMs(this.timeoutMs)
                    .setVersion(this.version);
    return this;
}
 
Example #7
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setTimeoutMs(int timeoutMs) {
    this.timeoutMs = timeoutMs;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setVersion(this.version)
                    .setTimeoutMs(this.timeoutMs);
    return this;
}
 
Example #8
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public Builder setVersion(int version) {
    this.version = version;
    this.dataPointReceiverFactory =
            new HttpDataPointProtobufReceiverFactory(endpoint)
                    .setVersion(this.version)
                    .setTimeoutMs(this.timeoutMs);
    return this;
}
 
Example #9
Source File: SignalFxOutputPlugin.java    From ffwd with Apache License 2.0 4 votes vote down vote up
@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 #10
Source File: ProtobufExample.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
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 #11
Source File: SendMetrics.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
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();
        }
    }
}