Search in sources :

Example 1 with Attributes

use of com.newrelic.telemetry.Attributes in project beneficiary-fhir-data by CMSgov.

the class PipelineApplication method main.

/**
 * This method is the one that will get called when users launch the application from the command
 * line.
 *
 * @param args (should be empty, as this application accepts configuration via environment
 *     variables)
 * @throws Exception any unhandled checked {@link Exception}s that are encountered will cause the
 *     application to halt
 */
public static void main(String[] args) throws Exception {
    LOGGER.info("Application starting up!");
    configureUnexpectedExceptionHandlers();
    AppConfiguration appConfig = null;
    try {
        appConfig = AppConfiguration.readConfigFromEnvironmentVariables();
        LOGGER.info("Application configured: '{}'", appConfig);
    } catch (AppConfigurationException e) {
        System.err.println(e.getMessage());
        LOGGER.warn("Invalid app configuration.", e);
        System.exit(EXIT_CODE_BAD_CONFIG);
    }
    MetricRegistry appMetrics = new MetricRegistry();
    appMetrics.registerAll(new MemoryUsageGaugeSet());
    appMetrics.registerAll(new GarbageCollectorMetricSet());
    Slf4jReporter appMetricsReporter = Slf4jReporter.forRegistry(appMetrics).outputTo(LOGGER).build();
    MetricOptions metricOptions = appConfig.getMetricOptions();
    if (metricOptions.getNewRelicMetricKey().isPresent()) {
        SenderConfiguration configuration = SenderConfiguration.builder(metricOptions.getNewRelicMetricHost().orElse(null), metricOptions.getNewRelicMetricPath().orElse(null)).httpPoster(new OkHttpPoster()).apiKey(metricOptions.getNewRelicMetricKey().orElse(null)).build();
        MetricBatchSender metricBatchSender = MetricBatchSender.create(configuration);
        Attributes commonAttributes = new Attributes().put("host", metricOptions.getHostname().orElse("unknown")).put("appName", metricOptions.getNewRelicAppName().orElse(null));
        NewRelicReporter newRelicReporter = NewRelicReporter.build(appMetrics, metricBatchSender).commonAttributes(commonAttributes).build();
        newRelicReporter.start(metricOptions.getNewRelicMetricPeriod().orElse(15), TimeUnit.SECONDS);
    }
    appMetricsReporter.start(1, TimeUnit.HOURS);
    /*
     * Create the PipelineManager that will be responsible for running and managing the various
     * jobs.
     */
    PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(appMetrics);
    PipelineManager pipelineManager = new PipelineManager(appMetrics, jobRecordStore);
    registerShutdownHook(appMetrics, pipelineManager);
    LOGGER.info("Job processing started.");
    // Create a pooled data source for use by the DatabaseSchemaUpdateJob.
    final HikariDataSource pooledDataSource = PipelineApplicationState.createPooledDataSource(appConfig.getDatabaseOptions(), appMetrics);
    /*
     * Register and wait for the database schema job to run, so that we don't have to worry about
     * declaring it as a dependency (since it is for pretty much everything right now).
     */
    pipelineManager.registerJob(new DatabaseSchemaUpdateJob(pooledDataSource));
    PipelineJobRecord<NullPipelineJobArguments> dbSchemaJobRecord = jobRecordStore.submitPendingJob(DatabaseSchemaUpdateJob.JOB_TYPE, null);
    try {
        jobRecordStore.waitForJobs(dbSchemaJobRecord);
    } catch (InterruptedException e) {
        pooledDataSource.close();
        throw new InterruptedException();
    }
    /*
     * Create and register the other jobs.
     */
    if (appConfig.getCcwRifLoadOptions().isPresent()) {
        // Create an application state that reuses the existing pooled data source with the ccw/rif
        // persistence unit.
        final PipelineApplicationState appState = new PipelineApplicationState(appMetrics, pooledDataSource, PipelineApplicationState.PERSISTENCE_UNIT_NAME, Clock.systemUTC());
        pipelineManager.registerJob(createCcwRifLoadJob(appConfig.getCcwRifLoadOptions().get(), appState));
        LOGGER.info("Registered CcwRifLoadJob.");
    } else {
        LOGGER.warn("CcwRifLoadJob is disabled in app configuration.");
    }
    if (appConfig.getRdaLoadOptions().isPresent()) {
        LOGGER.info("RDA API jobs are enabled in app configuration.");
        // Create an application state that reuses the existing pooled data source with the rda
        // persistence unit.
        final PipelineApplicationState rdaAppState = new PipelineApplicationState(appMetrics, pooledDataSource, PipelineApplicationState.RDA_PERSISTENCE_UNIT_NAME, Clock.systemUTC());
        final RdaLoadOptions rdaLoadOptions = appConfig.getRdaLoadOptions().get();
        final Optional<RdaServerJob> mockServerJob = rdaLoadOptions.createRdaServerJob();
        if (mockServerJob.isPresent()) {
            pipelineManager.registerJob(mockServerJob.get());
            LOGGER.warn("Registered RdaServerJob.");
        } else {
            LOGGER.info("Skipping RdaServerJob registration - not enabled in app configuration.");
        }
        pipelineManager.registerJob(rdaLoadOptions.createFissClaimsLoadJob(rdaAppState));
        LOGGER.info("Registered RdaFissClaimLoadJob.");
        pipelineManager.registerJob(rdaLoadOptions.createMcsClaimsLoadJob(rdaAppState));
        LOGGER.info("Registered RdaMcsClaimLoadJob.");
    } else {
        LOGGER.info("RDA API jobs are not enabled in app configuration.");
    }
/*
     * At this point, we're done here with the main thread. From now on, the PipelineManager's
     * executor service should be the only non-daemon thread running (and whatever it kicks off).
     * Once/if that thread stops, the application will run all registered shutdown hooks and Wait
     * for the PipelineManager to stop running jobs, and then check to see if we should exit
     * normally with 0 or abnormally with a non-0 because a job failed.
     */
}
Also used : RdaLoadOptions(gov.cms.bfd.pipeline.rda.grpc.RdaLoadOptions) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricRegistry(com.codahale.metrics.MetricRegistry) Attributes(com.newrelic.telemetry.Attributes) SenderConfiguration(com.newrelic.telemetry.SenderConfiguration) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) MetricBatchSender(com.newrelic.telemetry.metrics.MetricBatchSender) PipelineApplicationState(gov.cms.bfd.pipeline.sharedutils.PipelineApplicationState) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) NewRelicReporter(com.codahale.metrics.newrelic.NewRelicReporter) RdaServerJob(gov.cms.bfd.pipeline.rda.grpc.RdaServerJob) Slf4jReporter(com.codahale.metrics.Slf4jReporter) OkHttpPoster(com.newrelic.telemetry.OkHttpPoster) DatabaseSchemaUpdateJob(gov.cms.bfd.pipeline.sharedutils.databaseschema.DatabaseSchemaUpdateJob) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Example 2 with Attributes

use of com.newrelic.telemetry.Attributes in project einstein-bot-channel-connector by forcedotcom.

the class NewRelicMetricsExportAutoConfiguration method newRelicMeterRegistry.

@Bean
public NewRelicRegistry newRelicMeterRegistry(NewRelicRegistryConfig config) throws UnknownHostException {
    NewRelicRegistry newRelicRegistry = NewRelicRegistry.builder(config).commonAttributes(new Attributes().put("host", InetAddress.getLocalHost().getHostName())).build();
    newRelicRegistry.config().meterFilter(MeterFilter.ignoreTags("plz_ignore_me"));
    newRelicRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("jvm.threads"));
    newRelicRegistry.start(new NamedThreadFactory("newrelic.micrometer.registry"));
    return newRelicRegistry;
}
Also used : NewRelicRegistry(com.newrelic.telemetry.micrometer.NewRelicRegistry) NamedThreadFactory(io.micrometer.core.instrument.util.NamedThreadFactory) Attributes(com.newrelic.telemetry.Attributes) Bean(org.springframework.context.annotation.Bean)

Example 3 with Attributes

use of com.newrelic.telemetry.Attributes in project newrelic-java-agent by newrelic.

the class JfrService method doStart.

@Override
protected void doStart() {
    if (coreApisExist() && isEnabled()) {
        Agent.LOG.log(Level.INFO, "Attaching New Relic JFR Monitor");
        NewRelic.getAgent().getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_JFR_SERVICE_STARTED_SUCCESS);
        try {
            final DaemonConfig daemonConfig = buildDaemonConfig();
            final Attributes commonAttrs = buildCommonAttributes(daemonConfig);
            final String entityGuid = ServiceFactory.getRPMService().getEntityGuid();
            Agent.LOG.log(Level.INFO, "JFR Monitor obtained entity guid from agent: " + entityGuid);
            commonAttrs.put(ENTITY_GUID, entityGuid);
            final JFRUploader uploader = buildUploader(daemonConfig);
            String pattern = defaultAgentConfig.getValue(ThreadService.NAME_PATTERN_CFG_KEY, ThreadNameNormalizer.DEFAULT_PATTERN);
            uploader.readyToSend(new EventConverter(commonAttrs, pattern));
            jfrController = SetupUtils.buildJfrController(daemonConfig, uploader);
            ExecutorService jfrMonitorService = Executors.newSingleThreadExecutor();
            jfrMonitorService.submit(() -> {
                try {
                    startJfrLoop();
                } catch (JfrRecorderException e) {
                    Agent.LOG.log(Level.INFO, "Error in JFR Monitor, shutting down", e);
                    jfrController.shutdown();
                }
            });
        } catch (Throwable t) {
            Agent.LOG.log(Level.INFO, "Unable to attach JFR Monitor", t);
        }
    } else {
        NewRelic.getAgent().getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_JFR_SERVICE_STARTED_FAIL);
    }
}
Also used : Attributes(com.newrelic.telemetry.Attributes) SetupUtils.buildCommonAttributes(com.newrelic.jfr.daemon.SetupUtils.buildCommonAttributes) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with Attributes

use of com.newrelic.telemetry.Attributes in project dropwizard-metrics-newrelic by newrelic.

the class GaugeTransformerTest method testDoubleGauge.

@Test
void testDoubleGauge() {
    // Given
    double value = 12345d;
    Gauge<Double> wizardGauge = () -> value;
    Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, value, timestamp, new Attributes());
    GaugeTransformer converter = new GaugeTransformer(clock);
    // When
    Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
    // Then
    assertEquals(singleton(expectedMetric), result);
}
Also used : Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) RatioGauge(com.codahale.metrics.RatioGauge) Gauge(com.codahale.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 5 with Attributes

use of com.newrelic.telemetry.Attributes in project dropwizard-metrics-newrelic by newrelic.

the class GaugeTransformerTest method testRatioGauge.

@Test
void testRatioGauge() {
    // Given
    Ratio ratio = Ratio.of(37, 31);
    RatioGauge wizardGauge = new RatioGauge() {

        @Override
        protected Ratio getRatio() {
            return ratio;
        }
    };
    Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, ratio.getValue(), timestamp, new Attributes());
    GaugeTransformer converter = new GaugeTransformer(clock);
    // When
    Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
    // Then
    assertEquals(singleton(expectedMetric), result);
}
Also used : RatioGauge(com.codahale.metrics.RatioGauge) Attributes(com.newrelic.telemetry.Attributes) Ratio(com.codahale.metrics.RatioGauge.Ratio) Metric(com.newrelic.telemetry.metrics.Metric) RatioGauge(com.codahale.metrics.RatioGauge) Gauge(com.codahale.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (com.newrelic.telemetry.Attributes)25 Test (org.junit.jupiter.api.Test)16 Metric (com.newrelic.telemetry.metrics.Metric)13 Count (com.newrelic.telemetry.metrics.Count)10 Gauge (com.newrelic.telemetry.metrics.Gauge)7 Gauge (com.codahale.metrics.Gauge)4 Histogram (com.codahale.metrics.Histogram)3 MetricRegistry (com.codahale.metrics.MetricRegistry)3 RatioGauge (com.codahale.metrics.RatioGauge)3 TimeTracker (com.codahale.metrics.newrelic.util.TimeTracker)3 OkHttpPoster (com.newrelic.telemetry.OkHttpPoster)3 SenderConfiguration (com.newrelic.telemetry.SenderConfiguration)3 MetricBatchSender (com.newrelic.telemetry.metrics.MetricBatchSender)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Meter (com.codahale.metrics.Meter)2 Snapshot (com.codahale.metrics.Snapshot)2 Timer (com.codahale.metrics.Timer)2 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)2 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)2 NewRelicReporter (com.codahale.metrics.newrelic.NewRelicReporter)2