Project to monitor various services
- Start the containers:
docker-compose up -d
- Initialize the mongodb replica set:
docker exec mongodb1 /scripts/rs-init.sh
- Restart the mongodb-exporter:
docker restart mongodb-exporter
- Create a redis cluster:
docker exec -it redis1 redis-cli -a eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81 --cluster create --cluster-replicas 0 172.29.0.10:6379 172.29.0.11:6380 172.29.0.12:6381 --cluster-yes
- Restart the redis-exporter:
docker restart redis-exporter
$ ./start-monitoring.sh
$ ./stop-monitoring.sh
user: admin
password: admin
- Navigate to the config.yml file inside the config/alertmanager directoy.
- Update the below fields to receive the email alerts:
auth_username: <EMAIL_AUTH_USERNAME> auth_password: <EMAIL_AUTH_PASSWORD> from: <EMAIL_FROM_ADDRESS> to: <EMAIL_TO_ADDRESS>
- We can also update the email template as per our requirement.
Steps to monitor mongodb replica sets: (Some of these steps only applicable if mongo is auth enabled)
- Generate a shared secret key:
openssl rand -base64 741 > replica.key.devel
- Pass this replica key while running the mongo command for each replicaset:
command:mongod --replSet rs0 --auth --bind_ip_all --keyFile /data/replica.key
- Mount this key file in the volume.
- Once all the mongo replicaset instances are ready, initialize them with below command:
docker exec mongodb1 /scripts/rs-init.sh
- Check if the replicaset is configured correctly with below commands:
docker exec -it mongodb1 mongosh -u root -p Enter password: root rs.status() - It will list all the members of the replicaSet out of which only one would be primary node.
- Make sure the mongodb-exporter is running with the below command:
command:--mongodb.uri mongodb://exporter:password@mongodb1:27017/admin?replicaSet=rs0&ssl=false&tls=false
- Restart the mongodb-exporter:
docker restart mongodb-exporter
- The exporter only allows single replica set member:
To monitor a MongoDB replica set with the Percona MongoDB exporter, you need to specify a single replica set member in the MONGODB_URI environment variable. The exporter will then discover the other replica set members by querying the replica set configuration.
- Atleast 3 instances of redis must be added to form a cluster.
- Each redis startup command would look like below:
redis-server --port 6379 --cluster-enabled yes --cluster-config-file /data/nodes.conf --cluster-node-timeout 5000 --requirepass $$REDIS_PASSWORD
- Add the redis_exporter_targets in the prometheus.yml file:
- job_name: 'redis_exporter_targets' static_configs: - targets: - redis://redis1:6379 - redis://redis2:6380 - redis://redis3:6381 metrics_path: /scrape relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: redis-exporter:9121
- Command to create redis cluster after all redis instances are up:
docker exec -it redis1 redis-cli -a eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81 --cluster create --cluster-replicas 0 172.29.0.10:6379 172.29.0.11:6380 172.29.0.12:6381 --cluster-yes
- Restart the redis-exporter:
docker restart redis-exporter
- Check if all redis instances are being monitored:
http://localhost:9121/metrics
http://localhost:9121/scrape?target=redis1:6379
http://localhost:9121/scrape?target=redis2:6380
http://localhost:9121/scrape?target=redis3:6381