New relic 📋 Copia tutti i nuovi comandi Relic 📄 Genera nuova reliquia PDF Guida_HTML_TAG_90__ Traduzione: # New Relic Cheatsheet # ## Installazione ### Agente delle infrastrutture _Tabella_93___ ## New Relic CLI _Tabella_94__ ### APM Agents # _Tabella_95__ # Comandi di base ## CLI # Gestione dei profili _Tabella_96__ ### Gestione delle entrate TABELLA ### Infrastructure Agent Control _Tabella_98__ ## Uso avanzato ### NRQL Querys _Tabella_99_ ### Gestione delle risorse _Tabella_100__ ### Gestione del carico di lavoro _Tabella_101__ ### Gestione allerta _Tabella_102__ ### Gestione del Dashboard _Tabella_103__ ## Configurazione ### 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 Configuration (`~/.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" } } } ## Common Use Cases ### Use Case 1: Monitorare le prestazioni delle applicazioni # 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: Imposta il monitoraggio delle infrastrutture con i tag personalizzati # 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: Create Deployment Markers for Release Tracking # 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: Centralized 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: Crea Dashboard personalizzato con 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 # Migliori Pratiche - **Utilizzare gli attributi personalizzati**: etichettare tutte le entità con l'ambiente, il team e i metadati di scopo per migliorare il filtraggio e l'organizzazione. Aggiungi attributi personalizzati nei file di configurazione dell'agente per classificare automaticamente tutte le metriche. - **Implement Distributed Tracing**: Abilita il tracciamento distribuito in tutti gli agenti APM per monitorare le richieste attraverso i microservizi. Questo fornisce visibilità end-to-end e aiuta a identificare i colli di bottiglia in architetture complesse. - **Set Up Deployment Markers**: Crea marcatori di distribuzione per ogni rilascio di produzione per correlare le modifiche delle prestazioni con le implementazioni dei codici. Questo riduce drasticamente il tempo di risoluzione dei problemi quando si presentano problemi. - **Configurare le politiche di allarme correttamente**: Utilizzare avvisi di base per soglie dinamiche e avvisi statici per limiti noti. Impostare più canali di notifica e utilizzare l'intelligenza incidente per ridurre la stanchezza di allarme. - **Ottimizzare la conservazione dei dati**: Utilizzare strumenti di gestione dei dati per controllare l'ingestione e la conservazione dei dati. Metriche inutili, dati aggregati in modo appropriato, e utilizzare il campionamento per applicazioni ad alto volume per gestire i costi. - **Leverage Workloads**: Gruppo entità collegate in carichi di lavoro per monitorare insieme interi stack applicativi. Questo fornisce una visione unificata dello stato di salute e semplifica la collaborazione del team. **Utilizza NRQL efficacemente**: Master NRQL per query e dashboard personalizzati. Utilizzare `FACET` per raggruppare, `TIMESERIES` per le tendenze, e `percentile()` per metriche di performance significative al posto delle medie. - **Implementare il monitoraggio sintetico**: Impostare monitor sintetici per i viaggi utente critici e endpoint API da più posizioni geografiche. Questo fornisce all'avviso proattivo prima che gli utenti si verifichino problemi. - **Segui le tue API Keys**: Utilizzare i tasti API utente per le operazioni CLI e le chiavi di licenza per gli agenti. Ruotare regolarmente i tasti, utilizzare diverse chiavi per ambiente, e non commit mai chiavi per il controllo della versione. ## Risoluzione dei problemi _Tabella_104__ ## 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