From 5f5d298cc1a6fcfabc4d118d57dcc2f97a335dfa Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Wed, 5 Jun 2024 14:55:20 -0500 Subject: [PATCH] Add redis example --- README.md | 11 +++--- other-examples/collector/redis/.env | 7 ++++ other-examples/collector/redis/README.md | 35 +++++++++++++++++ other-examples/collector/redis/collector.yaml | 39 +++++++++++++++++++ .../collector/redis/docker-compose.yaml | 23 +++++++++++ 5 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 other-examples/collector/redis/.env create mode 100644 other-examples/collector/redis/README.md create mode 100644 other-examples/collector/redis/collector.yaml create mode 100644 other-examples/collector/redis/docker-compose.yaml diff --git a/README.md b/README.md index 25a41b20..4a846dec 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,12 @@ The [Getting Started Guides](./getting-started-guides/README.md) demonstrate how OpenTelemetry is a big ecosystem and everything doesn't fit into the goals of the [getting started guides](#getting-started-guides). These "other examples" demonstrate how other areas of OpenTelemetry fit in with New Relic. * Collector - * [OpenTelemetry Collector with OTLP and New Relic](./other-examples/collector/nr-config) - * [OpenTelemetry Collector with Host Monitoring and New Relic](./other-examples/collector/host-monitoring) - * [OpenTelemetry Collector with Confluent Cloud and New Relic](./other-examples/collector/confluentcloud) - * [OpenTelemetry Collector with Singlestore and New Relic](./other-examples/collector/singlestore) - * [OpenTelemetry Collector with HCP Consul and New Relic](./other-examples/collector/hcp-consul) + * [Telemetry data processing](./other-examples/collector/nr-config) + * [Host monitoring](./other-examples/collector/host-monitoring) + * [Confluent cloud monitoring](./other-examples/collector/confluentcloud) + * [Singlestore monitoring](./other-examples/collector/singlestore) + * [HCP Consul monitoring](./other-examples/collector/hcp-consul) + * [Redis monitoring](./other-examples/collector/redis) * Java * [OpenTelemetry Agent New Relic Config](./other-examples/java/agent-nr-config) * [Micrometer Shim with OTLP Export](./other-examples/java/micrometer-shim) diff --git a/other-examples/collector/redis/.env b/other-examples/collector/redis/.env new file mode 100644 index 00000000..5ea44511 --- /dev/null +++ b/other-examples/collector/redis/.env @@ -0,0 +1,7 @@ +# New Relic API key to authenticate the call. +# docs: https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key +NEW_RELIC_API_KEY= + +# The default US endpoint is set here. You can change the endpoint and port based on your requirements if needed. +# docs: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/best-practices/opentelemetry-otlp/#configure-endpoint-port-protocol +NEW_RELIC_OTLP_ENDPOINT=https://otlp.nr-data.net/ diff --git a/other-examples/collector/redis/README.md b/other-examples/collector/redis/README.md new file mode 100644 index 00000000..3ba39413 --- /dev/null +++ b/other-examples/collector/redis/README.md @@ -0,0 +1,35 @@ +# Monitoring Redis with OpenTelemetry Collector + +This simple example demonstrates monitoring redis with the [OpenTelemetry collector](https://opentelemetry.io/docs/collector/), using the [redis receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/redisreceiver) and sending the data to New Relic via OTLP. + +## Requirements + +* [Docker compose](https://docs.docker.com/compose/) must be installed and the docker daemon must be running. +* [A New Relic account](https://one.newrelic.com/) +* [A New Relic license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key) + +## Running the application + +1. Set the following environment variables to configure OpenTelemetry to send + data to New Relic: + + ```shell + export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net + export OTEL_EXPORTER_OTLP_HEADERS=api-key= + ``` + + * If your account is based in the EU, set the endpoint to: [https://otlp.eu01.nr-data.net](https://otlp.eu01.nr-data.net) + +2. Run the application with the following command. + + ```shell + docker compose up + ``` + +## Viewing your data + +To review your redis data in New Relic, navigate to "New Relic -> All Entities -> Redis instances" and click on the instance with name "redis" to view the instance summary. Click on "Metric explorer" to view all metrics associated with the redis instance, or use [NRQL](https://docs.newrelic.com/docs/query-your-data/explore-query-data/get-started/introduction-querying-new-relic-data/) to perform ad-hoc analysis. + +## Additional notes + +This example monitors a redis instance defined in [docker-compose.yaml](docker-compose.yaml), which is not receiving any load. To use in production, you'll need to modify the `.receivers.redis.endpoint` value in [collector.yaml](./collector.yaml) to point to the endpoint of your redis instance. diff --git a/other-examples/collector/redis/collector.yaml b/other-examples/collector/redis/collector.yaml new file mode 100644 index 00000000..3c0301e5 --- /dev/null +++ b/other-examples/collector/redis/collector.yaml @@ -0,0 +1,39 @@ +receivers: + redis: + endpoint: ${REDIS_HOST}:${REDIS_PORT} + metrics: + # Enable redis.maxmemory optional metric + redis.maxmemory: + enabled: true + +processors: + batch: + # This is required for New Relic entity synthesis. The redis receiver does not currently include any identifying attributes on the metrics it produces. + attributes/redis_metrics: + include: + match_type: regexp + metric_names: + # Notice that if with single or without quotes just one backslash is needed 'redis\..*' + - "redis\\..*" + actions: + - action: upsert + key: server.address + value: ${REDIS_HOST} + - action: upsert + key: server.port + value: ${REDIS_PORT} + +exporters: + logging: + verbosity: detailed + otlphttp: + endpoint: $NEW_RELIC_OTLP_ENDPOINT + headers: + api-key: $NEW_RELIC_API_KEY + +service: + pipelines: + metrics: + receivers: [redis] + processors: [attributes/redis_metrics, batch] + exporters: [logging, otlphttp] diff --git a/other-examples/collector/redis/docker-compose.yaml b/other-examples/collector/redis/docker-compose.yaml new file mode 100644 index 00000000..4c91ff6d --- /dev/null +++ b/other-examples/collector/redis/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3' +services: + redis: + image: redis:7.2-alpine + user: redis + deploy: + resources: + limits: + memory: 20M + restart: unless-stopped + ports: + - "6379" + + collector: + image: otel/opentelemetry-collector-contrib:0.92.0 + command: --config=/etc/otelcol/config.yaml + volumes: + - ./collector.yaml:/etc/otelcol/config.yaml + environment: + - REDIS_HOST=redis + - REDIS_PORT=6379 + - NEW_RELIC_OTLP_ENDPOINT + - NEW_RELIC_API_KEY