Tutorial: Monitor Redis running on Kubernetes

BETA

This tutorial gives an example of enabling monitoring for a Redis service running on the Kubernetes PHP Guestbook.

This feature is in beta. For questions and feedback, contact the product manager at jjoly @ newrelic.com.

Introduction

If you have a service running on Kubernetes, and it's a service we support, you can enable monitoring of that service by adding a configuration section for that integration to the Kubernetes integration's config file.

This tutorial gives an example of enabling monitoring for a Redis service running on the Kubernetes PHP Guestbook. For the general procedure of how to monitor services running on Kubernetes, see Monitor a Kubernetes-running service.

Requirements

  • See the general requirements for this feature, including supported services.
  • The kubectl command-line tool must be configured to communicate with your cluster. If you don't have a cluster, you can create one using Minikube.

Step 1: Set up an example Redis application

Before starting, ensure you meet the requirements.

This tutorial builds on the Kubernetes tutorial Deploying a PHP Guestbook application with Redis. You have two options:

  • Recommended. If you'd like to skip doing the Kubernetes tutorial, run the following command to set up the application needed for our tutorial:

    kubectl create -f https://raw.githubusercontent.com/kubernetes/examples/master/guestbook/all-in-one/guestbook-all-in-one.yaml
    
  • If you'd like to first complete the Kubernetes tutorial, follow their tutorial instructions but do not follow the instructions in the Cleaning up section.

Step 2: Enable monitoring of Redis instances

The PHP Guestbook application has three Redis instances: one master and two slave instances. Each instance is tagged with a label where app=redis. For this example, we're using our Redis monitoring integration. It can monitor both master and slave instances of Redis, so we don’t have to distinguish between them.

  1. In the Kubernetes integration's YAML config file (newrelic-infrastructure-k8s-latest.yaml), you need to update the nri-integration-cfg section. From the list of integration configs, get the Redis integration YAML and add it to the Kubernetes config. The Redis YAML is highlighted below.

    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: nri-integration-cfg
      namespace: default
    data:
      redis-config.yml: |
        ---
        # Run auto discovery to find pods with label "app=redis"
        # https://docs.newrelic.com/docs/integrations/host-integrations/installation/container-auto-discovery
        discovery:
          command:
            # Run NRI Discovery for Kubernetes
            # https://github.com/newrelic/nri-discovery-kubernetes
            exec: /var/db/newrelic-infra/nri-discovery-kubernetes
            match:
              label.app: redis
        integrations:
          - name: nri-redis
            env:
              # using the discovered IP as the hostname address
              HOSTNAME: ${discovery.ip}
              PORT: 6379
              KEYS: '{"0":["<KEY_1>"],"1":["<KEY_2>"]}'
              REMOTE_MONITORING: true
            labels:
              env: production
    
  2. Deploy the updated service:
    kubectl create -f newrelic-infrastructure-k8s-latest.yaml
    

    You should be able to see the following in the logs for the pod newrelic-infra:

    time="2019-12-23T17:37:07Z" level=info msg="Integration health check starting" instance=redis-metrics integration=com.newrelic.redis prefix=integration/com.newrelic.redis working-dir=/var/db/newrelic-infra/newrelic-integrations
    time="2019-12-23T17:37:07Z" level=info msg="Integration health check finished with success" instance=redis-metrics integration=com.newrelic.redis prefix=integration/com.newrelic.redis working-dir=/var/db/newrelic-infra/newrelic-integrations
    

If there are no errors, you should see Redis data in the Infrastructure UI. To find the Redis dashboards: Go to infrastructure.newrelic.com > Third party services, and select the Redis dashboard.

For the general procedure of how to monitor services running on Kubernetes, including more detail about how configuration works, see Monitor a Kubernetes-running service.

Recommendations for learning more: