-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmonitor.sh
82 lines (72 loc) · 2.41 KB
/
monitor.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
76
77
78
79
80
81
82
#!/bin/bash
cd $HOME
if [ ! $OWNER ]; then
read -p "Введите свой ник, например телеграмм(без @): " OWNER
fi
echo 'Владелец: ' $OWNER
sleep 1
echo 'export OWNER='$OWNER >> $HOME/.profile
if [ ! $HOSTNAME ]; then
read -p "Введите название своего сервера: " HOSTNAME
fi
echo 'Название вашего сервера: ' $HOSTNAME
sleep 1
echo 'export HOSTNAME='$HOSTNAME >> $HOME/.profile
sudo systemctl stop prometheus && systemctl disable prometheus
sudo mkdir /etc/prometheus
sudo apt install wget -y
wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.63.0/vmutils-amd64-v1.63.0.tar.gz
tar xvf vmutils-amd64-v1.63.0.tar.gz
rm -rf vmutils-amd64-v1.63.0.tar.gz
sudo tee <<EOF >/dev/null /etc/prometheus/prometheus.yml
global:
scrape_interval: 30s
evaluation_interval: 30s
external_labels:
owner: '$OWNER'
hostname: '$HOSTNAME'
scrape_configs:
- job_name: "node_exporter"
scrape_interval: 30s
static_configs:
- targets: ["localhost:9100"]
relabel_configs:
- source_labels: [__address__]
regex: '.*'
target_label: instance
replacement: '$HOSTNAME'
EOF
sudo tee <<EOF >/dev/null /etc/systemd/system/vmagent.service
[Unit]
Description=vmagent Monitoring
Wants=network-online.target
After=network-online.target
[Service]
User=root
Type=simple
ExecStart=$HOME/vmagent-prod \
-promscrape.config=/etc/prometheus/prometheus.yml \
-remoteWrite.url=http://doubletop:[email protected]:8080/api/v1/write
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable vmagent && sudo systemctl restart vmagent
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
tar xvf node_exporter-1.1.2.linux-amd64.tar.gz
sudo cp node_exporter-1.1.2.linux-amd64/node_exporter /usr/local/bin
rm -rf node_exporter-1.1.2.linux-amd64*
sudo tee <<EOF >/dev/null /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=$USER
Type=simple
ExecStart=/usr/local/bin/node_exporter --web.listen-address=":9100"
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable node_exporter && sudo systemctl restart node_exporter
echo "Monitoring Installed"