Skip to content

Commit

Permalink
Add redis example
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Jun 5, 2024
1 parent a6b838e commit f993017
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ OpenTelemetry is a big ecosystem and everything doesn't fit into the goals of th

* 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)
* [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)
Expand Down
7 changes: 7 additions & 0 deletions other-examples/collector/redis/.env
Original file line number Diff line number Diff line change
@@ -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/
35 changes: 35 additions & 0 deletions other-examples/collector/redis/README.md
Original file line number Diff line number Diff line change
@@ -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=<your_license_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.
39 changes: 39 additions & 0 deletions other-examples/collector/redis/collector.yaml
Original file line number Diff line number Diff line change
@@ -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]
23 changes: 23 additions & 0 deletions other-examples/collector/redis/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f993017

Please sign in to comment.