From 66f49c057f28936d0d1fbd840af751cd8070af61 Mon Sep 17 00:00:00 2001 From: FARKHOD ABDUKODIROV Date: Sat, 17 May 2025 22:59:45 +0900 Subject: [PATCH] update --- .gitignore | 39 +++++++++++++++++-- README.md | 8 ++-- group_vars/all.yml | 9 +++++ main.yml => playbooks/main.yml | 0 .../prometheus_config.yml | 0 .../alert_manager/files/alertmanager.service | 2 +- roles/grafana/files/grafana.nginx.conf | 8 ++-- roles/loki/files/loki.yml | 6 +-- roles/prometheus/files/prometheus.nginx.conf | 6 +-- roles/prometheus/files/prometheus.yml | 2 +- roles/promtail/files/promtail.yml | 4 +- 11 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 group_vars/all.yml rename main.yml => playbooks/main.yml (100%) rename prometheus_config.yml => playbooks/prometheus_config.yml (100%) diff --git a/.gitignore b/.gitignore index 0921a42..e6d4e77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,37 @@ +# Inventory and configuration files inventory.ini -/roles/prometheus_config/files/hosts -/roles/prometheus_config/files/prometheus.yml -/roles/prometheus_config/templates/prometheus.yml.j2 +config_hosts.yml + +# Prometheus configuration files +roles/prometheus_config/files/hosts +roles/prometheus_config/files/prometheus.yml +roles/prometheus_config/templates/prometheus.yml.j2 + +# Sample files +samples/inventory.sample +samples/hosts.sample +samples/prometheus.yml.sample + +# Ansible-related files +*.retry +*.log + +# System files +.DS_Store +Thumbs.db + +# Editor swap files +*.swp +*.swo +*.bak +*.tmp + +# Python cache +__pycache__/ +*.pyc +*.pyo +*.pyd + +# Virtual environment +venv/ +.env/ \ No newline at end of file diff --git a/README.md b/README.md index 983e414..58266fa 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ cp samples/hosts.sample roles/prometheus_config/files/hosts cp samples/prometheus.yml.sample roles/prometheus_config/templates/prometheus.yml.j2 ``` -The config_hosts.yml file is how we set up internal DNS lookup by editing /etc/hosts file. This will make the Grafana dashboard easier to read as each server has its human-readable name rather than an IP address like "10.0.0.1" +The `config_hosts.yml` file is how we set up internal DNS lookup by editing `/etc/hosts` file. This will make the Grafana dashboard easier to read as each server has its human-readable name rather than an IP address like `10.0.0.1` # Step 3: Run main playbook to set up a fresh monitor -The main monitor ansible file is main.yml, which sets up a new fresh monitor from scratch. It will set up firewall, install Prometheus, Grafana and Alert Manager. +The main monitor ansible file is `main.yml`, which sets up a new fresh monitor from scratch. It will set up firewall, install Prometheus, Grafana and Alert Manager. ```bash -ansible-playbook -i inventory main.yml +ansible-playbook -i inventory playbooks/main.yml ``` -That's it! +That's it! \ No newline at end of file diff --git a/group_vars/all.yml b/group_vars/all.yml new file mode 100644 index 0000000..05d8a04 --- /dev/null +++ b/group_vars/all.yml @@ -0,0 +1,9 @@ +alertmanager_port: 9093 +nginx_listen_port: 80 +nginx_server_name: monitor.polkachu.com +nginx_server_name_prometheus: prometheus.polkachu.com +nginx_prometheus_port: 9090 +nginx_proxy_grafana_port: 3000 +nginx_proxy_loki_port: 3100 +loki_grpc_listen_port: 9096 +loki_http_listen_port: 9080 \ No newline at end of file diff --git a/main.yml b/playbooks/main.yml similarity index 100% rename from main.yml rename to playbooks/main.yml diff --git a/prometheus_config.yml b/playbooks/prometheus_config.yml similarity index 100% rename from prometheus_config.yml rename to playbooks/prometheus_config.yml diff --git a/roles/alert_manager/files/alertmanager.service b/roles/alert_manager/files/alertmanager.service index 4bcc13f..74001d2 100644 --- a/roles/alert_manager/files/alertmanager.service +++ b/roles/alert_manager/files/alertmanager.service @@ -7,7 +7,7 @@ After=network-online.target User=root Group=root Type=simple -ExecStart=/usr/local/bin/alertmanager --config.file /etc/alertmanager/alertmanager.yml --web.external-url=http://localhost:9093 --cluster.advertise-address='0.0.0.0:9093' +ExecStart=/usr/local/bin/alertmanager --config.file /etc/alertmanager/alertmanager.yml --web.external-url=http://localhost:{{ alertmanager_port }} --cluster.advertise-address='0.0.0.0:{{ alertmanager_port }}' [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/grafana/files/grafana.nginx.conf b/roles/grafana/files/grafana.nginx.conf index 4ba0369..4399bdd 100644 --- a/roles/grafana/files/grafana.nginx.conf +++ b/roles/grafana/files/grafana.nginx.conf @@ -1,17 +1,17 @@ server { - listen 80 default_server; - server_name monitor.polkachu.com; + listen {{ nginx_listen_port }} default_server; + server_name {{ nginx_server_name }}; root /usr/share/nginx/html; index index.html index.htm; location / { - proxy_pass http://localhost:3000/; + proxy_pass http://localhost:{{ nginx_proxy_grafana_port }}/; proxy_set_header Host $http_host; } location /loki/ { - proxy_pass http://localhost:3100/; + proxy_pass http://localhost:{{ nginx_proxy_loki_port }}/; auth_basic "Prometheus"; auth_basic_user_file ".loki"; } diff --git a/roles/loki/files/loki.yml b/roles/loki/files/loki.yml index 4102315..9bfa390 100644 --- a/roles/loki/files/loki.yml +++ b/roles/loki/files/loki.yml @@ -1,8 +1,8 @@ auth_enabled: false server: - http_listen_port: 3100 - grpc_listen_port: 9096 + http_listen_port: {{ nginx_proxy_loki_port }} + grpc_listen_port: {{ loki_grpc_listen_port }} ingester: wal: @@ -61,7 +61,7 @@ ruler: local: directory: /tmp/loki/rules rule_path: /tmp/loki/rules-temp - alertmanager_url: http://localhost:9093 + alertmanager_url: http://localhost:{{ alertmanager_port }} ring: kvstore: store: inmemory diff --git a/roles/prometheus/files/prometheus.nginx.conf b/roles/prometheus/files/prometheus.nginx.conf index 1de6408..17ae1ef 100644 --- a/roles/prometheus/files/prometheus.nginx.conf +++ b/roles/prometheus/files/prometheus.nginx.conf @@ -1,12 +1,12 @@ server { - listen 80; - server_name prometheus.polkachu.com; + listen {{ nginx_listen_port }}; + server_name {{ nginx_server_name_prometheus }}; root /usr/share/nginx/html; index index.html index.htm; location / { - proxy_pass http://localhost:9090/; + proxy_pass http://localhost:{{ nginx_prometheus_port }}/; auth_basic "Prometheus"; auth_basic_user_file ".prometheus"; diff --git a/roles/prometheus/files/prometheus.yml b/roles/prometheus/files/prometheus.yml index 00bd0a7..880a412 100755 --- a/roles/prometheus/files/prometheus.yml +++ b/roles/prometheus/files/prometheus.yml @@ -9,4 +9,4 @@ alerting: alertmanagers: - static_configs: - targets: - - localhost:9093 + - localhost:{{ alertmanager_port }} diff --git a/roles/promtail/files/promtail.yml b/roles/promtail/files/promtail.yml index 489baf6..6a061ef 100644 --- a/roles/promtail/files/promtail.yml +++ b/roles/promtail/files/promtail.yml @@ -1,12 +1,12 @@ server: - http_listen_port: 9080 + http_listen_port: {{ loki_http_listen_port }} grpc_listen_port: 0 positions: filename: /tmp/positions.yaml clients: - - url: http://127.0.0.1:3100/loki/api/v1/push + - url: http://127.0.0.1:{{ nginx_proxy_loki_port }}/loki/api/v1/push scrape_configs: - job_name: journal