Skip to content

Commit 1801248

Browse files
committed
adding docker, vault, nomad and consul monitoring via prometheus and grafana
1 parent ffc0400 commit 1801248

18 files changed

+133
-38
lines changed

docker/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
557557
user.local.dev: vagrant ssh -c "docker exec -it apache2 /bin/bash -c "apache2 -t -v""
558558
```
559559

560+
## Monitoring Docker
561+
562+
We use Prometheus and Grafana to Monitor Docker
563+
564+
See: [__Monitoring Docker__](prometheus-grafana/README?id=monitoring-docker)
565+
560566
## Docker Vagrant Provisioner
561567

562568
[filename](docker.sh ':include :type=code')

docker/docker.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sudo apt-get update -qq < /dev/null > /dev/null
2121
sudo DEBIAN_FRONTEND=noninteractive apt-get install -qq --allow-downgrades --assume-yes docker-ce=5:20.10.9~3-0~ubuntu-focal docker-ce-cli containerd.io=1.5.11-1 docker-compose-plugin < /dev/null > /dev/null
2222
sudo usermod -aG docker vagrant
2323
sudo mkdir -p /etc/docker
24+
# https://docs.docker.com/config/daemon/prometheus/
2425
sudo echo '{
2526
"metrics-addr": "0.0.0.0:9323",
2627
"experimental": true,

hashicorp/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
675675
```
676676
![Consul](images/consul.png?raw=true "Consul")
677677

678+
## Monitoring Hashicorp Consul
679+
680+
We use Prometheus and Grafana to Monitor Consul
681+
682+
See: [__Monitoring Hashicorp Consul__](prometheus-grafana/README?id=monitoring-hashicorp-consul)
683+
678684
## Consul Vagrant Provisioner
679685

680686
[filename](consul.sh ':include :type=code')

hashicorp/consul.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ui_config {
5151
# https://grafana.com/grafana/dashboards/13396-consul-server-monitoring/
5252
# https://developer.hashicorp.com/consul/docs/agent/telemetry
5353
telemetry {
54-
prometheus_retention_time = 24h
54+
prometheus_retention_time = "24h"
5555
disable_hostname = true
5656
}
5757
EOF
@@ -121,8 +121,8 @@ StartLimitBurst=3
121121
122122
## Configure unit start rate limiting. Units which are started more than
123123
## *burst* times within an *interval* time span are not permitted to start any
124-
## more. Use `StartLimitIntervalSec` or `StartLimitInterval` (depending on
125-
## systemd version) to configure the checking interval and `StartLimitBurst`
124+
## more. Use StartLimitIntervalSec or StartLimitInterval (depending on
125+
## systemd version) to configure the checking interval and StartLimitBurst
126126
## to configure how many starts per interval are allowed. The values in the
127127
## commented lines are defaults.
128128

hashicorp/nomad.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ StartLimitBurst=3
110110
111111
## Configure unit start rate limiting. Units which are started more than
112112
## *burst* times within an *interval* time span are not permitted to start any
113-
## more. Use `StartLimitIntervalSec` or `StartLimitInterval` (depending on
114-
## systemd version) to configure the checking interval and `StartLimitBurst`
113+
## more. Use StartLimitIntervalSec or StartLimitInterval (depending on
114+
## systemd version) to configure the checking interval and StartLimitBurst
115115
## to configure how many starts per interval are allowed. The values in the
116116
## commented lines are defaults.
117117

prometheus-grafana/README.md

+88-17
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Prometheus is an open source monitoring system for which Grafana provides out-of
1616

1717
In order to provision Prometheus and Grafana, you need bastetools, docker, minikube as dependencies.
1818

19-
:bulb: We enable Vault, because we monitor it with Prometheus and we enable Minikube because we host Grafana and Prometheus on Minikkube using Helm
19+
:bulb: We enable Vault, Consul and Nomad, because we monitor these with Prometheus and we enable Minikube because we host Grafana and Prometheus on Minikkube and deploy it using Helm
2020

21-
`vagrant up --provision-with basetools,docker,vault,minikube,prometheus-grafana`
21+
`vagrant up --provision-with basetools,docker,docsify,vault,consul,nomad,minikube,prometheus-grafana`
2222

2323
Prometheus http://localhost:9090 <br />
2424
Alertmanager http://localhost:9093 <br />
@@ -56,12 +56,20 @@ You can also open Prometheus web interface and look at Status -> Targets
5656

5757
![Prometheus Targets](images/prometheus.png?raw=true "Prometheus Targets")
5858

59+
## Grafana Datasource Prometheus
60+
61+
:bulb: We have done this automatically during the provisioning step, in the grafana-values.yaml file see below
62+
63+
[filename](grafana-values.yaml ':include :type=code')
64+
5965
To use Prometheus as a Datasource in Grafana, we need to add it so let's do that now, please head over to Grafana on http://localhost:3000 and login with user: `admin` and the password: `TOKEN_IN_TERMINAL_OUTPUT`
6066

6167
![Grafana Login](images/grafana.png?raw=true "Grafana Login")
6268

6369
Click on Configuration -> Datasources
6470

71+
:bulb: We have done this automatically during the provisioning step
72+
6573
Click add Data sources
6674
Select Prometheus and enter the URL of Prometheus, in this case we will use http://10.9.99.10:9090
6775

@@ -91,23 +99,27 @@ telemetry {
9199
}
92100
```
93101

94-
When we install Prometheus with Helm we set a values.yaml file that specify an `extraScrapeConfigs` You guessed it! Vault...
102+
When we install Prometheus with Helm we set a prometheus-values.yaml file that specify an `extraScrapeConfigs` You guessed it! Vault...
95103

96-
`helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/values.yaml`
104+
`helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/prometheus-values.yaml`
97105

98-
[filename](values.yaml ':include :type=code')
106+
[filename](prometheus-values.yaml ':include :type=code')
99107

100108
You should now see the Vault target in Prometheus web interface at http://localhost:9090/targets
101109

102110
![Prometheus Vault Target](images/prometheus-targets-vault.png?raw=true "Prometheus Vault Target")
103111

104-
We now need to Grafana Datasource of Type Prometheus based on this Target
112+
## Grafana Datasource Prometheus
105113

106-
Please navigate to http://localhost:3000/connections/your-connections/datasources
114+
:bulb: We have done this automatically during the provisioning step, in the grafana-values.yaml file see below
115+
116+
[filename](grafana-values.yaml ':include :type=code')
107117

108-
And add a Vault Datasource
118+
We now need to add a Grafana Datasource of Type Prometheus based on these Targets
109119

110-
Name: Vault
120+
Please navigate to http://localhost:3000/connections/your-connections/datasources
121+
122+
Name: Prometheus <br />
111123
URL: http://10.9.99.10:9090
112124

113125
![Grafana Datasource Prometheus Vault](images/grafana-datasource-prometheus-vault.png?raw=true "Grafana Datasource Prometheus Vault")
@@ -148,11 +160,11 @@ telemetry {
148160
}
149161
```
150162

151-
When we install Prometheus with Helm we set a values.yaml file that specify an `extraScrapeConfigs` You guessed it! Nomad...
163+
When we install Prometheus with Helm we set a prometheus-values.yaml file that specify an `extraScrapeConfigs` You guessed it! Nomad...
152164

153-
`helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/values.yaml`
165+
`helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/prometheus-values.yaml`
154166

155-
[filename](values.yaml ':include :type=code')
167+
[filename](prometheus-values.yaml ':include :type=code')
156168

157169
You should now see the Nomad target in Prometheus web interface at http://localhost:9090/targets
158170

@@ -169,17 +181,76 @@ URL: http://10.9.99.10:9090
169181

170182
![Grafana Datasource Prometheus Nomad](images/grafana-datasource-prometheus-vault.png?raw=true "Grafana Datasource Prometheus Nomad")
171183

172-
Now, let's import the Nomad Grafana Dashboard, to do that, click on the top right + and select `Import Dashboard` ref: https://grafana.com/grafana/dashboards/12904-hashicorp-vault/
184+
Now, let's import the Nomad Grafana Dashboard, to do that, click on the top right + and select `Import Dashboard` ref: https://grafana.com/grafana/dashboards/12787-nomad-jobs/
173185

174-
![Grafana Import Dashboard Nomad 12904](images/grafana-import-dashboard-vault-12904.png?raw=true "Grafana Import Dashboard Vault 12904")
186+
![Grafana Import Dashboard Nomad 12787](images/grafana-import-dashboard-nomad-12787.png?raw=true "Grafana Import Dashboard Vault 12787")
175187

176-
Enter `12904` and click on Load
188+
Enter `12787` and click on Load
177189

178-
![Grafana Import Dashboard Vault 12904 Load](images/grafana-import-dashboard-vault-12904-load.png?raw=true "Grafana Import Dashboard Vault 12904 Load")
190+
![Grafana Import Dashboard Nomad 12787 Load](images/grafana-import-dashboard-nomad-12787-load.png?raw=true "Grafana Import Dashboard Nomad 12787 Load")
179191

180192
Navigating to Grafana -> Dashboards you should now be able to see the Hashicorp Nomad Grafana Dashboard
181193

182-
![Grafana Hashicorp Nomad Dashboard](images/grafana-hashicorp-vault-dashboard.png?raw=true "Grafana Hashicorp Nomad Dashboard")
194+
![Grafana Hashicorp Nomad Dashboard](images/grafana-hashicorp-nomad-dashboard.png?raw=true "Grafana Hashicorp Nomad Dashboard")
195+
196+
## Monitoring Hashicorp Consul
197+
198+
https://lvinsf.medium.com/monitor-consul-using-prometheus-and-grafana-1f2354cc002f <br />
199+
https://grafana.com/grafana/dashboards/13396-consul-server-monitoring/ <br />
200+
https://developer.hashicorp.com/consul/docs/agent/telemetry
201+
202+
In hashicorp/consul.sh we enabled Telemetry in the Consul config file see `hashicorp/consul.sh`
203+
204+
```hcl
205+
# https://lvinsf.medium.com/monitor-consul-using-prometheus-and-grafana-1f2354cc002f
206+
# https://grafana.com/grafana/dashboards/13396-consul-server-monitoring/
207+
# https://developer.hashicorp.com/consul/docs/agent/telemetry
208+
telemetry {
209+
prometheus_retention_time = "24h"
210+
disable_hostname = true
211+
}
212+
```
213+
214+
Now, let's import the Consul Grafana Dashboard, to do that, click on the top right + and select `Import Dashboard` ref: https://grafana.com/grafana/dashboards/2351-consul/
215+
216+
![Grafana Import Dashboard Consul 2351](images/grafana-import-dashboard-consul-2351.png?raw=true "Grafana Import Dashboard Consul 2351")
217+
218+
Enter `2351` and click on Load
219+
220+
![Grafana Import Dashboard Consul 2351 Load](images/grafana-import-dashboard-consul-2351-load.png?raw=true "Grafana Import Dashboard Consul 2351 Load")
221+
222+
Navigating to Grafana -> Dashboards you should now be able to see the Hashicorp Consul Grafana Dashboard
223+
224+
![Grafana Hashicorp Consul Dashboard](images/grafana-hashicorp-consul-dashboard.png?raw=true "Grafana Hashicorp Consul Dashboard")
225+
226+
## Monitoring Docker
227+
228+
https://docs.docker.com/config/daemon/prometheus/
229+
230+
In docker/docker.sh we enabled Telemetry in the Docker config file see `docker/docker.sh`
231+
232+
```bash
233+
# https://docs.docker.com/config/daemon/prometheus/
234+
sudo echo '{
235+
"metrics-addr": "0.0.0.0:9323",
236+
"experimental": true,
237+
"storage-driver": "overlay2",
238+
"insecure-registries": ["10.9.99.10:5001", "10.9.99.10:5002", "localhost:5001", "localhost:5002"]
239+
}
240+
' >/etc/docker/daemon.json
241+
```
242+
243+
Now, let's import the Docker Grafana Dashboard, to do that, click on the top right + and select `Import Dashboard` ref: https://grafana.com/grafana/dashboards/10619-docker-host-container-overview/
244+
245+
![Grafana Import Dashboard Docker 10619](images/grafana-import-dashboard-docker-10619.png?raw=true "Grafana Import Dashboard Docker 10619")
246+
247+
Enter `10619` and click on Load
248+
249+
![Grafana Import Dashboard Docker 10619 Load](images/grafana-import-dashboard-docker-10619-load.png?raw=true "Grafana Import Dashboard Docker 10619 Load")
250+
251+
Navigating to Grafana -> Dashboards you should now be able to see the Docker Grafana Dashboard
252+
253+
![Grafana Docker Dashboard](images/grafana-docker-dashboard.png?raw=true "Grafana Docker Dashboard")
183254

184255
## Prometheus Grafana Vagrant Provisioner
185256

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins:
2+
- digrich-bubblechart-panel
3+
- grafana-clock-panel
4+
- grafana-piechart-panel
5+
6+
datasources:
7+
datasources.yaml:
8+
apiVersion: 1
9+
datasources:
10+
- name: Prometheus
11+
type: prometheus
12+
url: http://10.9.99.10:9090
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

prometheus-grafana/prometheus-grafana.sh

+12-16
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ sudo docker rm grafana prometheus
2121
yes | sudo docker system prune -a
2222
yes | sudo docker system prune --volumes
2323
for i in $(ps aux | grep kubectl | grep -ve sudo -ve grep -ve bin | grep -e grafana -e prometheus -e alertmanager | tr -s " " | cut -d " " -f2); do kill -9 $i; done
24+
sudo --preserve-env=PATH -u vagrant helm list
2425
sudo --preserve-env=PATH -u vagrant helm uninstall prometheus
2526
sudo --preserve-env=PATH -u vagrant helm uninstall grafana
27+
sudo --preserve-env=PATH -u vagrant helm list
2628

2729
echo -e '\e[38;5;198m'"++++ "
2830
echo -e '\e[38;5;198m'"++++ helm version"
@@ -46,19 +48,16 @@ sudo --preserve-env=PATH -u vagrant helm search repo prometheus-community
4648

4749
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
4850
echo -e '\e[38;5;198m'"++++ "
49-
echo -e '\e[38;5;198m'"++++ Set Vault token in values.yaml for prometheus for monitoring Vault"
51+
echo -e '\e[38;5;198m'"++++ Set Vault token in prometheus-values.yaml for prometheus for monitoring Vault"
5052
echo -e '\e[38;5;198m'"++++ "
51-
sed -i "s/VAULT_TOKEN/$VAULT_TOKEN/g" /vagrant/prometheus-grafana/values.yaml
53+
export VAULT_TOKEN=$(grep 'Initial Root Token' /etc/vault/init.file | cut -d ':' -f2 | tr -d ' ')
54+
sed -i "s/bearer_token: .*/bearer_token: \"$VAULT_TOKEN\"/g" /vagrant/prometheus-grafana/prometheus-values.yaml
55+
cat /vagrant/prometheus-grafana/prometheus-values.yaml
5256

53-
echo -e '\e[38;5;198m'"++++ "
54-
echo -e '\e[38;5;198m'"++++ cleanup prometheus"
55-
echo -e '\e[38;5;198m'"++++ "
56-
sudo --preserve-env=PATH -u vagrant helm list
57-
sudo --preserve-env=PATH -u vagrant helm delete prometheus --namespace default
5857
echo -e '\e[38;5;198m'"++++ "
5958
echo -e '\e[38;5;198m'"++++ helm install prometheus prometheus-community/prometheus"
6059
echo -e '\e[38;5;198m'"++++ "
61-
sudo --preserve-env=PATH -u vagrant helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/values.yaml
60+
sudo --preserve-env=PATH -u vagrant helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/prometheus-values.yaml
6261

6362
echo -e '\e[38;5;198m'"++++ "
6463
echo -e '\e[38;5;198m'"++++ Helm add Grafana repo"
@@ -74,15 +73,10 @@ echo -e '\e[38;5;198m'"++++ helm search repo grafana"
7473
echo -e '\e[38;5;198m'"++++ "
7574
sudo --preserve-env=PATH -u vagrant helm search repo grafana
7675

77-
echo -e '\e[38;5;198m'"++++ "
78-
echo -e '\e[38;5;198m'"++++ cleanup grafana"
79-
echo -e '\e[38;5;198m'"++++ "
80-
sudo --preserve-env=PATH -u vagrant helm list
81-
sudo --preserve-env=PATH -u vagrant helm delete grafana --namespace default
8276
echo -e '\e[38;5;198m'"++++ "
8377
echo -e '\e[38;5;198m'"++++ helm install grafana grafana/grafana"
8478
echo -e '\e[38;5;198m'"++++ "
85-
sudo --preserve-env=PATH -u vagrant helm install grafana grafana/grafana
79+
sudo --preserve-env=PATH -u vagrant helm install grafana grafana/grafana -f /vagrant/prometheus-grafana/grafana-values.yaml
8680

8781
echo -e '\e[38;5;198m'"++++ "
8882
echo -e '\e[38;5;198m'"++++ Waiting for Prometheus and Alertmanager and Grafana to become available.."
@@ -152,6 +146,8 @@ ps aux | grep kubectl | grep -ve sudo -ve grep -ve bin
152146
echo -e '\e[38;5;198m'"++++ "
153147
echo -e '\e[38;5;198m'"++++ Vault policy write prometheus-metrics path /sys/metrics"
154148
echo -e '\e[38;5;198m'"++++ "
149+
export VAULT_ADDR=http://127.0.0.1:8200
150+
env | grep VAULT_ADDR
155151
vault policy write prometheus-metrics - << EOF
156152
path "/sys/metrics*" {
157153
capabilities = ["read", "list"]
@@ -160,9 +156,9 @@ EOF
160156

161157
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
162158
echo -e '\e[38;5;198m'"++++ "
163-
echo -e '\e[38;5;198m'"++++ Reset Vault token in values.yaml"
159+
echo -e '\e[38;5;198m'"++++ Reset Vault token in prometheus-values.yaml"
164160
echo -e '\e[38;5;198m'"++++ "
165-
sed -i "s/bearer_token: .*/bearer_token: \"VAULT_TOKEN\"/g" /vagrant/prometheus-grafana/values.yaml
161+
sed -i "s/bearer_token: .*/bearer_token: \"VAULT_TOKEN\"/g" /vagrant/prometheus-grafana/prometheus-values.yaml
166162

167163
# https://github.com/grafana/grafana/issues/29296
168164
echo -e '\e[38;5;198m'"++++ Prometheus http://localhost:9090"

prometheus-grafana/values.yaml prometheus-grafana/prometheus-values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ extraScrapeConfigs: |
2929
metrics_path: /v1/metrics
3030
params:
3131
format: ['prometheus']
32+
- job_name: 'docker'
33+
static_configs:
34+
- targets: ['10.9.99.10:9323']

0 commit comments

Comments
 (0)