- Move the Prometheus and grafana configuration in a dedicated directory and docker-compose file.
- Add documentation about setting-up prometheus and grafana.
This commit is contained in:
parent
a8eea1ccf4
commit
b499209ce3
|
@ -3,7 +3,6 @@ version: '3.3'
|
|||
services:
|
||||
|
||||
urls_controller:
|
||||
profiles: ["onlyController", "all"]
|
||||
image: 'pdf_aggregation_service/urls_controller:latest'
|
||||
ports:
|
||||
- '1880:1880'
|
||||
|
@ -26,23 +25,3 @@ services:
|
|||
build:
|
||||
dockerfile: ./Dockerfile
|
||||
context: .
|
||||
|
||||
prometheus:
|
||||
profiles: ["all"]
|
||||
image: 'prom/prometheus:latest'
|
||||
ports:
|
||||
- '9090:9090'
|
||||
command: '--config.file=/etc/prometheus/config.yml'
|
||||
volumes:
|
||||
- './src/main/resources/prometheus.yml:/etc/prometheus/config.yml'
|
||||
depends_on:
|
||||
- urls_controller
|
||||
|
||||
grafana:
|
||||
profiles: ["all"]
|
||||
image: 'grafana/grafana:latest'
|
||||
ports:
|
||||
- '3000:3000'
|
||||
depends_on:
|
||||
- urls_controller
|
||||
- prometheus
|
||||
|
|
|
@ -49,23 +49,25 @@ if [[ justInstall -eq 0 ]]; then
|
|||
|
||||
if [[ shouldRunInDocker -eq 1 ]]; then
|
||||
|
||||
runPrometheusAndGrafanaContainers=0
|
||||
runPrometheusAndGrafanaContainers=0 # This is set here, not through cmd-args.
|
||||
|
||||
echo -e "\nBuilding the docker image and running the containers..\n"
|
||||
sudo docker --version || handle_error "Docker was not found!" 3
|
||||
(sudo mkdir -p "$HOME"/tmp/config && sudo cp ./src/main/resources/application.yml "$HOME"/tmp/config) || true # This also replaces an existing "application.yml".
|
||||
sudo mkdir -p "$HOME"/logs || true
|
||||
|
||||
if [[ runPrometheusAndGrafanaContainers -eq 1 ]]; then
|
||||
(sudo docker compose --profile all up --build -d && echo -e "\nThe Urls_Controller, Prometheus and Grafana docker-containers started running.\nWaiting 65 seconds before getting their status..\n") || handle_error "Could not list docker containers!" 4
|
||||
else
|
||||
(sudo docker compose --profile onlyController up --build -d && echo -e "\nThe Urls_Controller docker-container started running.\nWaiting 65 seconds before getting its status..\n") || handle_error "Could not list docker containers!" 4
|
||||
fi
|
||||
# Run in "detached mode" -d (in the background).
|
||||
(sudo docker compose up --build -d && echo -e "\nThe Urls_Controller docker-container started running.\n") || handle_error "Could not build and/or run the 'urls_controller' docker container!" 4
|
||||
|
||||
if [[ runPrometheusAndGrafanaContainers -eq 1 ]]; then
|
||||
(sudo docker compose -f prometheus/docker-compose-prometheus.yml up --build -d && echo -e "\nThe Prometheus and Grafana docker-containers started running.\n") || handle_error "Could not build and/or run the 'prometheus' and/or 'grafana' docker containers!" 5
|
||||
fi
|
||||
|
||||
echo -e "Waiting 65 seconds before getting the status..\n"
|
||||
sleep 65
|
||||
sudo docker ps -a || handle_error "Could not get the status of docker-containers!" 5 # Using -a to get the status of failed containers as well.
|
||||
sudo docker ps -a || handle_error "Could not get the status of docker-containers!" 6 # Using -a to get the status of failed containers as well.
|
||||
echo -e "\n\nGetting the logs of docker-container \"urlscontroller-urls_controller-1\":\n"
|
||||
sudo docker logs "$(sudo docker ps -aqf "name=^urlscontroller-urls_controller-1$")" || handle_error "Could not get the logs of docker-container \"urlscontroller-urls_controller-1\"!" 6 # Using "regex anchors" to avoid false-positives. Works even if the container is not running, thus showing the error-log.
|
||||
sudo docker logs "$(sudo docker ps -aqf "name=^urlscontroller-urls_controller-1$")" || handle_error "Could not get the logs of docker-container \"urlscontroller-urls_controller-1\"!" 7 # Using "regex anchors" to avoid false-positives. Works even if the container is not running, thus showing the error-log.
|
||||
fi
|
||||
else
|
||||
export PATH=/opt/gradle/gradle-${gradleVersion}/bin:$PATH # Make sure the gradle is still accessible (it usually isn't without the "export").
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Visualize Prometheus metrics
|
||||
|
||||
### Requirements
|
||||
- Run the docker-compose of the Controller.
|
||||
- Run the docker-compose of prometheus.
|
||||
|
||||
|
||||
### Check the metrics
|
||||
- To check the raw metrics hit this url in your browser: http://<IP>:1880/api/actuator/prometheus
|
||||
- To check the metrics though GUI, with some graphs, hit: http://<IP>:9090
|
||||
|
||||
|
||||
### Visualize metrics in Grafana
|
||||
- Access grafana in: http://<IP>:3000/
|
||||
- Give the default username and password: "admin" (for both).
|
||||
- Specify the new password.
|
||||
- Then, add a "Prometheus" datasource.
|
||||
- Specify the prometheus url: http://<IP>:9090
|
||||
- Save the datasource.
|
||||
- Go to "dashboards", click "import", add the number "12900" in the input and click "load" and "next".
|
||||
- Then select the "prometheus" datasource and click "import".
|
||||
- Enjoy the graphs.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
version: '3.3'
|
||||
|
||||
services:
|
||||
|
||||
prometheus:
|
||||
image: 'prom/prometheus:latest'
|
||||
ports:
|
||||
- '9090:9090'
|
||||
command: '--config.file=/etc/prometheus/config.yml'
|
||||
volumes:
|
||||
- './prometheus.yml:/etc/prometheus/config.yml'
|
||||
|
||||
grafana:
|
||||
image: 'grafana/grafana:latest'
|
||||
ports:
|
||||
- '3000:3000'
|
||||
depends_on:
|
||||
- prometheus
|
|
@ -1,8 +1,8 @@
|
|||
echo "Running compose down.."
|
||||
sudo docker compose down
|
||||
sudo docker compose -f ./prometheus/docker-compose-prometheus.yml down
|
||||
sudo docker compose -f docker-compose.yml -f ./prometheus/docker-compose-prometheus.yml down
|
||||
|
||||
echo "Stopping the running container.."
|
||||
sudo docker stop "$(sudo docker ps -aqf "name=^urlscontroller-urls_controller-1$")"
|
||||
|
||||
echo "Removing the container.."
|
||||
sudo docker rm "$(sudo docker ps -aqf "name=^urlscontroller-urls_controller-1$")"
|
||||
# In case we need to hard-remove the containers, use the following commands:
|
||||
#sudo docker stop $(sudo docker ps -aqf "name=^(?:urlscontroller-urls_controller|prometheus-(?:prometheus|grafana))-1$") || true # There may be no active containers
|
||||
#sudo docker rm $(sudo docker ps -aqf "name=^(?:urlscontroller-urls_controller|prometheus-(?:prometheus|grafana))-1$") || true # All containers may be already removed.
|
||||
|
|
Loading…
Reference in New Issue