Esta página configura el receptor Prometheus del Collector de OpenTelemetry para monitorear un clúster de Elasticsearch autohospedado a través de un exportador de Elasticsearch de Prometheus existente. Utilice esta ruta solo si ya ejecuta ese exportador o si está migrando desde un stack de monitoreo basado en Prometheus. De lo contrario, use NRDOT o OTel Collector Contrib en su lugar, los cuales se conectan directamente a la API de Elasticsearch sin un componente adicional.
Compatibilidad y requisitos
Soportado
- Elasticsearch 7.16 o posterior, monitoreado a través de
elasticsearch_exporter1.x
Necesita
- Una clave de licencia de New Relic
- Privilegios de root o sudo en el host que ejecuta el exportador y el recolector
- Conectividad HTTPS saliente (puerto 443) al extremo OTLP de New Relic
Instale el recolector NRDOT o el Collector Contrib de OTel
Instale el recolector NRDOT o el Collector Contrib de OpenTelemetry y ejecútelo como un servicio de systemd. Los paquetes oficiales de .deb/.rpm crean la unidad de servicio.
Instale y configure el exportador de Elasticsearch
El exportador de Elasticsearch para Prometheus expone las métricas de Elasticsearch en formato Prometheus en el puerto 9114.
Descargue el exportador:
bash$wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.8.0/elasticsearch_exporter-1.8.0.linux-amd64.tar.gz$tar xzf elasticsearch_exporter-*.tar.gz$cd elasticsearch_exporter-*Inicie el exportador, apuntando a la instancia de Elasticsearch:
bash$./elasticsearch_exporter --es.uri=http://<YOUR_ELASTICSEARCH_HOST>:9200Para un clúster seguro, use
--es.uri=https://<YOUR_ELASTICSEARCH_USERNAME>:<YOUR_ELASTICSEARCH_PASSWORD>@<YOUR_ELASTICSEARCH_HOST>:9200 --es.ssl-skip-verify. El indicador--es.ssl-skip-verifydesactiva la verificación del certificado TLS, así que utilícelo solo para pruebas y utilice un certificado de confianza en producción.Este comando se ejecuta en primer plano, así que mantenga esta terminal abierta y use una segunda terminal para el siguiente paso. El exportador se detiene al cerrar la sesión, por lo que para mantenerlo en ejecución, ejecútelo como un servicio de systemd o bajo un administrador de procesos.
Verifique que el exportador se esté ejecutando:
bash$curl http://localhost:9114/metrics | grep elasticsearch_cluster_healthDebería ver métricas en formato Prometheus como
elasticsearch_cluster_health_status. Si no devuelve nada, el exportador no es accesible. Verifique su proceso y el valor--es.uriantes de continuar.
Configurar el recolector
Esta configuración funciona tanto con NRDOT como con OTel Collector Contrib. Colóquelo en la ubicación de configuración adecuada para el recolector, /etc/nrdot-collector/config.yaml para NRDOT o /etc/otelcol-contrib/config.yaml para OTel Collector Contrib, y reemplace el contenido existente. Esto asigna los nombres de las métricas de Prometheus del exportador a los nombres de estilo OTel que alimentan el dashboard de New Relic Elasticsearch.
Antes de reemplazar el archivo, haga una copia de seguridad de la configuración existente del recolector:
$# NRDOT$sudo cp /etc/nrdot-collector/config.yaml /etc/nrdot-collector/config.yaml.backup$
$# OTel Collector Contrib$sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backupLuego utilice esta configuración:
receivers: prometheus/elasticsearch: config: scrape_configs: - job_name: 'elasticsearch' scrape_interval: 15s static_configs: - targets: ['localhost:9114'] # <-- elasticsearch_exporter address
processors: memory_limiter: check_interval: 60s limit_mib: ${env:NEW_RELIC_MEMORY_LIMIT_MIB:-100} metricstransform/prom_to_otel: transforms: - include: ^elasticsearch_cluster_health_number_of_data_nodes$ match_type: regexp action: update new_name: elasticsearch.cluster.data_nodes - include: ^elasticsearch_cluster_health_status$ match_type: regexp action: update new_name: elasticsearch.cluster.health operations: - action: update_label label: color new_label: status - include: ^elasticsearch_cluster_health_number_of_in_flight_fetch$ match_type: regexp action: update new_name: elasticsearch.cluster.in_flight_fetch - include: ^elasticsearch_cluster_health_number_of_nodes$ match_type: regexp action: update new_name: elasticsearch.cluster.nodes - include: ^elasticsearch_cluster_health_number_of_pending_tasks$ match_type: regexp action: update new_name: elasticsearch.cluster.pending_tasks - include: ^elasticsearch_cluster_health_active_shards$ match_type: regexp action: update new_name: elasticsearch.cluster.shards operations: - action: add_label new_label: state new_value: active - include: ^elasticsearch_cluster_health_active_primary_shards$ match_type: regexp action: update new_name: elasticsearch.cluster.shards operations: - action: add_label new_label: state new_value: active_primary - include: ^elasticsearch_cluster_health_initializing_shards$ match_type: regexp action: update new_name: elasticsearch.cluster.shards operations: - action: add_label new_label: state new_value: initializing - include: ^elasticsearch_cluster_health_relocating_shards$ match_type: regexp action: update new_name: elasticsearch.cluster.shards operations: - action: add_label new_label: state new_value: relocating - include: ^elasticsearch_cluster_health_unassigned_shards$ match_type: regexp action: update new_name: elasticsearch.cluster.shards operations: - action: add_label new_label: state new_value: unassigned - include: ^elasticsearch_indices_docs$ match_type: regexp action: insert new_name: elasticsearch.node.documents operations: - action: add_label new_label: state new_value: active - include: ^elasticsearch_indices_docs$ match_type: regexp action: insert new_name: elasticsearch.index.documents operations: - action: add_label new_label: state new_value: active - action: add_label new_label: aggregation new_value: primary_shards - action: add_label new_label: elasticsearch.index.name new_value: _all - include: ^elasticsearch_indices_docs_deleted$ match_type: regexp action: insert new_name: elasticsearch.node.documents operations: - action: add_label new_label: state new_value: deleted - include: ^elasticsearch_indices_fielddata_evictions$ match_type: regexp action: update new_name: elasticsearch.node.cache.evictions operations: - action: add_label new_label: cache_name new_value: fielddata - include: ^elasticsearch_indices_query_cache_evictions$ match_type: regexp action: update new_name: elasticsearch.node.cache.evictions operations: - action: add_label new_label: cache_name new_value: query - include: ^elasticsearch_indices_fielddata_memory_size_bytes$ match_type: regexp action: update new_name: elasticsearch.node.cache.memory.usage operations: - action: add_label new_label: cache_name new_value: fielddata - include: ^elasticsearch_indices_query_cache_memory_size_bytes$ match_type: regexp action: update new_name: elasticsearch.node.cache.memory.usage operations: - action: add_label new_label: cache_name new_value: query - include: ^elasticsearch_transport_rx_size_bytes_total$ match_type: regexp action: update new_name: elasticsearch.node.cluster.io operations: - action: add_label new_label: direction new_value: received - include: ^elasticsearch_transport_tx_size_bytes_total$ match_type: regexp action: update new_name: elasticsearch.node.cluster.io operations: - action: add_label new_label: direction new_value: sent - include: ^elasticsearch_filesystem_data_available_bytes$ match_type: regexp action: update new_name: elasticsearch.node.fs.disk.available - include: ^elasticsearch_filesystem_data_size_bytes$ match_type: regexp action: update new_name: elasticsearch.node.fs.disk.total - include: ^elasticsearch_process_open_files_count$ match_type: regexp action: update new_name: elasticsearch.node.open_files - include: ^elasticsearch_indices_indexing_index_total$ match_type: regexp action: update new_name: elasticsearch.node.operations.completed operations: - action: add_label new_label: operation new_value: index - include: ^elasticsearch_indices_search_query_total$ match_type: regexp action: update new_name: elasticsearch.node.operations.completed operations: - action: add_label new_label: operation new_value: query - include: ^elasticsearch_indices_get_total$ match_type: regexp action: update new_name: elasticsearch.node.operations.completed operations: - action: add_label new_label: operation new_value: get - include: ^elasticsearch_indices_merges_total$ match_type: regexp action: update new_name: elasticsearch.node.operations.completed operations: - action: add_label new_label: operation new_value: merge - include: ^elasticsearch_indices_indexing_index_time_seconds_total$ match_type: regexp action: update new_name: elasticsearch.node.operations.time operations: - action: add_label new_label: operation new_value: index - action: experimental_scale_value experimental_scale: 1000 - include: ^elasticsearch_indices_search_query_time_seconds$ match_type: regexp action: update new_name: elasticsearch.node.operations.time operations: - action: add_label new_label: operation new_value: query - action: experimental_scale_value experimental_scale: 1000 - include: ^elasticsearch_thread_pool_active_count$ match_type: regexp action: insert new_name: elasticsearch.node.operations.current operations: - action: update_label label: type new_label: operation - include: ^elasticsearch_os_cpu_percent$ match_type: regexp action: update new_name: elasticsearch.os.cpu.usage - include: ^elasticsearch_os_load1$ match_type: regexp action: update new_name: elasticsearch.os.cpu.load_avg.1m - include: ^elasticsearch_os_load5$ match_type: regexp action: update new_name: elasticsearch.os.cpu.load_avg.5m - include: ^elasticsearch_os_load15$ match_type: regexp action: update new_name: elasticsearch.os.cpu.load_avg.15m - include: ^elasticsearch_jvm_gc_collection_seconds_count$ match_type: regexp action: update new_name: jvm.gc.collections.count - include: ^elasticsearch_jvm_gc_collection_seconds_sum$ match_type: regexp action: update new_name: jvm.gc.collections.elapsed operations: - action: experimental_scale_value experimental_scale: 1000 - include: ^elasticsearch_jvm_memory_max_bytes$ match_type: regexp action: update new_name: jvm.memory.heap.max - include: ^elasticsearch_jvm_memory_used_bytes$ match_type: regexp action: update new_name: jvm.memory.heap.used - include: ^elasticsearch_thread_pool_threads_count$ match_type: regexp action: update new_name: jvm.threads.count operations: - action: aggregate_labels label_set: [name, cluster] aggregation_type: sum - include: ^elasticsearch_indices_segments_count$ match_type: regexp action: update new_name: elasticsearch.index.segments.count
filter/allowed_metrics: metrics: include: match_type: strict metric_names: - elasticsearch.cluster.data_nodes - elasticsearch.cluster.health - elasticsearch.cluster.in_flight_fetch - elasticsearch.cluster.nodes - elasticsearch.cluster.pending_tasks - elasticsearch.cluster.shards - elasticsearch.index.documents - elasticsearch.index.segments.count - elasticsearch.node.cache.evictions - elasticsearch.node.cache.memory.usage - elasticsearch.node.cluster.io - elasticsearch.node.documents - elasticsearch.node.fs.disk.available - elasticsearch.node.fs.disk.total - elasticsearch.node.open_files - elasticsearch.node.operations.completed - elasticsearch.node.operations.current - elasticsearch.node.operations.time - elasticsearch.os.cpu.usage - elasticsearch.os.cpu.load_avg.1m - elasticsearch.os.cpu.load_avg.5m - elasticsearch.os.cpu.load_avg.15m - jvm.gc.collections.count - jvm.gc.collections.elapsed - jvm.memory.heap.max - jvm.memory.heap.used - jvm.threads.count
transform/rename_node_name: metric_statements: - context: datapoint statements: - set(attributes["elasticsearch.node.name"], attributes["name"]) where attributes["name"] != nil - delete_key(attributes, "name") where attributes["elasticsearch.node.name"] != nil
groupbyattrs/node: keys: - elasticsearch.node.name - elasticsearch.cluster.name
cumulativetodelta: {}
resource/cluster_name_override: attributes: - key: elasticsearch.cluster.name value: "<YOUR_ELASTICSEARCH_CLUSTER_NAME>" action: upsert
transform/scope_override: metric_statements: - context: scope statements: - set(name, "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/elasticsearchreceiver") - set(version, "")
resourcedetection: detectors: [system] system: resource_attributes: host.name: enabled: true host.id: enabled: true os.type: enabled: true
batch: timeout: 30s send_batch_size: 2048 send_batch_max_size: 4096
attributes/cardinality_reduction: actions: - key: process.pid action: delete - key: process.parent_pid action: delete
transform/metadata_nullify: metric_statements: - context: metric statements: - set(description, "") - set(unit, "")
exporters: otlphttp: endpoint: ${env:NEWRELIC_OTLP_ENDPOINT} headers: api-key: ${env:NEWRELIC_LICENSE_KEY} compression: gzip timeout: 30s retry_on_failure: enabled: true initial_interval: 5s max_interval: 30s max_elapsed_time: 300s
service: pipelines: metrics/elasticsearch: receivers: [prometheus/elasticsearch] processors: - memory_limiter - metricstransform/prom_to_otel - filter/allowed_metrics - transform/rename_node_name - groupbyattrs/node - transform/scope_override - resourcedetection - resource/cluster_name_override - attributes/cardinality_reduction - cumulativetodelta - transform/metadata_nullify - batch exporters: [otlphttp]Parámetro de configuración
La siguiente tabla describe los parámetros de configuración clave utilizados en la configuración anterior:
| Parámetro | Descripción |
|---|---|
targets | La dirección del elasticsearch_exporter, actualizando localhost:9114 si se ejecuta en un host o puerto diferente. |
elasticsearch.cluster.name (en resource/cluster_name_override) | Un nombre único que identifica este clúster en New Relic, reemplazando <YOUR_ELASTICSEARCH_CLUSTER_NAME> con un nombre que sea único en toda su cuenta. |
NEW_RELIC_MEMORY_LIMIT_MIB | El límite de memoria, en MiB, para el procesador memory_limiter del recolector, configurado para adaptarse al entorno. |
NEWRELIC_LICENSE_KEY | Su clave de licencia de New Relic. |
NEWRELIC_OTLP_ENDPOINT | El extremo OTLP de New Relic para la región de la cuenta, según los extremos OTLP de New Relic. |
Establezca las variables de entorno
Reemplace <collector-service> en los comandos a continuación con nrdot-collector o otelcol-contrib, según el recolector que esté utilizando. Luego, configure las credenciales y los detalles de conexión que el recolector necesita para enviar datos a New Relic.
$sudo mkdir -p /etc/systemd/system/<collector-service>.service.d$cat <<EOF | sudo tee /etc/systemd/system/<collector-service>.service.d/environment.conf$[Service]$Environment="NEWRELIC_OTLP_ENDPOINT=<YOUR_NEWRELIC_OTLP_ENDPOINT>"$Environment="NEWRELIC_LICENSE_KEY=<YOUR_NEWRELIC_LICENSE_KEY>"$Environment="NEW_RELIC_MEMORY_LIMIT_MIB=100"$EOFReinicie el recopilador
Reinicie el recolector para aplicar los cambios, utilizando el mismo valor <collector-service> que en el paso anterior:
$sudo systemctl daemon-reload$sudo systemctl enable <collector-service>$sudo systemctl restart <collector-service>Verificar la recopilación de datos
En un plazo de -5 minutos después de reiniciar el recolector, ejecute esta consulta en New Relic para confirmar que los datos están fluyendo (reemplace <YOUR_ELASTICSEARCH_CLUSTER_NAME> por el nombre del clúster):
FROM Metric SELECT count(*)WHERE metricName LIKE 'elasticsearch.%'AND elasticsearch.cluster.name = '<YOUR_ELASTICSEARCH_CLUSTER_NAME>'SINCE 10 minutes agoSugerencia
También puede verificar el recolector en sí. Debería reportar active (running) (sudo systemctl status <collector-service>), sin errores de conexión en los logs (sudo journalctl -u <collector-service> -f).
Si no ve datos en -5 minutos, consulte la resolución de problemas de Elasticsearch.
Encuentra y utiliza tus datos
Una vez que New Relic recopile los datos, puede acceder al monitoreo de Elasticsearch a través de la UI de New Relic.
Para buscar el dashboard de Elasticsearch en New Relic:
- Vaya a one.newrelic.com > Integrations & Agents.
- En la pestaña All, haga clic en Dashboards, luego busque Elasticsearch (OpenTelemetry Collector) para ver el dashboard.
O, desde la navegación de la izquierda:
- Haga clic en Dashboards.
- Busque el dashboard Elasticsearch (OpenTelemetry Collector) para verlo.
Después de configurar el monitoreo de Elasticsearch, puede:
- Cree un dashboard personalizado para visualizar las métricas de Elasticsearch
- Configure alertas para umbrales críticos de estado y rendimiento del clúster
- Explore los datos con las capacidades de consulta de New Relic
Sugerencia
Correlacione APM con Elasticsearch: para conectar la aplicación APM y el clúster de Elasticsearch, incluya el atributo de recurso es.cluster.name="your-cluster-name" en las métricas de APM. Esto le permite ver los datos de APM y Elasticsearch juntos en New Relic.