The official Solr Image on Docker Hub was released just a few weeks ago and already has 16K pulls. Why not more? Well, there are more than 200 different Solr images on Docker Hub — probably because no official Image was available!
A rapidly growing number of organizations are using Solr and Docker in production and they are probably happy about the new official Image. Needless to say, monitoring Solr is essential in production. Docker is disruptive in many ways, and there are many things that are slightly different and worth mentioning. These include:
- Changed deployment for Solr and its monitoring tools using Dockerfile, Docker Compose or various Orchestration Tools
- There is a new Layer to monitor: Container Metrics and Events, see: Docker Events and Metrics monitoring and SPM for Docker
- Logging has changed: containers log to the console and logs need to be retrieved from Docker-Daemon instead getting them from the Solr log file. Check out our post on the subject: Innovative Docker Log Management
- Official Images may not provide options for monitoring (such as JMX). However, the official Image for Solr provides an option to pass parameters to the Java Runtime Environment. We we will use this option for Solr monitoring in this post.
Next, I’m going to demonstrate the setup of a Solr node with SPM. The final setup will provide the full Solr & Docker Monitoring and Logging package:
- Detailed Application Metrics for Solr, deployed on Docker
- Detailed Container Metrics and Docker Events
- Centralized Logs for all Containers by SPM for Docker
Let’s first decide on one of the following options to monitor Solr on Docker:
- Build your own Solr container with a mix of open-source monitoring/alerting tools. I’m not going to go into detail about this option today because dealing with a mix of open-source DevOps tools and a non-official Solr image doesn’t sound clean; plus, we can do better.
- Use a standalone monitoring agent, which queries metrics from the Solr container. This requires a setup for JMX and Docker networking configurations for the monitor and Solr. The metrics gathered by remote agents are limited and, in the Docker context, running an external monitoring process plus Solr processes consumes more resources. And the next option …
- Inject an SPM in-process monitoring agent into Solr. This option has the lowest resource usage and has support for advanced monitoring functions like Transaction Tracing and AppMap.
We’ll go with Option #3 in this blog post, as it provides the best insights into Solr. Sematext provides the SPM Client (this includes the monitoring agent and metrics sender) pre-installed in a Docker Image. We refer to this dockerized SPM Client as “SPM Client Image/Container” in the following instructions. The main trick here is to mount a volume from SPM Client Container into Solr Containers in order to load the monitoring library that’s part of the SPM Client Container.
Let’s have a look at the desired setup and how to get there:
We’ll use the latest Docker-Compose Version (> v1.5) because we can than use environment variables substitution in Docker-Compose.
1) Configure and start SPM-Client Container
The SPM Token is a unique identifier for monitored applications – if you haven’t created an SPM App for Solr, then create one here first. Should take about 37 seconds.
# Set the SPM Token as Environment Variable export SPM_TOKEN=4feb144c-4da8-4081-83b5-b0b8e06e743a # Set the JVM Name, which appears in SPM JVM Metrics Report # In addition we will use it as Hostname for the Solr container export JVM_NAME=SOLR1
2) Create SPM Client and Solr service in docker-compose.yml Note: you may copy this file to make changes for additional Solr options; all parameters are set as Environment Variables.
spm-client-solr: image: sematext/spm-client container_name: spm-client-solr hostname: spm-client-solr environment: - SPM_CONFIG=${SPM_TOKEN} solr javaagent jvmname:${JVM_NAME} volumes: - /var/run/docker.sock:/var/run/docker.sock SOLR1: image: solr hostname: solr1 ports: - "8983:8983" volumes_from: - spm-client-solr environment: - SOLR_OPTS=-Dcom.sun.management.jmxremote -javaagent:/opt/spm/spm-monitor/lib/spm-monitor-solr.jar=${SPM_TOKEN}::${JVM_NAME} command: bin/solr -f
In the Environment variable “SOLR_OPTS” in the Docker-Compose file above we see options for the SPM in-process monitor to inject a .jar file from the SPM Client Volume. The SOLR_OPTS string is taken from SPM install instructions. It includes the SPM Token (the ${SPM_TOKEN} part) and provides the JVM name so we can distinguish between multiple Solr instances if we run N of them on the same host (the ::${JVM_NAME} part).
3) Run Solr and SPM Monitor
We are now ready to fire up Solr:
docker-compose up -d
All done! After about a minute, metrics for the Docker Host, JVMs and Solr nodes will appear in SPM. Because we chose a consistent naming for Container hostname, and JVM name we can immediately see, in every chart, the relevant filters named “SOLR1”. This is much better than some random Container IDs.
Solr Metrics Overview
But what about my Solr Logs and the Container Metrics?
Simply run SPM for Docker – it collect logs as well as container and host metrics. It can also parse Solr logs and store them in Logsene (see Logsene 1-Click ELK Stack), which is awesome because it means you can have both Solr/OS/JVM metrics AND Solr logs all in one place! Or do you maybe like to ssh to your servers and grep log files?
Docker Logs & Metrics Steps:
First we create the SPM App with the type “Docker” for Docker-specific metrics and then we create a Logsene App for our logs. Then we use the generated App Tokens to run Sematext Agent for Docker.
docker run -d -name sematext-agent -e SPM_TOKEN=SPM_DOCKER_APP_TOKEN -e LOGSENE_TOKEN=LOGSENE_APP_TOKEN sematext/sematext-agent-docker
After a few minutes, you will get Host and Container Metrics together with Events and Logs in SPM, as shown here:
Please note that logs from the containers are automatically shipped and parsed! No setup for log shippers? That is correct — there is NO complicated setup of syslog, Logstash, Docker log drivers, etc. All this work is done by SPM for Docker. For example, each log line has a “node_name” field for the Solr node. It takes the timestamp, severity, class, thread and source from the Solr log and each log is automatically tagged with the container ID and image name. Moving from SPM Metrics to detailed Solr Logs including Exceptions and parsed Stack Traces is just another mouse click away! Look:
The filters next to field stats on the right side of the screen make it easy to identify containers with the most logs by choosing “container_name”. That’s just a little detail in the Logsene UI – feel free to explore it by creating Alerts or Kibana 4 Dashboards for your container logs.
Like what you saw here? To monitor Docker and Solr with SPM just get a free account here! And drop us an email or hit us on Twitter with suggestions, questions or comments. Solr and Docker are topics we enjoy chatting about with the community!