-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazonlinux-prometheus.sh
75 lines (58 loc) · 2.15 KB
/
amazonlinux-prometheus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Fetched Latest Prometheus Version
LATEST_VERSION=3.0.1
# Construct the download URL
DOWNLOAD_URL="https://github.com/prometheus/prometheus/releases/download/v${LATEST_VERSION}/prometheus-${LATEST_VERSION}.linux-amd64.tar.gz"
# Download the latest version of Prometheus
wget $DOWNLOAD_URL
# Extract the downloaded tarball
tar -xf prometheus-${LATEST_VERSION}.linux-amd64.tar.gz
# Move the binaries to /usr/local/bin
sudo mv prometheus-${LATEST_VERSION}.linux-amd64/prometheus prometheus-${LATEST_VERSION}.linux-amd64/promtool /usr/local/bin
# Create directories for configuration files and other Prometheus data
sudo mkdir -p /etc/prometheus /var/lib/prometheus
# Move console libraries
sudo mv prometheus-${LATEST_VERSION}.linux-amd64/console_libraries /etc/prometheus
# Clean up the extracted files
sudo rm -rvf prometheus-${LATEST_VERSION}.linux-amd64*
# Create Prometheus configuration file
sudo cat <<EOF | sudo tee /etc/prometheus/prometheus.yml
global:
scrape_interval: 10s
scrape_configs:
- job_name: 'prometheus_metrics'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter_metrics'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100','worker-1:9100','worker-2:9100']
EOF
# Create Prometheus user
sudo useradd -rs /bin/false prometheus
# Change ownership of the directories
sudo chown -R prometheus: /etc/prometheus /var/lib/prometheus
# Create systemd service file for Prometheus
sudo cat <<EOF | sudo tee /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd and enable Prometheus service
sudo systemctl daemon-reload
sudo systemctl enable prometheus
# Start Prometheus service and check status
sudo systemctl start prometheus
sudo systemctl status prometheus --no-pager