Prometheus. Almalinux 8. Install Prometheus + Grafana: различия между версиями
Cless (обсуждение | вклад) (Новая страница: «Категория:Prometheus __ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__») |
Cless (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
[[Категория:Prometheus]] | [[Категория:Prometheus]] | ||
__ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__ | __ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__ | ||
== Prometheus install == | |||
<code>dnf update -y</code> | |||
<code>wget <nowiki>https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz</nowiki></code> | |||
<code>useradd --no-create-home --shell /bin/false prometheus</code> | |||
<code>mkdir /etc/prometheus</code> | |||
<code>mkdir /var/lib/prometheus</code> | |||
<code>chown prometheus:prometheus /etc/prometheus</code> | |||
<code>chown prometheus:prometheus /var/lib/prometheus</code> | |||
<code>tar -xvzf prometheus-*</code> | |||
<code>mv prometheus-2.37.0.linux-amd64 prometheuspackage</code> | |||
<code>cp prometheuspackage/prometheus /usr/local/bin/</code> | |||
<code>cp prometheuspackage/promtool /usr/local/bin/</code> | |||
<code>chown prometheus:prometheus /usr/local/bin/prometheus</code> | |||
<code>chown prometheus:prometheus /usr/local/bin/promtool</code> | |||
Copy consoles and console_libraries directories from the prometheuspackage to /etc/prometheus folder | |||
<code>cp -r prometheuspackage/consoles /etc/prometheus</code> | |||
<code>cp -r prometheuspackage/console_libraries /etc/prometheus</code> | |||
<code>cp -r prometheuspackage/prometheus.yml /etc/prometheus/prometheus.yml</code> | |||
<code>chown -R prometheus:prometheus /etc/prometheus/consoles</code> | |||
<code>chown -R prometheus:prometheus /etc/prometheus/console_libraries</code> | |||
<code>chown -R prometheus:prometheus /etc/prometheus/prometheus.yml</code> | |||
<code>nano /etc/prometheus/prometheus.yml</code> | |||
... | |||
global: | |||
scrape_interval: 10s | |||
scrape_configs: | |||
- job_name: 'prometheus_master' | |||
scrape_interval: 5s | |||
static_configs: | |||
- targets: ['localhost:9090'] | |||
... | |||
Save and exit the file | |||
<code>chown prometheus:prometheus /etc/prometheus/prometheus.yml</code> | |||
<code>nano /etc/systemd/system/prometheus.service</code> | |||
[Unit] | |||
Description=Prometheus | |||
Wants=network-online.target | |||
After=network-online.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 | |||
<code>systemctl daemon-reload</code> | |||
<code>systemctl start prometheus</code> | |||
<code>systemctl status prometheus</code> | |||
<code>firewall-cmd --zone=public --add-port=9090/tcp --permanent</code> | |||
<code>systemctl reload firewalld</code> | |||
Go to web | |||
<code>http://<Server-IP>:9090/graph</code> | |||
== Grafana install == | |||
Grafana is a free and open-source, general-purpose graph and dashboard composer. | |||
It supports many third party software applications such as Prometheus, PNP, InfluxDB, Graphite, etc. | |||
Grafana runs as a web application at default port 3000/tcp. | |||
In this article we will use Grafana Web UI to create a dashboard for Prometheus metrics. | |||
<code>nano /etc/yum.repos.d/grafana.repo</code> | |||
[grafana] | |||
name=grafana | |||
baseurl=<nowiki>https://packages.grafana.com/oss/rpm</nowiki> | |||
repo_gpgcheck=1 | |||
enabled=1 | |||
gpgcheck=1 | |||
gpgkey=<nowiki>https://packages.grafana.com/gpg.key</nowiki> | |||
sslverify=1 | |||
sslcacert=/etc/pki/tls/certs/ca-bundle.crt | |||
<code>dnf install -y grafana</code> | |||
<code>systemctl enable --now grafana-server.service</code> | |||
<code>firewall-cmd --permanent --add-port=3000/tcp</code> | |||
<code>firewall-cmd --reload</code> | |||
Go to web | |||
<code>http://<prometheus-IP>:3000</code><blockquote>login: admin | |||
password: admin</blockquote>Change password at first sign in | |||
=== Link Prometheus to Grafana === | |||
* Click on Add Data Source | |||
* Click on Prometheus | |||
* Add a Prometheus data source: '''<nowiki>http://localhost:9090</nowiki>''' | |||
* Click on Save and Test | |||
=== Create Prometheus Dashboard in Grafana: === | |||
* Now, to add a dashboard for Prometheus, click on '''Dashboards tab''' | |||
* Here, you can see the available dashboards related to Prometheus data source | |||
* Import a dashboard by clicking on the '''Import button''' | |||
* To customize this dashboard, click on '''Dashboards > Manage''' button from the left sidebar | |||
* Click on the '''Prometheus 2.0 Stats''' dashboard | |||
* Customize this dashboard according to your requirements | |||
Версия 11:43, 21 июля 2022
Prometheus install
dnf update -y
wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
useradd --no-create-home --shell /bin/false prometheus
mkdir /etc/prometheus
mkdir /var/lib/prometheus
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus
tar -xvzf prometheus-*
mv prometheus-2.37.0.linux-amd64 prometheuspackage
cp prometheuspackage/prometheus /usr/local/bin/
cp prometheuspackage/promtool /usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
Copy consoles and console_libraries directories from the prometheuspackage to /etc/prometheus folder
cp -r prometheuspackage/consoles /etc/prometheus
cp -r prometheuspackage/console_libraries /etc/prometheus
cp -r prometheuspackage/prometheus.yml /etc/prometheus/prometheus.yml
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
chown -R prometheus:prometheus /etc/prometheus/prometheus.yml
nano /etc/prometheus/prometheus.yml
... global: scrape_interval: 10s scrape_configs: - job_name: 'prometheus_master' scrape_interval: 5s static_configs: - targets: ['localhost:9090'] ...
Save and exit the file
chown prometheus:prometheus /etc/prometheus/prometheus.yml
nano /etc/systemd/system/prometheus.service
[Unit] Description=Prometheus Wants=network-online.target After=network-online.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
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
firewall-cmd --zone=public --add-port=9090/tcp --permanent
systemctl reload firewalld
Go to web
http://<Server-IP>:9090/graph
Grafana install
Grafana is a free and open-source, general-purpose graph and dashboard composer.
It supports many third party software applications such as Prometheus, PNP, InfluxDB, Graphite, etc.
Grafana runs as a web application at default port 3000/tcp.
In this article we will use Grafana Web UI to create a dashboard for Prometheus metrics.
nano /etc/yum.repos.d/grafana.repo
[grafana] name=grafana baseurl=https://packages.grafana.com/oss/rpm repo_gpgcheck=1 enabled=1 gpgcheck=1 gpgkey=https://packages.grafana.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt
dnf install -y grafana
systemctl enable --now grafana-server.service
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --reload
Go to web
http://<prometheus-IP>:3000
login: admin password: admin
Change password at first sign in
Link Prometheus to Grafana
- Click on Add Data Source
- Click on Prometheus
- Add a Prometheus data source: http://localhost:9090
- Click on Save and Test
Create Prometheus Dashboard in Grafana:
- Now, to add a dashboard for Prometheus, click on Dashboards tab
- Here, you can see the available dashboards related to Prometheus data source
- Import a dashboard by clicking on the Import button
- To customize this dashboard, click on Dashboards > Manage button from the left sidebar
- Click on the Prometheus 2.0 Stats dashboard
- Customize this dashboard according to your requirements