Search in sources :

Example 1 with Normalizer

use of com.newrelic.agent.normalization.Normalizer in project newrelic-java-agent by newrelic.

the class RPMService method harvest.

@Override
public void harvest(StatsEngine statsEngine) {
    if (!isConnected()) {
        // Assumption: failed re-connect should be a result of a temporary condition, and we need to retry
        try {
            Agent.LOG.fine("Trying to re-establish connection to New Relic.");
            this.launch();
        } catch (Exception e) {
            Agent.LOG.fine("Problem trying to re-establish connection to New Relic: " + e.getMessage());
        }
    }
    if (isConnected()) {
        boolean retry = false;
        Normalizer metricNormalizer = ServiceFactory.getNormalizationService().getMetricNormalizer(appName);
        List<MetricData> data = statsEngine.getMetricData(metricNormalizer);
        long startTime = System.nanoTime();
        long reportInterval = 0;
        try {
            long now = System.currentTimeMillis();
            sendMetricDataSyncRestart(lastReportTime, now, data);
            reportInterval = now - lastReportTime;
            lastReportTime = now;
            last503Error.set(0);
            // log at info level whenever we successfully send metric data following a failure
            if (retryCount.get() > 0) {
                Agent.LOG.log(Level.INFO, "Successfully reconnected to the New Relic data service.");
            }
            Agent.LOG.log(Level.FINE, "Reported {0} timeslices for {1}", data.size(), getApplicationName());
        } catch (InternalLimitExceeded e) {
            Agent.LOG.log(Level.SEVERE, "The metric data post was too large. {0} timeslices will not be resent", data.size());
        } catch (MetricDataException e) {
            Agent.LOG.log(Level.SEVERE, "An invalid response was received while sending metric data. This data will not be resent.");
            Agent.LOG.log(Level.FINEST, e, e.toString());
        } catch (HttpError e) {
            // HttpError handled here
            retry = e.isRetryableError();
            if (HttpResponseCode.SERVICE_UNAVAILABLE == e.getStatusCode()) {
                // 503s are unfortunately common for the collector, so we log these at a lower level until we see
                // many consecutive failures
                handle503Error(e);
            } else if (retry) {
                // otherwise if we're going to retry later things aren't so bad
                Agent.LOG.log(Level.INFO, "An error occurred posting metric data - {0}. This data will be resent later.", e.getMessage());
            } else {
                // but let's call out when we're dropping data. Check out HttpError.isRetryableError()
                Agent.LOG.log(Level.SEVERE, "An error occurred posting metric data - {0}. {1} timeslices will not be resent.", e.getMessage(), data.size());
            }
        } catch (ForceRestartException e) {
            logForceRestartException(e);
            reconnectAsync();
            retry = true;
        } catch (ForceDisconnectException e) {
            logForceDisconnectException(e);
            shutdownAsync();
        } catch (HostConnectException e) {
            retry = true;
            Agent.LOG.log(Level.INFO, "A connection error occurred contacting {0}. Please check your network / proxy settings.", e.getHostName());
            Agent.LOG.log(Level.FINEST, e, e.toString());
        } catch (Exception e) {
            // LicenseException handled here
            logMetricDataError(e);
            retry = true;
            if (e.getMessage() != null) {
                String message = e.getMessage().toLowerCase();
                // (web transaction maybe?). clear out the metrics
                if (message.contains("json") && message.contains("parse")) {
                    retry = false;
                }
            }
        }
        long duration = System.nanoTime() - startTime;
        if (retry) {
            retryCount.getAndIncrement();
        } else {
            retryCount.set(0);
            statsEngine.clear();
            recordSupportabilityMetrics(statsEngine, reportInterval, duration, data.size());
        }
    }
}
Also used : Normalizer(com.newrelic.agent.normalization.Normalizer) HostConnectException(com.newrelic.agent.transport.HostConnectException) ConnectException(java.net.ConnectException) UnexpectedException(java.rmi.UnexpectedException) HostConnectException(com.newrelic.agent.transport.HostConnectException) HttpError(com.newrelic.agent.transport.HttpError)

Example 2 with Normalizer

use of com.newrelic.agent.normalization.Normalizer in project newrelic-java-agent by newrelic.

the class Transaction method renameTransaction.

private void renameTransaction() {
    if (Agent.LOG.isFinestEnabled()) {
        threadAssertion();
    }
    String appName = getApplicationName();
    // 1. Apply metric_name_rules (aka, "regex rules") sent by the collector.
    Normalizer metricDataNormalizer = ServiceFactory.getNormalizationService().getMetricNormalizer(appName);
    String txName = metricDataNormalizer.normalize(priorityTransactionName.getName());
    // 2. Apply transaction_segment_terms rules (aka, "white list rules") and transaction_name_rules.
    Normalizer txNormalizer = ServiceFactory.getNormalizationService().getTransactionNormalizer(appName);
    txName = txNormalizer.normalize(txName);
    if (txName == null) {
        setIgnore(true);
        return;
    }
    if (!txName.equals(priorityTransactionName.getName())) {
        setPriorityTransactionNameLocked(PriorityTransactionName.create(txName, isWebTransaction() ? PriorityTransactionName.WEB_TRANSACTION_CATEGORY : PriorityTransactionName.UNDEFINED_TRANSACTION_CATEGORY, TransactionNamePriority.REQUEST_URI));
    }
}
Also used : Normalizer(com.newrelic.agent.normalization.Normalizer)

Aggregations

Normalizer (com.newrelic.agent.normalization.Normalizer)2 HostConnectException (com.newrelic.agent.transport.HostConnectException)1 HttpError (com.newrelic.agent.transport.HttpError)1 ConnectException (java.net.ConnectException)1 UnexpectedException (java.rmi.UnexpectedException)1