Zum Inhalt
_

_

New Relic Cheatsheet

• Installation

Infrastructure Agent

Platform Command
Ubuntu/Debian INLINE_CODE_10
RHEL/CentOS INLINE_CODE_11
macOS INLINE_CODE_12
Windows (PowerShell) INLINE_CODE_13
Docker INLINE_CODE_14

New Relic CLI

Platform Command
Linux/macOS INLINE_CODE_15
macOS (Homebrew) INLINE_CODE_16
Linux (Snap) INLINE_CODE_17
Windows (Scoop) INLINE_CODE_18

APM Agents

Language Command
Node.js INLINE_CODE_19
Python INLINE_CODE_20
Java INLINE_CODE_21
Ruby INLINE_CODE_22 (add to Gemfile)
PHP INLINE_CODE_23 (Ubuntu) or INLINE_CODE_24 (RHEL)
.NET Download from INLINE_CODE_25
_
oder Grundlegende Befehle

CLI Profilverwaltung

Command Description
INLINE_CODE_26 Add new profile with API key
INLINE_CODE_27 List all configured profiles
INLINE_CODE_28 Set default profile
INLINE_CODE_29 Delete a profile
INLINE_CODE_30 View profile details
_
### Entity Management
Command Description
INLINE_CODE_31 Search for entities by name
INLINE_CODE_32 Search entities by type
INLINE_CODE_33 Get detailed entity information
INLINE_CODE_34 List all tags for an entity
INLINE_CODE_35 Add tag to entity
INLINE_CODE_36 Remove tag from entity
_
### Infrastruktur Agent Control
Command Description
INLINE_CODE_37 Check agent status
INLINE_CODE_38 Start infrastructure agent
INLINE_CODE_39 Stop infrastructure agent
INLINE_CODE_40 Restart infrastructure agent
INLINE_CODE_41 Enable agent at boot
INLINE_CODE_42 View agent logs in real-time
INLINE_CODE_43 Test configuration without starting
INLINE_CODE_44 Display agent version

/ Fortgeschrittene Nutzung

NRQL Quers

Command Description
INLINE_CODE_45 Execute basic NRQL query
INLINE_CODE_46 Query with faceting
INLINE_CODE_47 Search logs with filtering
INLINE_CODE_48 Get percentiles with JSON output
INLINE_CODE_49 Calculate rate with time series

Deployment Management

Command Description
INLINE_CODE_50 Create deployment marker
INLINE_CODE_51 Create detailed deployment marker
INLINE_CODE_52 List all deployments for application

Workload Management

Command Description
INLINE_CODE_53 Create new workload
INLINE_CODE_54 Get workload details
INLINE_CODE_55 Update workload name
INLINE_CODE_56 Delete workload
INLINE_CODE_57 List all workloads in account

Alert Management

Command Description
INLINE_CODE_58 Create alert policy
INLINE_CODE_59 List all alert policies
INLINE_CODE_60 List conditions for policy
INLINE_CODE_61 List notification channels

Dashboard Management

Command Description
INLINE_CODE_62 Create new dashboard
INLINE_CODE_63 List all dashboards
INLINE_CODE_64 Get dashboard configuration
INLINE_CODE_65 Delete dashboard

Konfiguration

Infrastructure Agent Configuration (/etc/newrelic-infra.yml_)

# Required: License key
license_key: YOUR_LICENSE_KEY

# Optional: Custom display name
display_name: web-server-01

# Logging configuration
log_file: /var/log/newrelic-infra/newrelic-infra.log
log_level: info  # Options: error, warn, info, debug, trace

# Proxy configuration
proxy: http://proxy.example.com:8080
proxy_validate_certificates: true

# Custom attributes (tags)
custom_attributes:
  environment: production
  team: platform
  region: us-east-1

# Metrics configuration
disable_all_plugins: false
metrics_network_sample_rate: 10  # seconds
metrics_process_sample_rate: 20  # seconds
metrics_storage_sample_rate: 20  # seconds

# Process monitoring
enable_process_metrics: true

APM Agent Configuration (Node.js - newrelic.js)

'use strict'

exports.config = {
  app_name: ['My Application'],
  license_key: 'YOUR_LICENSE_KEY',

  logging: {
    level: 'info',
    filepath: 'stdout'
  },

  // Distributed tracing
  distributed_tracing: {
    enabled: true
  },

  // Transaction tracer
  transaction_tracer: {
    enabled: true,
    transaction_threshold: 'apdex_f',
    record_sql: 'obfuscated',
    explain_threshold: 500
  },

  // Error collector
  error_collector: {
    enabled: true,
    ignore_status_codes: [404]
  },

  // Custom attributes
  attributes: {
    include: ['request.parameters.*'],
    exclude: ['request.headers.cookie']
  }
}

Python Agent Configuration (newrelic.ini)

[newrelic]
license_key = YOUR_LICENSE_KEY
app_name = Python Application

# Logging
log_file = stdout
log_level = info

# Distributed tracing
distributed_tracing.enabled = true

# Transaction tracer
transaction_tracer.enabled = true
transaction_tracer.transaction_threshold = apdex_f
transaction_tracer.record_sql = obfuscated
transaction_tracer.explain_threshold = 0.5

# Error collector
error_collector.enabled = true
error_collector.ignore_status_codes = 404

# Browser monitoring
browser_monitoring.auto_instrument = true

# Custom attributes
attributes.include = request.parameters.*
attributes.exclude = request.headers.cookie

CLI Konfiguration (~/.newrelic/newrelic-cli.json)

{
  "defaultProfile": "production",
  "profiles": {
    "production": {
      "apiKey": "YOUR_USER_API_KEY",
      "region": "us",
      "accountId": "YOUR_ACCOUNT_ID"
    },
    "staging": {
      "apiKey": "YOUR_STAGING_API_KEY",
      "region": "us",
      "accountId": "YOUR_STAGING_ACCOUNT_ID"
    }
  }
}

Häufige Anwendungsfälle

Use Case 1: Monitor Application Performance

# Install Node.js APM agent
npm install newrelic --save

# Generate configuration
cp node_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 application
node app.js

# Query transaction performance
newrelic nrql query --accountId YOUR_ACCOUNT_ID \
  --query "SELECT average(duration), percentile(duration, 95) FROM Transaction WHERE appName = 'My Application' SINCE 1 hour ago"

Use Case 2: Infrastrukturüberwachung mit benutzerdefinierten Tags einrichten

# Install infrastructure agent
curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash

# Configure with custom attributes
sudo tee /etc/newrelic-infra.yml << EOF
license_key: YOUR_LICENSE_KEY
display_name: web-server-01
custom_attributes:
  environment: production
  team: platform
  datacenter: us-east-1
  role: webserver
EOF

# Start the agent
sudo systemctl start newrelic-infra
sudo systemctl enable newrelic-infra

# Verify it's reporting
newrelic entity search --name "web-server-01"

# Query infrastructure metrics
newrelic nrql query --accountId YOUR_ACCOUNT_ID \
  --query "SELECT average(cpuPercent), average(memoryUsedPercent) FROM SystemSample WHERE environment = 'production' FACET hostname SINCE 1 hour ago"

Use Case 3: Deployment Markers for Release Tracking erstellen

# Configure CLI profile
newrelic profile add --profile production \
  --apiKey YOUR_USER_API_KEY \
  --region us \
  --accountId YOUR_ACCOUNT_ID

# Get application ID
APP_ID=$(newrelic entity search --name "My Application" --type APPLICATION | grep -oP 'id: \K\d+')

# Create deployment marker during CI/CD
newrelic apm deployment create \
  --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 deployment
newrelic nrql query --accountId YOUR_ACCOUNT_ID \
  --query "SELECT average(duration) FROM Transaction WHERE appName = 'My Application' SINCE 2 hours ago TIMESERIES 10 minutes"

Use Case 4: Zentralisiertes Log Management

# Configure infrastructure agent to forward logs
sudo tee -a /etc/newrelic-infra.yml << EOF
log_forward:
  - name: application-logs
    file: /var/log/myapp/*.log
    attributes:
      logtype: application
      environment: production
EOF

# Restart agent
sudo systemctl restart newrelic-infra

# Search logs for errors
newrelic nrql query --accountId YOUR_ACCOUNT_ID \
  --query "SELECT * FROM Log WHERE logtype = 'application' AND message LIKE '%ERROR%' SINCE 30 minutes ago LIMIT 100"

# Analyze error patterns
newrelic nrql query --accountId YOUR_ACCOUNT_ID \
  --query "SELECT count(*) FROM Log WHERE logtype = 'application' AND message LIKE '%ERROR%' FACET message SINCE 1 day ago"

Use Case 5: Erstellen Sie benutzerdefiniertes Dashboard mit CLI

# Create dashboard with multiple widgets
newrelic dashboard create --accountId YOUR_ACCOUNT_ID << 'EOF'
{
  "name": "Production Overview",
  "permissions": "PUBLIC_READ_WRITE",
  "pages": [
    {
      "name": "Application Performance",
      "widgets": [
        {
          "title": "Average Response Time",
          "visualization": { "id": "viz.line" },
          "rawConfiguration": {
            "nrqlQueries": [
              {
                "accountId": YOUR_ACCOUNT_ID,
                "query": "SELECT average(duration) FROM Transaction TIMESERIES AUTO"
              }
            ]
          }
        }
      ]
    }
  ]
}
EOF

# List dashboards
newrelic dashboard list --accountId YOUR_ACCOUNT_ID

oder Best Practices

**Benutzerdefinierte Attribute verwenden*: Alle Einheiten mit Umgebung, Team und Zweck Metadaten für bessere Filterung und Organisation. Fügen Sie benutzerdefinierte Attribute in Agent-Konfigurationsdateien hinzu, um automatisch alle Metriken zu kategorisieren.

  • Implementieren Sie verteilte Tracing: Aktivieren Sie verteilte Tracing in allen APM-Agenten, um Anfragen über Mikroservices zu verfolgen. Dies bietet eine End-to-End-Vision und hilft, Engpässe in komplexen Architekturen zu identifizieren.

  • Set Up Deployment Markers: Erstellen Sie Deployment Marker für jede Produktion, um Leistungsänderungen mit Code-Installationen zu korrelieren. Dies reduziert die Fehlerbehebungszeit drastisch, wenn Probleme auftreten.

  • Konfigurieren Sie Alarmrichtlinien Properly: Verwenden Sie Basis-Alarme für dynamische Schwellenwerte und statische Alarme für bekannte Grenzen. Konfigurieren Sie mehrere Benachrichtigungskanäle und verwenden Sie Störinformationen, um Alarmermüdung zu reduzieren.

  • **Datenretention optimieren*: Verwenden Sie die Datenverwaltungstools, um Dateneinnahme und Speicherung zu steuern. unnötige Metriken fallen lassen, aggregierte Daten angemessen erfassen und für hochvolumige Anwendungen Stichproben verwenden, um Kosten zu verwalten.

  • **Leverage Workloads*: Gruppenbezogene Einheiten in Workloads, um ganze Anwendungsstapel zusammen zu überwachen. Dies bietet eine einheitliche Sicht auf den Gesundheitszustand und vereinfacht die Teamkooperation.

  • ** Verwenden Sie NRQL effektiv*: Master NRQL für benutzerdefinierte Abfragen und Dashboards. Verwenden Sie FACET für Gruppierung, TIMESERIES für Trends und percentile() für aussagekräftige Performance Metriken statt nur durchschnittlichen.

  • **Implement Synthetic Monitoring*: Aufbau von synthetischen Monitoren für kritische Nutzerfahrten und API-Endpunkte aus mehreren geographischen Standorten. Dies bietet eine proaktive Warnung, bevor Benutzer Probleme erleben.

  • **Secure Your API Keys*: Verwenden Sie Benutzer-API-Tasten für CLI-Betriebe und Lizenzschlüssel für Agenten. Drehen Sie die Tasten regelmäßig, verwenden Sie verschiedene Tasten pro Umgebung und begehen Sie nie Schlüssel zur Versionskontrolle.

Fehlerbehebung

Issue Solution
Agent not reporting data Check license key in configuration file, verify network connectivity to New Relic endpoints (INLINE_CODE_73), check agent logs for errors: INLINE_CODE_74
High memory usage by infrastructure agent Reduce sampling rates in INLINE_CODE_75: set INLINE_CODE_76, INLINE_CODE_77, 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 INLINE_CODE_78 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): INLINE_CODE_79, check API key permissions
Data not appearing in queries Verify correct account ID, check data type (Transaction vs TransactionError), ensure time range is appropriate (INLINE_CODE_80), verify entity is reporting: INLINE_CODE_81
Docker agent not collecting container metrics Ensure proper volume mounts: INLINE_CODE_82, run with INLINE_CODE_83 flag, verify INLINE_CODE_84 is set for process monitoring
Logs not forwarding Check log file paths in INLINE_CODE_85, 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

 Quick Reference: Common NRQL Queries

-- Average response time by application
SELECT average(duration) FROM Transaction FACET appName SINCE 1 hour ago

-- Error rate percentage
SELECT percentage(count(*), WHERE error IS true) FROM Transaction SINCE 1 hour ago

-- 95th and 99th percentile response times
SELECT percentile(duration, 95, 99) FROM Transaction SINCE 1 day ago TIMESERIES

-- Top 10 slowest transactions
SELECT average(duration), count(*) FROM Transaction FACET name SINCE 1 hour ago LIMIT 10

-- Infrastructure CPU usage
SELECT average(cpuPercent) FROM SystemSample FACET hostname SINCE 1 hour ago

-- Log error count by message
SELECT count(*) FROM Log WHERE level = 'error' FACET message SINCE 1 hour ago

-- Request throughput per minute
SELECT rate(count(*), 1 minute) FROM Transaction TIMESERIES SINCE 1 hour ago

-- Database query performance
SELECT average(databaseDuration) FROM Transaction FACET databaseType SINCE 1 hour ago