Java Code Examples for com.signalfx.codahale.reporter.SignalFxReporter#getMetricMetadata()

The following examples show how to use com.signalfx.codahale.reporter.SignalFxReporter#getMetricMetadata() . 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: SignalFxEndpointMetricsHandler.java    From riposte with Apache License 2.0 4 votes vote down vote up
protected static MetricMetadata extractMetricMetadataFromSignalFxReporter(SignalFxReporter reporter) {
    if (reporter  == null)
        throw new IllegalArgumentException("SignalFxReporter cannot be null");

    return reporter.getMetricMetadata();
}
 
Example 2
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 3
Source File: SignalFxReporterTest.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
private void testReporterWithDetails(){
	
	StoredDataPointReceiver dbank = new StoredDataPointReceiver();
       assertEquals(0, dbank.addDataPoints.size());

       Set<SignalFxReporter.MetricDetails> detailsToAdd = new HashSet<SignalFxReporter.MetricDetails>();
       detailsToAdd.add(SignalFxReporter.MetricDetails.STD_DEV);
       detailsToAdd.add(SignalFxReporter.MetricDetails.MEAN);
       
       MetricsRegistry metricRegistery = new MetricsRegistry();
       SignalFxReporter reporter = new SignalFxReporter.Builder(metricRegistery, new StaticAuthToken(""), "myserver")
               .setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank))
               .setDetailsToAdd(
           		ImmutableSet.of(
       				SignalFxReporter.MetricDetails.COUNT,
       				SignalFxReporter.MetricDetails.MIN, 
       				SignalFxReporter.MetricDetails.MAX
           		)
               )
               .setName("testReporter")
               .setDefaultSourceName("defaultSource")
               .useLocalTime(false)
               .setOnSendErrorHandlerCollection(
               		Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler(){
                       	public void handleError(MetricError error){
                       		System.out.println("" + error.getMessage());
                       	}
                       })
               )
               .setFilter(MetricPredicate.ALL)
               .setRateUnit(TimeUnit.SECONDS)
               .setDetailsToAdd(detailsToAdd)
               .build();
       
       final MetricMetadata metricMetadata = reporter.getMetricMetadata();
       
       MetricName histogramName = new MetricName("group1", "type1", "histogram");
       Histogram histogram = metricRegistery.newHistogram(histogramName, true);
       histogram.update(10);
       histogram.update(14);
       histogram.update(7);
       
       metricMetadata.forMetric(histogram)
       	.withMetricName("histogram")
       	.withSourceName("histogram_source")
       	.withMetricType(SignalFxProtocolBuffers.MetricType.GAUGE)
       	.withDimension("key", "value");
       
       reporter.report();
       
       assertEquals(2, dbank.addDataPoints.size());
	
}