diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index c09ecc1af3..0000000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,71 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "master" ] - paths: [ "app_python/**" ] - pull_request: - branches: [ "master" ] - paths: [ "app_python/**" ] - pull_request: - branches: [ "master" ] - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Snyk - uses: snyk/actions/python-3.10@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - with: - args: app_python/ --skip-unresolved - - - name: Test - run: | - cd app_python - python -m unittest tests.py - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push Docker image - uses: docker/build-push-action@v6.13.0 - with: - context: "{{defaultContext}}:app_python" - push: true - tags: ${{ vars.DOCKERHUB_USERNAME }}/moscow_time:latest - cache-from: type=gha - cache-to: type=gha,mode=max - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest diff --git a/monitoring/METRICS.md b/monitoring/METRICS.md new file mode 100644 index 0000000000..1ce4c96cdb --- /dev/null +++ b/monitoring/METRICS.md @@ -0,0 +1,15 @@ +## Prometheus website working + +![](static/prometheus_site.png) + +## Grafana Metrics Example + +![](static/grafana_metrics.png) + +## Containers' logs Resources Configuration + +All Containers have been set the following resource parameters: + +- Memory Limits: 512MB +- Memory Reservation: 256MB +- Log Rotation: 10MB max size, 3 files diff --git a/monitoring/docker-compose.yml b/monitoring/docker-compose.yml index bd5176add9..54a79eac6a 100644 --- a/monitoring/docker-compose.yml +++ b/monitoring/docker-compose.yml @@ -1,77 +1,133 @@ -version: "3.3" - networks: - loki: + monitoring: services: + app: + build: + context: ../app_python + dockerfile: Dockerfile + container_name: app + restart: unless-stopped + networks: + - monitoring + ports: + - "8000:5005" + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + deploy: + resources: + limits: + memory: 256M + reservations: + memory: 128M + loki: image: grafana/loki:latest + container_name: loki + restart: unless-stopped + networks: + - monitoring ports: - "3100:3100" - volumes: - - ./loki:/etc/loki command: -config.file=/etc/loki/local-config.yaml + user: "0" + healthcheck: + test: ["CMD-SHELL", "wget -q --tries=1 -O- http://localhost:3100/ready || exit 1"] + interval: 10s + timeout: 3s + retries: 3 + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + deploy: + resources: + limits: + memory: 256M + reservations: + memory: 128M + + prometheus: + image: prom/prometheus:v2.42.0 + container_name: prometheus + ports: + - "9090:9090" + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml networks: - - loki + - monitoring + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + deploy: + resources: + limits: + memory: 256M + reservations: + memory: 128M promtail: image: grafana/promtail:latest + container_name: promtail volumes: - - /var/log:/var/log + - /var/lib/docker/containers:/var/lib/docker/containers:ro - /var/run/docker.sock:/var/run/docker.sock - - /var/lib/docker/containers:/var/lib/docker/containers - - ./promtail.yml:/etc/promtail/config.yml + - ./promtail-config.yaml:/etc/promtail/config.yml command: -config.file=/etc/promtail/config.yml networks: - - loki + - monitoring + depends_on: + loki: + condition: service_healthy + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + deploy: + resources: + limits: + memory: 256M + reservations: + memory: 128M grafana: - environment: - - GF_PATHS_PROVISIONING=/etc/grafana/provisioning - - GF_AUTH_ANONYMOUS_ENABLED=true - - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin - - GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode - entrypoint: - - sh - - -euc - - | - mkdir -p /etc/grafana/provisioning/datasources - cat < /etc/grafana/provisioning/datasources/ds.yaml - apiVersion: 1 - datasources: - - name: Loki - type: loki - access: proxy - orgId: 1 - url: http://loki:3100 - basicAuth: false - isDefault: true - version: 1 - editable: false - EOF - /run.sh image: grafana/grafana:latest - ports: - - "3000:3000" + container_name: grafana + restart: unless-stopped networks: - - loki - moscow_time: - image: tjann7/moscow_time:latest + - monitoring ports: - - "5005:5005" + - "3000:3000" + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_USERS_ALLOW_SIGN_UP=false + volumes: + - grafana-storage:/var/lib/grafana + - ./grafana/provisioning/:/etc/grafana/provisioning/ + depends_on: + loki: + condition: service_healthy logging: driver: "json-file" - go_random: - image: tjann7/go_random:latest - ports: - - "5500:5500" - prometheus: - image: prom/prometheus:latest - ports: - - "9090:9090" - volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml - command: - - "--config.file=/etc/prometheus/prometheus.yml" - networks: - - loki + options: + max-size: "10m" + max-file: "3" + deploy: + resources: + limits: + memory: 256M + reservations: + memory: 128M + +volumes: + grafana-storage: {} + loki-data: {} + loki-wal: {} \ No newline at end of file diff --git a/monitoring/loki-config.yaml b/monitoring/loki-config.yaml new file mode 100644 index 0000000000..868c3ebd41 --- /dev/null +++ b/monitoring/loki-config.yaml @@ -0,0 +1,59 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + +common: + path_prefix: /loki + storage: + filesystem: + chunks_directory: /loki/chunks + rules_directory: /loki/rules + replication_factor: 1 + ring: + kvstore: + store: inmemory + +schema_config: + configs: + - from: 2020-10-24 + store: boltdb-shipper + object_store: filesystem + schema: v11 + index: + prefix: index_ + period: 24h + +ruler: + alertmanager_url: http://localhost:9093 + +limits_config: + retention_period: 744h + enforce_metric_name: false + reject_old_samples: true + reject_old_samples_max_age: 744h + ingestion_rate_mb: 64 + ingestion_burst_size_mb: 128 + per_stream_rate_limit: 32MB + per_stream_rate_limit_burst: 64MB + +chunk_store_config: + max_look_back_period: 744h + +table_manager: + retention_deletes_enabled: true + retention_period: 744h + +ingester: + lifecycler: + address: 127.0.0.1 + ring: + kvstore: + store: inmemory + replication_factor: 1 + final_sleep: 0s + chunk_idle_period: 1h + chunk_retain_period: 30s + wal: + enabled: true + dir: /wal \ No newline at end of file diff --git a/monitoring/prometheus.yml b/monitoring/prometheus.yml index 722656caba..2b67d65dce 100644 --- a/monitoring/prometheus.yml +++ b/monitoring/prometheus.yml @@ -1,27 +1,15 @@ ---- global: scrape_interval: 15s scrape_configs: - - job_name: "prometheus" + - job_name: 'loki' static_configs: - - targets: ["prometheus:9090"] + - targets: ['loki:3100'] - - job_name: "moscow_time" - metrics_path: "/metrics" + - job_name: 'grafana' static_configs: - - targets: ["moscow_time:5005"] + - targets: ['grafana:3000'] - - job_name: "go_random" - metrics_path: "/metrics" + - job_name: 'prometheus' static_configs: - - targets: ["go_random:5500"] - - - job_name: "loki" - static_configs: - - targets: ["loki:3100"] - - - job_name: "grafana" - metrics_path: "/metrics" - static_configs: - - targets: ["grafana:3000"] + - targets: ['prometheus:9090'] diff --git a/monitoring/promtail-config.yaml b/monitoring/promtail-config.yaml new file mode 100644 index 0000000000..0ea62997a5 --- /dev/null +++ b/monitoring/promtail-config.yaml @@ -0,0 +1,19 @@ +server: + http_listen_port: 9080 + grpc_listen_port: 0 + +positions: + filename: /tmp/positions.yaml + +clients: + - url: http://loki:3100/loki/api/v1/push + +scrape_configs: +- job_name: docker + docker_sd_configs: + - host: unix:///var/run/docker.sock + refresh_interval: 5s + relabel_configs: + - source_labels: ['__meta_docker_container_name'] + regex: '/(.*)' + target_label: 'container' \ No newline at end of file diff --git a/monitoring/promtail.yml b/monitoring/promtail.yml deleted file mode 100644 index e7015766ee..0000000000 --- a/monitoring/promtail.yml +++ /dev/null @@ -1,15 +0,0 @@ -server: - http_listen_port: 9080 - grpc_listen_port: 0 -positions: - filename: /tmp/positions.yaml -client: - url: http://loki:3100/api/v1/push -scrape_configs: - - job_name: logging_both_dockersW - static_configs: - - targets: - - localhost - labels: - job: docker - __path__: /var/lib/docker/containers/*/*log # For linux only diff --git a/monitoring/static/grafana_metrics.png b/monitoring/static/grafana_metrics.png new file mode 100644 index 0000000000..bcaebc6148 Binary files /dev/null and b/monitoring/static/grafana_metrics.png differ diff --git a/monitoring/static/prometheus_site.png b/monitoring/static/prometheus_site.png new file mode 100644 index 0000000000..ee9601c68b Binary files /dev/null and b/monitoring/static/prometheus_site.png differ