com.signalfx.endpoint.SignalFxEndpoint Java Examples

The following examples show how to use com.signalfx.endpoint.SignalFxEndpoint. 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: HttpDataPointProtobufReceiverConnectionTest.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBackfill() throws Exception {
    Server server = new Server(0);
    server.setHandler(new BackfillHandler());
    server.start();
    URI uri = server.getURI();
    DataPointReceiver dpr = new HttpDataPointProtobufReceiverFactory(
            new SignalFxEndpoint(uri.getScheme(), uri.getHost(), uri.getPort()))
            .createDataPointReceiver();

    ArrayList<SignalFxProtocolBuffers.PointValue> values = new ArrayList<SignalFxProtocolBuffers.PointValue>(Arrays.asList(
            SignalFxProtocolBuffers.PointValue.newBuilder().setTimestamp(System.currentTimeMillis())
                    .setValue(SignalFxProtocolBuffers.Datum.newBuilder().setDoubleValue(123.0)).build()
    ));
    HashMap<String,String> dims = new HashMap<String,String>();
    dims.put("baz", "gorch");
    dims.put("moo", "cow");

    dpr.backfillDataPoints(AUTH_TOKEN, "foo.bar.baz", "counter", "ABC123", dims, values);
    server.stop();
}
 
Example #3
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 #4
Source File: ServerSentEventsTransport.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
protected ServerSentEventsTransport(String token, final SignalFxEndpoint endpoint,
                                    final int apiVersion, final Integer timeout) {
    this.token = token;
    this.endpoint = endpoint;
    this.path = "/v" + apiVersion + "/signalflow";
    this.timeout = timeout;
}
 
Example #5
Source File: ServerSentEventsTransport.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public TransportConnection(SignalFxEndpoint endpoint, int timeoutMs) {
    super(endpoint, timeoutMs, new BasicHttpClientConnectionManager());

    this.transportRequestConfig = RequestConfig.custom().setSocketTimeout(0)
            .setConnectionRequestTimeout(this.requestConfig.getConnectionRequestTimeout())
            .setConnectTimeout(this.requestConfig.getConnectTimeout())
            .setProxy(this.requestConfig.getProxy()).build();

    log.debug("constructed request config: {}", this.transportRequestConfig.toString());
}
 
Example #6
Source File: WebSocketTransport.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
protected WebSocketTransport(String token, SignalFxEndpoint endpoint, int apiVersion,
                             int timeout, boolean compress, int maxBinaryMessageSize) {
    this.token = token;
    this.endpoint = endpoint;
    this.path = "/v" + apiVersion + "/signalflow/connect";
    this.timeout = timeout;
    this.compress = compress;

    try {
        this.transportConnection = new TransportConnection(token);
        URI uri = new URIBuilder(String.format("%s://%s:%s%s", endpoint.getScheme(),
                endpoint.getHostname(), endpoint.getPort(), path)).build();

        this.webSocketClient = new WebSocketClient(new SslContextFactory());
        if (maxBinaryMessageSize > 0) {
            this.webSocketClient.getPolicy().setMaxBinaryMessageSize(maxBinaryMessageSize);
        }
        if (timeout > 0) {
            this.webSocketClient.setConnectTimeout(TimeUnit.SECONDS.toMillis(timeout));
        }
        this.webSocketClient.start();
        this.webSocketClient.connect(this.transportConnection, uri);
        this.transportConnection.awaitConnected(timeout, TimeUnit.SECONDS);
    } catch (Exception ex) {
        if (this.webSocketClient != null) {
            try {
                this.webSocketClient.stop();
            } catch (Exception e) {
                log.warn("error closing websocket client", e);
            }
        }
        throw new SignalFlowException("failed to construct websocket transport", ex);
    }
}
 
Example #7
Source File: HttpDataPointProtobufReceiverConnectionTest.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpConnection() throws Exception {
    Server server = new Server(0);
    server.setHandler(new AddPointsHandler());
    server.start();
    URI uri = server.getURI();
    DataPointReceiver dpr = new HttpDataPointProtobufReceiverFactory(
            new SignalFxEndpoint(uri.getScheme(), uri.getHost(), uri.getPort()))
            .createDataPointReceiver();
    dpr.addDataPoints(AUTH_TOKEN, Collections.singletonList(
            SignalFxProtocolBuffers.DataPoint.newBuilder().setSource("source").build()));
    server.stop();
}
 
Example #8
Source File: SignalFxMetricsReporterService.java    From kafka-monitor with Apache License 2.0 4 votes vote down vote up
private SignalFxEndpoint getSignalFxEndpoint(String urlStr) throws Exception {
  URL url = new URL(urlStr);
  return new SignalFxEndpoint(url.getProtocol(), url.getHost(), url.getPort());
}
 
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: YammerExample.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        System.out.println("Running example...");

        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 endpoint = new SignalFxEndpoint(hostUrl.getProtocol(),
                hostUrl.getHost(), hostUrl.getPort());

        MetricsRegistry metricsRegistry = new MetricsRegistry();
        SignalFxReporter reporter = new SignalFxReporter.Builder(metricsRegistry,
                new StaticAuthToken(auth_token),
                hostUrlStr).setEndpoint(endpoint)
                .setOnSendErrorHandlerCollection(
                        Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler() {
                            public void handleError(MetricError error) {
                                System.out.println("" + error.getMessage());
                            }
                        }))
                .setDetailsToAdd(ImmutableSet.of(SignalFxReporter.MetricDetails.COUNT,
                        SignalFxReporter.MetricDetails.MIN,
                        SignalFxReporter.MetricDetails.MAX))
                .build();

        final MetricMetadata metricMetadata = reporter.getMetricMetadata();

        Counter counter = getCounter(metricsRegistry, metricMetadata);

        Metric cumulativeCounter = getCumulativeCounter(metricsRegistry, metricMetadata);

        Gauge gauge1 = getGauge(metricsRegistry, metricMetadata);

        Timer timer = getTimer(metricsRegistry, metricMetadata);

        // main body generating data and sending it in a loop
        while (true) {
            final TimerContext context = timer.time();
            try {
                System.out.println("Sending data...");
                Thread.sleep(500);
                counter.inc();
            } finally {
                context.stop();
            }
            reporter.report(); // Report all metrics
        }

    }
 
Example #11
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 #12
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();
        }
    }
}
 
Example #13
Source File: ServerSentEventsTransport.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
public ServerSentEventsTransport build() {
    SignalFxEndpoint endpoint = new SignalFxEndpoint(this.protocol, this.host, this.port);
    ServerSentEventsTransport transport = new ServerSentEventsTransport(this.token,
            endpoint, this.version, this.timeout * 1000);
    return transport;
}
 
Example #14
Source File: ServerSentEventsTransport.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
public TransportConnection(SignalFxEndpoint endpoint) {
    this(endpoint, DEFAULT_TIMEOUT_MS);
}
 
Example #15
Source File: WebSocketTransport.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
public WebSocketTransport build() {
    SignalFxEndpoint endpoint = new SignalFxEndpoint(this.protocol, this.host, this.port);
    WebSocketTransport transport = new WebSocketTransport(this.token, endpoint,
            this.version, this.timeout, this.compress, this.maxBinaryMessageSize);
    return transport;
}