Skip to content

Commit 4d62f05

Browse files
committed
monitoring hashicorp vault telemetry with prometheus and grafana
1 parent ce3397d commit 4d62f05

19 files changed

+129
-20
lines changed

ansible-tower/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,10 @@ null_resource.awx_cli: Creation complete after 36s [id=936123805330159798]
930930
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
931931
```
932932

933-
## The Code
933+
## Ansible AWX Tower Vagrant Provisioner
934934

935935
[filename](ansible-tower.sh ':include :type=code')
936936

937+
## Terraform calling Ansible AWX
938+
937939
[filename](main.tf ':include :type=code hcl')

apache-airflow/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The `test-ssh.py` just ssh into hashiqube to test the connection
5656
- https://airflow.readthedocs.io/_/downloads/en/1.10.2/pdf/
5757
- https://airflow.apache.org/docs/helm-chart/stable/parameters-ref.html
5858

59-
## The Code
59+
## Apache Airflow Vagrant Provisioner
6060

6161
[filename](apache-airflow.sh ':include :type=code')
6262

database/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ mysql: [Warning] Using a password on the command line interface can be insecure.
210210
| root | localhost |
211211
+------------------+-----------+
212212
```
213-
## The Code
213+
## MySQL Vagrant Provisioner
214214

215215
[filename](mysql.sh ':include :type=code')
216216

@@ -360,7 +360,7 @@ NT AUTHORITY\SYSTEM
360360
(21 rows affected)
361361
```
362362

363-
## The Code
363+
## MSSQL Vagrant Provisioner
364364

365365
[filename](mssql.sh ':include :type=code')
366366

@@ -453,6 +453,6 @@ Bringing machine 'hashiqube0.service.consul' up with 'virtualbox' provider...
453453
hashiqube0.service.consul: v-token-postgres-3AhBH3pbmVNnkbxXV8K3-1598841098 | Password valid until 2020-08-31 03:31:43+00 | {}
454454
```
455455

456-
## The Code
456+
## PostgreSQL Vagrant Provisioner
457457

458458
[filename](postgresql.sh ':include :type=code')

dbt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ In this way, if we have already run the model, the next RUN and TEST will execut
123123

124124
This would open space as well to implement cool stuff, such as running the model over a pull request.
125125

126-
## The Code
126+
## DBT Vagrant Provisioner
127127

128128
[filename](common.sh ':include :type=code')
129129

docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,6 @@ 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-
## The Code
560+
## Docker Vagrant Provisioner
561561

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

docsify/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
7575
After provision, you can access Docsify and HashiQube documentation at http://localhost:3333/
7676
![Docsify](images/docsify.png?raw=true "Docsify")
7777

78-
## The Code
78+
## Docsify Vagrant Provisioner
7979

8080
[filename](docsify.sh ':include :type=code')

hashicorp/README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Packer uses the HashiCorp Configuration Language - HCL - designed to allow conci
154154
### Windows 2019
155155

156156
[filename](packer/windows/windowsserver/windows-2019.pkr.hcl ':include :type=code')
157-
## The Code
157+
## Packer Vagrant Provisioner
158158

159159
[filename](packer.sh ':include :type=code')
160160

@@ -261,7 +261,7 @@ can't guarantee that exactly these actions will be performed if
261261
"terraform apply" is subsequently run.
262262
```
263263

264-
## The Code
264+
## Terraform Vagrant Provisioner
265265

266266
[filename](terraform.sh ':include :type=code')
267267

@@ -344,7 +344,13 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
344344
```
345345
![Vault](images/vault.png?raw=true "Vault")
346346

347-
## The Code
347+
## Monitoring Hashicorp Vault
348+
349+
We use Prometheus and Grafana to Monitor Vault
350+
351+
See: [__Monitoring Hashicorp Vault__](prometheus-grafana/README?id=monitoring-hashicorp-vault)
352+
353+
## Vault Vagrant Provisioner
348354

349355
[filename](vault.sh ':include :type=code')
350356

@@ -486,7 +492,7 @@ When you register a service in Consul all you need to add is a tag that announce
486492
Fabio runs as a Nomad job, see `hashicorp/nomad/jobs/fabio.nomad`
487493
Some routes are added via Consul, see `hashicorp/consul.sh`
488494

489-
## The Code
495+
## Nomad Vagrant Provisioner
490496

491497
[filename](nomad.sh ':include :type=code')
492498

@@ -663,7 +669,7 @@ Bringing machine 'user.local.dev' up with 'virtualbox' provider...
663669
```
664670
![Consul](images/consul.png?raw=true "Consul")
665671

666-
## The Code
672+
## Consul Vagrant Provisioner
667673

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

@@ -1097,7 +1103,7 @@ c97d646ce0ef: Already exists :
10971103
hashiqube0.service.consul: bM152PWkXxfoy4vA51JFhR7LmV9FA9RLbSpHoKrysFnwnRCAGzV2RExsyAmBrHu784d1WZRW6Cx4MkhvWzkDHvEn49c4wkSZYScfJ
10981104
```
10991105

1100-
## The Code
1106+
## Waypoint Vagrant Provisioner
11011107

11021108
[filename](waypoint.sh ':include :type=code')
11031109

@@ -1181,6 +1187,6 @@ Bringing machine 'hashiqube0.service.consul' up with 'virtualbox' provider...
11811187
hashiqube0.service.consul: /tmp/vagrant-shell: line 5: 5093 Terminated sh -c 'sudo tail -f /var/log/boundary.log | { sed "/worker successfully authed/ q" && kill $$ ;}'
11821188
```
11831189

1184-
## The Code
1190+
## Boundary Vagrant Provisioner
11851191

11861192
[filename](boundary.sh ':include :type=code')

hashicorp/vault.sh

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ storage "raft" {
128128
# address = "127.0.0.1:8500"
129129
# path = "vault"
130130
# }
131+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry
132+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
133+
telemetry {
134+
disable_hostname = true
135+
prometheus_retention_time = "12h"
136+
}
131137
api_addr = "http://10.9.99.10:8200"
132138
max_lease_ttl = "10h"
133139
default_lease_ttl = "10h"

hashiqube/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This Provider (Basetools) installs some essential tools that Hashiqube provision
88
swapspace rkhunter jq curl unzip software-properties-common bzip2 git make python3.9 python3-pip python3-dev python3-venv python3-virtualenv golang-go apt-utils ntp update-motd toilet figlet nano iputils-ping dnsutils iptables telnet
99
```
1010

11-
## The Code
11+
## Hashiqune Vagrant Provisioner
1212

1313
[filename](basetools.sh ':include :type=code')
1414

localstack/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Now check the assets with aws local inside vagrant
130130
2006-02-04 03:45:09 localstack-s3-bucket
131131
```
132132

133-
## The Code
133+
## Localstack Terraform Examples
134134

135135
[filename](variables.tf ':include :type=code')
136136

minikube/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ This guide explains how to use Traefik as an Ingress controller for a Kubernetes
144144

145145
![Traefik on Minikube](images/minikube-traefik-dashboard.png?raw=true "Traefik on Minikube")
146146

147-
## The Code
147+
## Minikube Vagrant Provisioner
148148

149149
[filename](minikube.sh ':include :type=code')

prometheus-grafana/README.md

+54-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +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-
`vagrant up --provision-with basetools,docker,minikube,prometheus-grafana`
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
20+
21+
`vagrant up --provision-with basetools,docker,vault,minikube,prometheus-grafana`
2022

2123
Prometheus http://localhost:9090 <br />
2224
Alertmanager http://localhost:9093 <br />
@@ -73,4 +75,55 @@ and you should be able to see some graphs.
7375

7476
![Grafana Dashboard Kubernetes Cluster (Prometheus)](images/grafana_dashboard_6417.png?raw=true "Grafana Dashboard Kubernetes Cluster (Prometheus)")
7577

78+
## Monitoring Hashicorp Vault
79+
80+
https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus <br />
81+
https://developer.hashicorp.com/vault/docs/configuration/telemetry
82+
83+
In hashicorp/vault.sh we enabled Telemetry in the Vault config file see `hashicorp/vault.sh`
84+
85+
```hcl
86+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry
87+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
88+
telemetry {
89+
disable_hostname = true
90+
prometheus_retention_time = "12h"
91+
}
92+
```
93+
94+
When we install Prometheus with Helm we set a values.yaml file that specify an `extraScrapeConfigs` You guessed it! Vault...
95+
96+
`helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/values.yaml`
97+
98+
[filename](values.yaml ':include :type=code')
99+
100+
You should now see the Vault target in Prometheus web interface at http://localhost:9090/targets
101+
102+
![Prometheus Vault Target](images/prometheus-targets-vault.png?raw=true "Prometheus Vault Target")
103+
104+
We now need to Grafana Datasource of Type Prometheus based on this Target
105+
106+
Please navigate to http://localhost:3000/connections/your-connections/datasources
107+
108+
And add a Vault Datasource
109+
110+
Name: Vault
111+
URL: http://10.9.99.10:9090
112+
113+
![Grafana Datasource Prometheus Vault](images/grafana-datasource-prometheus-vault.png?raw=true "Grafana Datasource Prometheus Vault")
114+
115+
Now, let's import the Vault Grafana Dashboard, to do that, click on the top right + and select `Import Dashboard` ref: https://grafana.com/grafana/dashboards/12904-hashicorp-vault/
116+
117+
![Grafana Import Dashboard Vault 12904](images/grafana-import-dashboard-vault-12904.png?raw=true "Grafana Import Dashboard Vault 12904")
118+
119+
Enter `12904` and click on Load
120+
121+
![Grafana Import Dashboard Vault 12904 Load](images/grafana-import-dashboard-vault-12904-load.png?raw=true "Grafana Import Dashboard Vault 12904 Load")
122+
123+
Navigating to Grafana -> Dashboards you should now be able to see the Hashicorp Vault Grafana Dashboard
124+
125+
![Grafana Hashicorp Vault Dashboard](images/grafana-hashicorp-vault-dashboard.png?raw=true "Grafana Hashicorp Vault Dashboard")
126+
127+
## Prometheus Grafana Vagrant Provisioner
76128

129+
[filename](prometheus-grafana.sh ':include :type=code')
Loading
Loading
Loading
Loading
Loading

prometheus-grafana/prometheus-grafana.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ echo -e '\e[38;5;198m'"++++ "
4343
echo -e '\e[38;5;198m'"++++ helm search repo prometheus-community"
4444
echo -e '\e[38;5;198m'"++++ "
4545
sudo --preserve-env=PATH -u vagrant helm search repo prometheus-community
46+
47+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
48+
echo -e '\e[38;5;198m'"++++ "
49+
echo -e '\e[38;5;198m'"++++ Set Vault token in values.yaml for prometheus for monitoring Vault"
50+
echo -e '\e[38;5;198m'"++++ "
51+
sed -i "s/VAULT_TOKEN/$VAULT_TOKEN/g" /vagrant/prometheus-grafana/values.yaml
52+
4653
echo -e '\e[38;5;198m'"++++ "
4754
echo -e '\e[38;5;198m'"++++ helm install prometheus prometheus-community/prometheus"
4855
echo -e '\e[38;5;198m'"++++ "
49-
sudo --preserve-env=PATH -u vagrant helm install prometheus prometheus-community/prometheus
56+
sudo --preserve-env=PATH -u vagrant helm install prometheus prometheus-community/prometheus -f /vagrant/prometheus-grafana/values.yaml
5057

5158
echo -e '\e[38;5;198m'"++++ "
5259
echo -e '\e[38;5;198m'"++++ Helm add Grafana repo"
@@ -129,6 +136,17 @@ done
129136

130137
ps aux | grep kubectl | grep -ve sudo -ve grep -ve bin
131138

139+
# https://developer.hashicorp.com/vault/tutorials/monitoring/monitor-telemetry-grafana-prometheus
140+
# https://developer.hashicorp.com/vault/docs/configuration/telemetry#prometheus
141+
echo -e '\e[38;5;198m'"++++ "
142+
echo -e '\e[38;5;198m'"++++ Vault policy write prometheus-metrics path /sys/metrics"
143+
echo -e '\e[38;5;198m'"++++ "
144+
vault policy write prometheus-metrics - << EOF
145+
path "/sys/metrics*" {
146+
capabilities = ["read", "list"]
147+
}
148+
EOF
149+
132150
# https://github.com/grafana/grafana/issues/29296
133151
echo -e '\e[38;5;198m'"++++ Prometheus http://localhost:9090"
134152
echo -e '\e[38;5;198m'"++++ Alertmanager http://localhost:9093"

prometheus-grafana/values.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extraScrapeConfigs: |
2+
- job_name: vault
3+
metrics_path: /v1/sys/metrics
4+
params:
5+
format: ['prometheus']
6+
scheme: http
7+
bearer_token: "hvs.m29F723W1wV8R8ths0ycs71x"
8+
static_configs:
9+
- targets: ['10.9.99.10:8200']
10+
# - job_name: 'prometheus-blackbox-exporter'
11+
# metrics_path: /probe
12+
# params:
13+
# module: [http_2xx]
14+
# static_configs:
15+
# - targets:
16+
# - https://example.com
17+
# relabel_configs:
18+
# - source_labels: [__address__]
19+
# target_label: __param_target
20+
# - source_labels: [__param_target]
21+
# target_label: instance
22+
# - target_label: __address__
23+
# replacement: prometheus-blackbox-exporter:9115
24+

0 commit comments

Comments
 (0)