# Install Node.js APM agentnpminstallnewrelic--save
# Generate configurationcpnode_modules/newrelic/newrelic.js.
# Edit configuration file with your license key# license_key: 'YOUR_LICENSE_KEY'# app_name: ['My Application']# Add to the first line of your main application file# require('newrelic');# Start applicationnodeapp.js
# Query transaction performancenewrelicnrqlquery--accountIdYOUR_ACCOUNT_ID\--query"SELECT average(duration), percentile(duration, 95) FROM Transaction WHERE appName = 'My Application' SINCE 1 hour ago"
Use Case 2: Set Up Infrastructure Monitoring with Custom Tags¶
# Install infrastructure agentcurl-Lshttps://download.newrelic.com/install/newrelic-cli/scripts/install.sh|bash
# Configure with custom attributessudotee/etc/newrelic-infra.yml<< EOFlicense_key: YOUR_LICENSE_KEYdisplay_name: web-server-01custom_attributes: environment: production team: platform datacenter: us-east-1 role: webserverEOF# Start the agentsudosystemctlstartnewrelic-infra
sudosystemctlenablenewrelic-infra
# Verify it's reportingnewrelicentitysearch--name"web-server-01"# Query infrastructure metricsnewrelicnrqlquery--accountIdYOUR_ACCOUNT_ID\--query"SELECT average(cpuPercent), average(memoryUsedPercent) FROM SystemSample WHERE environment = 'production' FACET hostname SINCE 1 hour ago"
Use Case 3: Create Deployment Markers for Release Tracking¶
# Configure CLI profilenewrelicprofileadd--profileproduction\--apiKeyYOUR_USER_API_KEY\--regionus\--accountIdYOUR_ACCOUNT_ID
# Get application IDAPP_ID=$(newrelicentitysearch--name"My Application"--typeAPPLICATION|grep-oP'id: \K\d+')# Create deployment marker during CI/CDnewrelicapmdeploymentcreate\--applicationId$APP_ID\--revision"v2.5.0"\--changelog"Added new feature X, fixed bug Y"\--description"Production deployment from Jenkins"\--user"$USER"# Query performance before and after deploymentnewrelicnrqlquery--accountIdYOUR_ACCOUNT_ID\--query"SELECT average(duration) FROM Transaction WHERE appName = 'My Application' SINCE 2 hours ago TIMESERIES 10 minutes"
# Configure infrastructure agent to forward logssudotee-a/etc/newrelic-infra.yml<< EOFlog_forward: - name: application-logs file: /var/log/myapp/*.log attributes: logtype: application environment: productionEOF# Restart agentsudosystemctlrestartnewrelic-infra
# Search logs for errorsnewrelicnrqlquery--accountIdYOUR_ACCOUNT_ID\--query"SELECT * FROM Log WHERE logtype = 'application' AND message LIKE '%ERROR%' SINCE 30 minutes ago LIMIT 100"# Analyze error patternsnewrelicnrqlquery--accountIdYOUR_ACCOUNT_ID\--query"SELECT count(*) FROM Log WHERE logtype = 'application' AND message LIKE '%ERROR%' FACET message SINCE 1 day ago"
Use Custom Attributes: Tag all entities with environment, team, and purpose metadata for better filtering and organization. Add custom attributes in agent configuration files to automatically categorize all metrics.
Implement Distributed Tracing: Enable distributed tracing in all APM agents to track requests across microservices. This provides end-to-end visibility and helps identify bottlenecks in complex architectures.
Set Up Deployment Markers: Create deployment markers for every production release to correlate performance changes with code deployments. This dramatically reduces troubleshooting time when issues arise.
Configure Alert Policies Properly: Use baseline alerts for dynamic thresholds and static alerts for known limits. Set up multiple notification channels and use incident intelligence to reduce alert fatigue.
Optimize Data Retention: Use data management tools to control data ingest and retention. Drop unnecessary metrics, aggregate data appropriately, and use sampling for high-volume applications to manage costs.
Leverage Workloads: Group related entities into workloads to monitor entire application stacks together. This provides a unified view of health status and simplifies team collaboration.
Use NRQL Effectively: Master NRQL for custom queries and dashboards. Use FACET for grouping, TIMESERIES for trends, and percentile() for meaningful performance metrics instead of just averages.
Implement Synthetic Monitoring: Set up synthetic monitors for critical user journeys and API endpoints from multiple geographic locations. This provides proactive alerting before users experience issues.
Secure Your API Keys: Use user API keys for CLI operations and license keys for agents. Rotate keys regularly, use different keys per environment, and never commit keys to version control.
Check license key in configuration file, verify network connectivity to New Relic endpoints (collector.newrelic.com), check agent logs for errors: sudo tail -f /var/log/newrelic-infra/newrelic-infra.log
High memory usage by infrastructure agent
Reduce sampling rates in /etc/newrelic-infra.yml: set metrics_network_sample_rate: 60, metrics_process_sample_rate: 60, disable unnecessary integrations
APM agent causing application slowdown
Reduce transaction trace threshold, disable slow SQL trace collection, or adjust sampling rate in agent configuration. For Node.js: set transaction_tracer.enabled: false temporarily
Missing distributed traces
Ensure all services have distributed tracing enabled in agent config, verify compatible agent versions (check compatibility matrix), ensure trace context headers are propagated through middleware
CLI authentication failures
Regenerate user API key from New Relic UI (Account Settings > API Keys), verify region setting (US vs EU): newrelic profile add --region us, check API key permissions
Data not appearing in queries
Verify correct account ID, check data type (Transaction vs TransactionError), ensure time range is appropriate (SINCE 1 hour ago), verify entity is reporting: newrelic entity search --name "app-name"
Docker agent not collecting container metrics
Ensure proper volume mounts: -v "/var/run/docker.sock:/var/run/docker.sock", run with --privileged flag, verify --pid=host is set for process monitoring
Logs not forwarding
Check log file paths in /etc/newrelic-infra.yml, verify file permissions (agent must read logs), ensure log forwarding is enabled, check for parsing errors in agent logs
High data ingest costs
Review data ingest in Data Management UI, implement drop rules for unnecessary data, reduce APM transaction trace sampling, disable detailed process metrics if not needed
Alert notifications not received
Verify notification channel configuration, check incident preference settings on alert policy, ensure conditions have proper thresholds, test notification channel from UI
-- Average response time by applicationSELECTaverage(duration)FROMTransactionFACETappNameSINCE1hourago-- Error rate percentageSELECTpercentage(count(*),WHEREerrorIStrue)FROMTransactionSINCE1hourago-- 95th and 99th percentile response timesSELECTpercentile(duration,95,99)FROMTransactionSINCE1dayagoTIMESERIES-- Top 10 slowest transactionsSELECTaverage(duration),count(*)FROMTransactionFACETnameSINCE1houragoLIMIT10-- Infrastructure CPU usageSELECTaverage(cpuPercent)FROMSystemSampleFACEThostnameSINCE1hourago-- Log error count by messageSELECTcount(*)FROMLogWHERElevel='error'FACETmessageSINCE1hourago-- Request throughput per minuteSELECTrate(count(*),1minute)FROMTransactionTIMESERIESSINCE1hourago-- Database query performanceSELECTaverage(databaseDuration)FROMTransactionFACETdatabaseTypeSINCE1hourago