new-relic – skill DevOps & Hạ tầng cho agent AI
Cấu hình nền tảng quan sát New Relic để giám sát hạ tầng và ứng dụng.
Cài skill new-relic bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/new-relic-b38da.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /new-relic – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/new-relic-b38da.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $new-relic – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/new-relic-b38da.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /new-relic – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/new-relic-b38da.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /new-relic – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
New Relic
Monitor applications and infrastructure with New Relic's observability platform.
When to Use This Skill
Use this skill when:
- Implementing full-stack observability
- Setting up APM for applications
- Monitoring infrastructure health
- Creating custom dashboards and alerts
- Implementing distributed tracing
Prerequisites
- New Relic account and license key
- Application access for APM agents
- Infrastructure access for host agents
Select the account/region, ingestion scope, retention and spend limits before enabling agents. Do not send user/customer IDs or sensitive logs without authorization/redaction. Placeholder keys must not become real secrets in source, shell arguments/history or Helm release values: use protected credential providers and existing-secret chart settings. The Docker sample is host-privileged (root mount, socket, host PID/network, SYS_PTRACE); use only if explicitly approved and necessary, with a pinned image and minimum permissions. Verify installed agent/API versions: dashboard/alert JSON are illustrative fragments, the Python metric third argument is not an arbitrary attributes map, and log forwarding configuration belongs in the version-specific logging configuration. Validate alert units and delivery before activation; actual notifications require authorization.
Infrastructure Agent
Linux Installation
# Add repository and install
curl -fLs https://download.newrelic.com/install/newrelic-cli/scripts/install.sh -o /tmp/newrelic-install.sh
# Review and pin the full installer before executing separately.
# Configure license key
sudo NEW_RELIC_API_KEY=<YOUR_API_KEY> NEW_RELIC_ACCOUNT_ID=<ACCOUNT_ID> /usr/local/bin/newrelic install
# Or manual configuration
echo "license_key: YOUR_LICENSE_KEY" | sudo tee -a /etc/newrelic-infra.yml
sudo systemctl start newrelic-infraDocker
# docker-compose.yml
version: '3.8'
services:
newrelic-infra:
image: newrelic/infrastructure:latest
cap_add:
- SYS_PTRACE
privileged: true
pid: "host"
network_mode: "host"
environment:
- NRIA_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY}
- NRIA_DISPLAY_NAME=docker-host
volumes:
- /:/host:ro
- /var/run/docker.sock:/var/run/docker.sockKubernetes
# Using Helm
helm repo add newrelic https://helm-charts.newrelic.com
helm install newrelic-bundle newrelic/nri-bundle \
--namespace newrelic \
--create-namespace \
--set global.licenseKey=${NEW_RELIC_LICENSE_KEY} \
--set global.cluster=my-cluster \
--set newrelic-infrastructure.privileged=true \
--set ksm.enabled=true \
--set kubeEvents.enabled=true \
--set logging.enabled=trueAPM Agents
Node.js
// At the very start of your application
require('newrelic');
// newrelic.js configuration
exports.config = {
app_name: ['My Application'],
license_key: process.env.NEW_RELIC_LICENSE_KEY,
distributed_tracing: {
enabled: true
},
logging: {
level: 'info'
},
error_collector: {
enabled: true,
ignore_status_codes: [404]
},
transaction_tracer: {
enabled: true,
transaction_threshold: 'apdex_f',
record_sql: 'obfuscated'
}
};# Install agent
npm install newrelic
# Run application
NEW_RELIC_LICENSE_KEY=xxx node -r newrelic app.jsPython
# newrelic.ini
[newrelic]
license_key = YOUR_LICENSE_KEY
app_name = My Application
distributed_tracing.enabled = true
transaction_tracer.enabled = true
error_collector.enabled = true
browser_monitoring.auto_instrument = true# Install agent
pip install newrelic
# Generate config file
newrelic-admin generate-config YOUR_LICENSE_KEY newrelic.ini
# Run application
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program python app.py
# Or with gunicorn
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn app:appJava
# Download agent
curl -O https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip
unzip newrelic-java.zip
# Configure newrelic.yml
# license_key: YOUR_LICENSE_KEY
# app_name: My Application
# Run with agent
java -javaagent:/path/to/newrelic.jar -jar myapp.jarGo
package main
import (
"github.com/newrelic/go-agent/v3/newrelic"
"net/http"
)
func main() {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("My Application"),
newrelic.ConfigLicense("YOUR_LICENSE_KEY"),
newrelic.ConfigDistributedTracerEnabled(true),
)
if err != nil {
panic(err)
}
http.HandleFunc(newrelic.WrapHandleFunc(app, "/", indexHandler))
http.ListenAndServe(":8080", nil)
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
txn := newrelic.FromContext(r.Context())
txn.AddAttribute("user_id", "12345")
w.Write([]byte("Hello, World!"))
}Custom Instrumentation
Custom Events
import newrelic.agent
# Record custom event
newrelic.agent.record_custom_event('OrderPlaced', {
'order_id': '12345',
'amount': 99.99,
'customer_id': 'cust_001'
})Custom Metrics
import newrelic.agent
# Record custom metric
newrelic.agent.record_custom_metric('Custom/OrderValue', 99.99)
# With attributes
newrelic.agent.record_custom_metric('Custom/ProcessingTime',
processing_time,
{'unit': 'milliseconds'}
)Custom Spans
import newrelic.agent
@newrelic.agent.function_trace(name='process_payment')
def process_payment(order_id, amount):
# This creates a custom span in the trace
pass
# Manual span creation
with newrelic.agent.FunctionTrace(name='custom_operation'):
# Traced code
passNRQL Queries
Basic Queries
-- Transaction throughput
SELECT rate(count(*), 1 minute) FROM Transaction
WHERE appName = 'My Application'
SINCE 1 hour ago
-- Average response time
SELECT average(duration) FROM Transaction
WHERE appName = 'My Application'
SINCE 1 hour ago
-- Error rate
SELECT percentage(count(*), WHERE error IS true) FROM Transaction
WHERE appName = 'My Application'
SINCE 1 hour ago
-- Apdex score
SELECT apdex(duration, t: 0.5) FROM Transaction
WHERE appName = 'My Application'
SINCE 1 hour agoAdvanced Queries
-- Slowest transactions
SELECT average(duration) FROM Transaction
WHERE appName = 'My Application'
FACET name
SINCE 1 hour ago
ORDER BY average(duration) DESC
LIMIT 10
-- Error breakdown
SELECT count(*) FROM TransactionError
WHERE appName = 'My Application'
FACET error.class
SINCE 1 hour ago
-- Percentile response times
SELECT percentile(duration, 50, 90, 95, 99) FROM Transaction
WHERE appName = 'My Application'
SINCE 1 hour ago TIMESERIES
-- Custom event analysis
SELECT average(amount), count(*) FROM OrderPlaced
FACET customer_id
SINCE 1 day agoDashboards
Dashboard JSON
{
"name": "Application Dashboard",
"pages": [
{
"name": "Overview",
"widgets": [
{
"title": "Throughput",
"visualization": {"id": "viz.line"},
"configuration": {
"nrqlQueries": [
{
"accountId": 12345,
"query": "SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName = 'My Application' SINCE 1 hour ago TIMESERIES"
}
]
}
},
{
"title": "Error Rate",
"visualization": {"id": "viz.billboard"},
"configuration": {
"nrqlQueries": [
{
"accountId": 12345,
"query": "SELECT percentage(count(*), WHERE error IS true) FROM Transaction WHERE appName = 'My Application' SINCE 1 hour ago"
}
]
}
}
]
}
]
}Alerts
Alert Condition (NRQL)
{
"name": "High Error Rate",
"type": "static",
"nrql": {
"query": "SELECT percentage(count(*), WHERE error IS true) FROM Transaction WHERE appName = 'My Application'"
},
"valueFunction": "single_value",
"terms": [
{
"threshold": 5,
"thresholdOccurrences": "all",
"thresholdDuration": 300,
"operator": "above",
"priority": "critical"
},
{
"threshold": 2,
"thresholdOccurrences": "all",
"thresholdDuration": 300,
"operator": "above",
"priority": "warning"
}
]
}Alert Policy
{
"name": "Application Alerts",
"incident_preference": "PER_CONDITION_AND_TARGET",
"conditions": [
{
"name": "High Response Time",
"type": "apm_app_metric",
"entities": ["My Application"],
"metric": "response_time_web",
"condition_scope": "application",
"terms": [
{
"duration": "5",
"operator": "above",
"threshold": "1",
"priority": "critical"
}
]
}
]
}Logs in Context
Python Configuration
```p
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- nfs-storage – Cấu hình máy chủ và máy khách NFS. Triển khai chia sẻ tệp qua mạng cho hệ thống Linux…
- noaa-radar-satellite-fetching – Tải sản phẩm NOAA NEXRAD và GOES từ kho lưu trữ đám mây công khai, chọn đúng site…
- observability-cloud-planning – Lập sổ đăng ký cloud, SLO và mức sẵn sàng ứng phó sự cố sau khi tiếp nhận yêu cầu. Dùng…
- observability-engineer – Xây dựng hệ thống monitoring, logging và tracing sẵn sàng cho production. Triển khai…
- observability-monitoring-monitor-setup – Thiết lập metrics, distributed tracing, tổng hợp log và dashboard để giám sát ứng dụng…
- observability-monitoring-slo-implement – Bạn là chuyên gia SLO (Service Level Objective), chuyên triển khai tiêu chuẩn độ tin cậy…
- odoo-backup-strategy – Chiến lược sao lưu và khôi phục Odoo toàn diện: dump cơ sở dữ liệu, sao lưu filestore…
- odoo-docker-deployment – Thiết lập Docker và docker-compose cho Odoo sẵn sàng production, với PostgreSQL, volume…