chore: optimize resource allocation and memory settings in Docker Compose

- Added memory and CPU limits and reservations for Prometheus, Grafana, and Uptime Kuma services to enhance performance and resource management.
- Updated Prometheus and Grafana configurations with new storage block duration settings for improved memory optimization.
- Revised README to include additional commands for running specific services and restarting containers.
This commit is contained in:
2026-01-23 21:38:48 +03:00
parent 75cd722cc4
commit 9e03c1f6f2
3 changed files with 56 additions and 6 deletions

View File

@@ -19,10 +19,6 @@ prod/
## 🚀 Быстрый запуск ## 🚀 Быстрый запуск
### ⚠️ Важное замечание
**Убедитесь, что вы удалили файл `docker-compose.yml` из папки `bots/telegram-helper-bot/`**
для избежания конфликтов портов. Используйте только корневой `docker-compose.yml`.
### 1. Настройка переменных окружения ### 1. Настройка переменных окружения
Скопируйте шаблон и настройте переменные: Скопируйте шаблон и настройте переменные:
@@ -57,12 +53,25 @@ GRAFANA_ADMIN_PASSWORD=admin
docker-compose up -d docker-compose up -d
``` ```
### 2.1 Запуск только основного бота (с зависимостями). Можно заменить на AnonBot
```bash
docker-compose up -d prometheus telegram-bot
```
### 3. Проверка статуса ### 3. Проверка статуса
```bash ```bash
docker-compose ps docker-compose ps
``` ```
### 4. Перезапуск контейнера
```bash
docker-compose down telegram-bot && docker-compose build --no-cache telegram-bot && docker-compose up -d telegram-bot
```
## 📊 Сервисы ## 📊 Сервисы
- **Prometheus** (порт 9090) - сбор метрик - **Prometheus** (порт 9090) - сбор метрик

View File

@@ -13,6 +13,9 @@ services:
- '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION_DAYS:-30}d' - '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION_DAYS:-30}d'
- '--web.enable-lifecycle' - '--web.enable-lifecycle'
- '--web.external-url=https://${SERVER_IP}/prometheus/' - '--web.external-url=https://${SERVER_IP}/prometheus/'
# Оптимизация памяти
- '--storage.tsdb.max-block-duration=2h'
- '--storage.tsdb.min-block-duration=2h'
ports: ports:
- "9090:9090" - "9090:9090"
volumes: volumes:
@@ -26,6 +29,14 @@ services:
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3
deploy:
resources:
limits:
memory: 128M
cpus: '0.5'
reservations:
memory: 64M
cpus: '0.25'
# Grafana Dashboard # Grafana Dashboard
grafana: grafana:
@@ -39,6 +50,10 @@ services:
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
- GF_SERVER_ROOT_URL=https://${SERVER_IP}/grafana/ - GF_SERVER_ROOT_URL=https://${SERVER_IP}/grafana/
- GF_SERVER_SERVE_FROM_SUB_PATH=true - GF_SERVER_SERVE_FROM_SUB_PATH=true
# Оптимизация памяти
- GF_DATABASE_MAX_IDLE_CONN=2
- GF_DATABASE_MAX_OPEN_CONN=5
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/node-exporter-full-dashboard.json
ports: ports:
- "3000:3000" - "3000:3000"
volumes: volumes:
@@ -53,6 +68,14 @@ services:
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3
deploy:
resources:
limits:
memory: 200M
cpus: '0.5'
reservations:
memory: 100M
cpus: '0.25'
# Uptime Kuma Status Page # Uptime Kuma Status Page
uptime-kuma: uptime-kuma:
@@ -73,6 +96,14 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
start_period: 40s start_period: 40s
deploy:
resources:
limits:
memory: 150M
cpus: '0.5'
reservations:
memory: 80M
cpus: '0.25'
# Alertmanager # Alertmanager
alertmanager: alertmanager:

View File

@@ -34,7 +34,7 @@
known_hosts: known_hosts:
path: ~/.ssh/known_hosts path: ~/.ssh/known_hosts
name: "{{ ansible_host }}" name: "{{ ansible_host }}"
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa,ecdsa,ed25519 ' + ansible_host) }}" key: "{{ lookup('pipe', 'ssh-keyscan -t rsa,ecdsa,ed25519 ' + ansible_host + ' 2>/dev/null') }}"
state: present state: present
delegate_to: localhost delegate_to: localhost
run_once: true run_once: true
@@ -71,6 +71,8 @@
- certbot - certbot
- python3-certbot-nginx - python3-certbot-nginx
- logrotate - logrotate
- net-tools
- cron
state: present state: present
- name: "[1/10] Установить Python библиотеки для Ansible" - name: "[1/10] Установить Python библиотеки для Ansible"
@@ -233,9 +235,10 @@
var: node_exporter_status.stdout_lines var: node_exporter_status.stdout_lines
- name: "[3/10] Проверить, что node_exporter слушает на порту 9100" - name: "[3/10] Проверить, что node_exporter слушает на порту 9100"
command: netstat -tulpn | grep 9100 command: ss -tulpn | grep 9100
register: node_exporter_port register: node_exporter_port
changed_when: false changed_when: false
ignore_errors: yes
- name: "[3/10] Показать информацию о порте 9100" - name: "[3/10] Показать информацию о порте 9100"
debug: debug:
@@ -1126,6 +1129,7 @@
command: fail2ban-client status command: fail2ban-client status
register: fail2ban_status register: fail2ban_status
changed_when: false changed_when: false
ignore_errors: yes
- name: "[9/10] Показать статус Fail2ban" - name: "[9/10] Показать статус Fail2ban"
debug: debug:
@@ -1233,6 +1237,12 @@
enabled: yes enabled: yes
state: started state: started
- name: "[9.5/10] Установить cron (если не установлен)"
apt:
name: cron
state: present
when: ansible_pkg_mgr == "apt"
- name: "[9.5/10] Настроить cron для ежедневного запуска logrotate" - name: "[9.5/10] Настроить cron для ежедневного запуска logrotate"
cron: cron:
name: "Logrotate daily" name: "Logrotate daily"