Skip to content

Commit 0f0da6c

Browse files
authored
bare-metal setup docs (#24)
1 parent 8fb7061 commit 0f0da6c

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ There are [two types of logs](./logger/logger.go) as mentioned below.
158158
2. Task Ranking Results logs - These are the results of task ranking using one of task ranking strategies.
159159
These logs are written to a file named **_task\_ranking\_results\_\<timestamp\>.log_**. To simplify parsing
160160
these logs are written in JSON format.
161+
162+
### Bare Metal Setup
163+
Follow instructions [here](./docs/BareMetalSetup.md) to setup Prometheus and cAdvisor on bare-metal.

docs/BareMetalSetup.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Bare Metal Setup of Prometheus and cAdvisor
2+
3+
## cAdvisor Configuration
4+
[cAdvisor](https://github.com/google/cadvisor) needs to be running on each host on which you want to monitor running containers.
5+
We are going to setup cAdvisor as a systemd service.
6+
7+
Follow instructions [here](https://github.com/google/cadvisor/blob/master/docs/development/build.md) to build cAdvisor from source.
8+
Once built, copy the executable into _/usr/local/bin_.
9+
10+
Create a systemd file named _cadvisor.service_ with the below contents in _/etc/systemd/system/_.
11+
12+
**/etc/systemd/system/cadvisor.service**
13+
```shell
14+
[Unit]
15+
Description=cAdvisor
16+
Wants=network-online.target
17+
After=network-online.target docker.service
18+
19+
[Service]
20+
Type=simple
21+
ExecStart=/usr/local/bin/cadvisor -port 9090 -store_container_labels=false -whitelisted_container_labels=LABEL, [LABEL, ...] -docker_only=true
22+
23+
[Install]
24+
WantedBy=multi-user.target
25+
```
26+
1. cAdvisor is being configured to run with root privileges to be able to whitelist docker labels.
27+
2. `-docker\_only=true` tells cAdvisor to report only docker container metrics.
28+
3. [-whitelisted\_container\_labels](https://github.com/google/cadvisor/blob/90f391fddf71801f76f408d8ed191ddc006df323/cmd/cadvisor.go#L72) are a comma separated list of container labels that you assign to containers that need to be monitored. You can then provide these labels are dedicated labels to Task Ranker that will use them as labels in the Prometheus query string.
29+
30+
Run the below command on each host to launch cAdvisor.
31+
```commandline
32+
sudo systemctl start cadvisor
33+
```
34+
35+
## Prometheus Configuration
36+
37+
Create a directory called _prometheus_ in _/etc_.
38+
On the host machine from which you will be collecting container metrics, store the below Prometheus configuration file in _/etc/prometheus/prometheus.yml_.
39+
Checkout [Prometheus configuration docs](https://github.com/prometheus/prometheus/blob/master/docs/configuration/configuration.md) to get more help on configuring Prometheus.
40+
```shell
41+
scrape_configs:
42+
- job_name: 'prometheus'
43+
scrape_interval: 1s
44+
static_configs:
45+
- targets: ['localhost:9090']
46+
- job_name: '<host1>-cadvisor'
47+
scrape_interval: 1s
48+
static_configs:
49+
- targets: ['<host1-ip>:9090']
50+
- job_name: '<host2>-cadvisor'
51+
scrape_interval: 1s
52+
static_configs:
53+
- targets: ['<host2-ip>:9090']
54+
...
55+
```
56+
57+
Use Prometheus [Makefile targets](https://github.com/prometheus/prometheus/blob/master/Makefile) to build from source.<br>
58+
Run the below command to create the directory in which Prometheus stores its time series database.
59+
```commandline
60+
mkdir /var/lib/prometheus
61+
```
62+
We will now setup Prometheus as a systemd service. Create a systemd file named _prometheus.service_ with the below contents in _/etc/systemd/system_.
63+
64+
**/etc/systemd/system/prometheus.service**
65+
```shell
66+
[Unit]
67+
Description=Prometheus
68+
Wants=network-online.target
69+
After=network-online.target
70+
71+
[Service]
72+
User=prometheus
73+
Group=prometheus
74+
ExecStart=/usr/local/bin/prometheus \
75+
--config.file /etc/prometheus/prometheus.yml \
76+
--storage.tsdb.path /var/lib/prometheus/ \
77+
--web.console.templates=/etc/prometheus/consoles \
78+
--web.console.libraries=/etc/prometheus/console_libraries
79+
80+
[Install]
81+
WantedBy=multi-user.target
82+
```
83+
84+
Run the below command on each host to launch prometheus.
85+
```commandline
86+
sudo systemctl start prometheus
87+
```
88+
89+
You should now be able to hit [http://localhost:9090](http://localhost:9090) to see the Prometheus UI.

0 commit comments

Comments
 (0)