-
Notifications
You must be signed in to change notification settings - Fork 0
Homework8 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
niskhakov
wants to merge
2
commits into
master
Choose a base branch
from
homework8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Homework8 #5
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # Admins: HW → MRP | ||
|
|
||
| ## Задание 1: Настройка Prometheus | ||
|
|
||
| 1. Для начала, скачиваем архивы и распаковывем их: | ||
| ```bash | ||
| mkdir Downloads | ||
| cd Downloads | ||
| wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz | ||
| wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz | ||
| tar xvf prometheus-2.3.2.linux-amd64.tar.gz | ||
| tar xvf node_exporter-0.16.0.linux-amd64.tar.gz | ||
| ``` | ||
|
|
||
| 2. Изменение конфигурации Prometheus: | ||
| ```bash | ||
| cd prometheus-2.3.2.linux-amd64 | ||
| vim prometheus.yml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| # my global config | ||
| global: | ||
| scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. | ||
| evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. | ||
| # scrape_timeout is set to the global default (10s). | ||
| # Alertmanager configuration | ||
| alerting: | ||
| alertmanagers: | ||
| - static_configs: | ||
| - targets: | ||
| # - alertmanager:9093 | ||
| # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. | ||
| rule_files: | ||
| # - "first_rules.yml" | ||
| # - "second_rules.yml" | ||
| # A scrape configuration containing exactly one endpoint to scrape: | ||
| # Here it's Prometheus itself. | ||
| scrape_configs: | ||
| # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. | ||
| - job_name: 'prometheus' | ||
| # metrics_path defaults to '/metrics' | ||
| # scheme defaults to 'http'. | ||
| static_configs: | ||
| - targets: ['localhost:9090'] | ||
| - job_name: 'node_exporter' | ||
| static_configs: | ||
| - targets: ['localhost:9100','localhost:9090'] | ||
| ``` | ||
|
|
||
| 3. Запуск Node_exporter: | ||
| ```bash | ||
| cd ../node_exporter-0.16.0linux-amd64 | ||
| ./node_exporter & | ||
| cd ../prometheus-2.3.2.linux-amd64 | ||
| ./prometheus | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
|  | ||
|
|
||
|  | ||
|
|
||
| ## Задание 2: Запуск Prometheus и Node_exporter под Supervisord | ||
|
|
||
| 1. Необходимо завершить работу Prometheus и Node Exporter | ||
| ```bash | ||
| ps aux | grep prometheus | ||
| kill <prometheus-id> | ||
| ps aux | grep node_exporter | ||
| kill <node_exporter-id> | ||
| # Или вызвать netstat -natp и посмотреть какие приложения сидят на каких портах | ||
| ``` | ||
|
|
||
| 2. Для удобства запуска программ под Supervisord выполним команды | ||
| ```bash | ||
| cd /root/Downloads/ | ||
| mv prometheus-2.3.2.linux-amd64 /opt/prometheus | ||
| mv node_exporter-0.16.0.linux-amd64 /opt/node_exporter | ||
| mkdir -p /var/log/prometheus /var/log/node_exporter | ||
| ``` | ||
|
|
||
| 3. Для работы Supervisord добавим в директорию /etc/supervisord.d/ файлы prometheus.ini и node_exporter.ini | ||
| ``` | ||
| [program:prometheus] | ||
| command=/opt/prometheus/prometheus | ||
| stdout_logfile=/var/log/prometheus/prometheus.log | ||
| stderr_logfile=/var/log/prometheus/errors.log | ||
| autostart=true | ||
| autorestart=true | ||
| directory=/opt/prometheus/ | ||
| ``` | ||
|
|
||
| ``` | ||
| [program:node_exporter] | ||
| command=/opt/node_exporter/node_exporter | ||
| stdout_logfile=/var/log/node_exporter/node_exporter.log | ||
| stderr_logfile=/var/log/node_exporter/errors.log | ||
| autostart=true | ||
| autorestart=true | ||
| ``` | ||
|
|
||
| 4. Запускаем Supervisord и проверяем запущены ли программы | ||
| ```bash | ||
| systemctl enable supervisord | ||
| systemctl start supervisord | ||
| systemctl status supervisord | ||
| ``` | ||
|
|
||
| Если Supervisord уже запущен и настроен на запуск при старте ОС, то достаточно выполнить команду: | ||
| ```bash | ||
| supervisorctl update | ||
| supervisorctl status | ||
| ``` | ||
|
|
||
| 5. От себя: | ||
| Ниже в файле уже поправил, но столкнулся с тем, что prometheus не мог запуститься под supervisord. Просмотрев логи, понял: проблема была в том, что prometheus не мог найти файл конфигурации promehteus.yml. Причина: программа запускалась не из дериктории /opt/prometheus. Для этого добавил в ini директиву _directory_. После выполнил `supervisorctl update` чтобы supervisord подхватил настройки заново. | ||
|
|
||
| ## Задание 3: Изменение метода отправки | ||
| 1. Для начала скачиваем и разархивируем uwsgi_exporter | ||
| ```bash | ||
| wget https://github.com/timonwong/uwsgi_exporter/releases/download/v0.7.0/uwsgi_exporter-0.7.0.linux-amd64.tar.gz | ||
| tar xvf uwsgi_exporter-0.7.0.linux-amd64.tar.gz | ||
| mv uwsgi_exporter-0.7.0.linux-amd64 /opt/uwsgi_exporter | ||
| mkdir -p /var/log/uwsgi_exporter | ||
| ``` | ||
|
|
||
| 2. Правим /etc/supervisord.d/former.ini | ||
| Таким образом команда запуска будет выглядеть следующим образом: | ||
| ``` | ||
| command=uwsgi | ||
| --plugins=python | ||
| --http-socket=0.0.0.0:80 | ||
| --wsgi-file /opt/webcode/former/process/webrunner.py | ||
| --static-map /form=/opt/webcode/former/form/index.html | ||
| --processes=5 | ||
| --master | ||
| --pidfile=/tmp/former.pid | ||
| --vacuum | ||
| --max-requests=5000 | ||
| --stats "127.0.0.1:1717" | ||
| --stats-http | ||
| ``` | ||
|
|
||
| 3. Также оборачиваем uwsgi_exporter в Supervisord | ||
| ``` | ||
| [program:uwsgi_exporter] | ||
| command=/opt/uwsgi_exporter/uwsgi_exporter | ||
| --stats.uri="http://127.0.0.1:1717" | ||
| stdout_logfile=/var/log/uwsgi_exporter/uwsgi_exporter.log | ||
| stderr_logfile=/var/log/uwsgi_exporter/errors.log | ||
| autostart=true | ||
| autorestart=true | ||
| ``` | ||
|
|
||
| 4. Делаем изменения в prometheus.yml | ||
| Добавляем в scrape_configs еще один job: | ||
| ```yaml | ||
| ... | ||
| scrape_configs: | ||
| ... | ||
| - job_name: 'uwsgi_exporter' | ||
| static_configs: | ||
| - targets: ['localhost:9117'] | ||
| ... | ||
| ``` | ||
|
|
||
| 5. Обновляем настройки Supervisord и проверяем | ||
| ```bash | ||
| supervisorctl update | ||
| supervisorctl status | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а чем этот способ лучше, нежели указать опцию
--config.fileпри запуске? :)