Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
software:monitoring [2025/11/15 05:15] – [promtail_config] 192.168.1.159software:monitoring [2025/12/07 02:38] (текущий) – [Программные средства] mirocow
Строка 1: Строка 1:
-{{tag>[loki docker swarm promtail grafana]}}+{{tag>[loki docker swarm promtail grafana monitoring fluentd fluent-bit prometheus}}
  
-====== Docker Swarm + Loki + Protmail + Grafana ======+====== Мониторинг ======
  
-===== Версии===== +{{:software:67567.jpg?600|}}
-  +
-  * grafana/loki:3.5.8 +
-  * grafana/promtail:3.5.8 +
-  * grafana/grafana:10.2.2+
  
-===== Настройки =====+Мониторинг IT-инфраструктуры (ИТ-мониторинг) — это процесс постоянного сбора, обработки и анализа данных о состоянии элементов ИТ-среды: серверов, сетевых устройств, приложений, каналов связи и других компонентов. Цель — обеспечить стабильность, безопасность и эффективность инфраструктуры, своевременно выявлять и устранять проблемы. 
  
-==== loki_config ====+  * Минимизация времени простоя — быстрая реакция на проблемы (перезапуск служб, уведомление администраторов, автоматизированные действия) сокращает время простоя. 
 +  * Снижение операционных расходов — автоматизация контроля сети, серверов, приложений уменьшает нагрузку на сотрудников, сокращает число ручных проверок. 
 +  * Улучшение пользовательского опыта — стабильная работа систем влияет на удовлетворённость клиентов и сотрудников, мониторинг помогает обеспечивать оптимальное время ответа приложений и сервисов. 
 +  * Планирование развития инфраструктуры — анализ исторических данных и трендов позволяет прогнозировать будущие потребности в ресурсах и планировать развитие ИТ-инфраструктуры.
  
-<code yaml> +===== Программы =====
-auth_enabled: false+
  
-server: +Grafana, Promtail, Loki, Prometheus, Fluent Bit, Fluentd, Kibana, Logstah, Elasticsearch, ELK, Zabbix, Alloy.
-  http_listen_port: 3100 +
-  grpc_listen_port: 9096 +
-  log_level: info +
-  # Таймауты для стабильности +
-  http_server_read_timeout: 300s +
-  http_server_write_timeout: 300s+
  
-common: +==== Рекомендации ====
-  path_prefix: /loki +
-  storage: +
-    filesystem: +
-      chunks_directory: /loki/chunks +
-      rules_directory: /loki/rules +
-  replication_factor:+
-  ring: +
-    instance_addr: 0.0.0.0 +
-    kvstore: +
-      store: inmemory+
  
-# Критически важные настройки для query-frontend +  * Использовать Fluentd или Fluent Bit, которые умеют отправлять данные в Loki. В отличие от Promtail они имеют готовые парсеры практически для любого вида лога и справляются в том числе с multiline-логами.
-query_scheduler: +
-  max_outstanding_requests_per_tenant: 2048+
  
-frontend: +===== Программные средства =====
-  # Параметр max_outstanding_per_tenant удален из этой секции +
-  log_queries_longer_than: 30s +
-  compress_responses: true+
  
-query_range: 
-  parallelise_shardable_queries: true 
-  results_cache: 
-    cache: 
-      embedded_cache: 
-        enabled: true 
-        max_size_mb: 100 
-  max_retries: 5 
  
-limits_config+  * [[system:universal]] 
-  # Таймаут запросов теперь настраивается здесь +  * [[.monitoring:promtail-loki-grafana]] 
-  query_timeout5m +  * [[.monitoring:fluent-bit-loki-grafana]] 
-   +  * [[.monitoring:fluent-bit-fluentd-loki-grafana]] 
-  ingestion_rate_mb1000 +  * [[.monitoring:prometheus]] 
-  ingestion_burst_size_mb: 2000 +  * [[system:ctop]] 
-  max_line_size: 256000 +  * [[system:htop]] 
-  reject_old_samples: true +  * [[system:iotop]] 
-  reject_old_samples_max_age: 168h +  * [[software:iperf3]] 
-  max_entries_limit_per_query: 50000 +  * [[:lsof]] 
-  retention_period: 8760h +  * [[system:elasticsearch:logstash]] 
-  max_query_length: 721h +  * [[:lm-sensors]] 
-  max_query_parallelism: 32 +  * [[mysql:mytop]] 
- +  * [[network:netstat]] 
-schema_config: +  * [[system:rsyslog]] 
-  configs: +  * [[:tcpdump]] 
-    from: 2024-01-01 +  * [[system:top]] 
-      store: tsdb +  * [[system:watch]] 
-      object_store: filesystem +  [[ping:zabbix]] 
-      schema: v13 +  [[system:vmstat]
-      index: +  * [[:software:monitoring:promtail]] 
-        prefix: index_ +  * [[software:monitoring:fluent-bit]] 
-        period: 24h +  * [[system:syslog]]
- +
-ingester: +
-  wal: +
-    enabled: true +
-    dir: /loki/wal +
-    flush_on_shutdown: true +
-  lifecycler: +
-    ring: +
-      kvstore: +
-        store: inmemory +
-      replication_factor:+
-      heartbeat_timeout: 1m +
-  chunk_idle_period: 1h +
-  max_chunk_age: 2h +
-  chunk_target_size: 1572864 +
-  chunk_retain_period: 30s +
- +
-storage_config: +
-  tsdb_shipper: +
-    active_index_directory: /loki/index +
-    cache_location: /loki/tsdb-shipper-cache +
-  filesystem: +
-    directory: /loki/chunks +
- +
-compactor: +
-  working_directory: /loki/boltdb-shipper-compactor +
-  retention_enabledtrue +
-  compaction_interval30m +
-  # ИСПРАВЛЕНИЕДобавляем конфигурацию для delete request store +
-  delete_request_storefilesystem +
-  delete_request_cancel_period: 24h +
- +
- +
-querier+
-  max_concurrent256 +
-  tail_max_duration1h +
- +
-analytics+
-  reporting_enabled: false +
-</code> +
- +
-==== promtail_config ==== +
- +
-<code yaml> +
-server+
-  http_listen_port9080 +
-  http_listen_address: 0.0.0.0 +
- +
-positions+
-  filename/tmp/positions.yaml +
-  # Запись позиций каждые 15 секунд +
-  sync_period: 15s +
- +
-clients+
-  - urlhttp://loki:3100/loki/api/v1/push +
-    backoff_config: +
-      min_period: 10s +
-      max_period: 5m +
-      max_retries: 50 +
-    batchwait: 30s +
-    batchsize: 2097152 +
-    timeout: 60s +
-    external_labels: +
-      cluster: docker-swarm +
-      host: "${HOSTNAME}" +
- +
-scrape_configs: +
- +
-  - job_name: docker_containers +
-    docker_sd_configs: +
-      - host: unix:///var/run/docker.sock +
-        refresh_interval: 60s +
-        filters: +
-          - name: status +
-            values: ["running"] +
-    relabel_configs: +
-      - target_label: job +
-        replacement: docker_containers +
-      - source_labels: [__meta_docker_container_name+
-        regex: '/(.*)' +
-        target_label: container +
-        action: replace +
-      - source_labels: [__meta_docker_container_label_com_docker_swarm_service_name] +
-        target_label: service +
-        regex: ".+" +
-        action: keep +
-      - source_labels: [__meta_docker_container_label_com_docker_swarm_service_name] +
-        target_labelswarm_service_name +
-      - source_labels: [__meta_docker_stack_namespace] +
-        target_label: stack +
-        action: replace +
-      - source_labels: [__meta_docker_swarm_node_id+
-        target_label: node_id +
-        action: replace +
-      - source_labels: [__meta_docker_container_label_com_docker_swarm_node_hostname] +
-        target_label: node +
-        action: replace +
-      - source_labels: [__meta_docker_container_log_stream] +
-        target_labellog_stream +
-        action: replace +
-      - source_labels: [__meta_docker_container_id] +
-        target_label: container_id +
-        action: replace +
-      - source_labels: [__meta_docker_container_image] +
-        target_label: image +
-        action: replace +
-      # Правило дропа для тестирования +
-      # - source_labels: [__meta_docker_container_name] +
-      #   regex: '(promtail|loki|grafana)' +
-      #   action: drop +
-    pipeline_stages: +
-      - docker: {} +
-      - timestamp: +
-          source: current_time +
-          format: RFC3339 +
- +
-  - job_name: journal_logs +
-    journal: +
-      max_age: 24h +
-      path: /var/log/journal +
-      labels: +
-        job: systemd_journal +
-    relabel_configs: +
-      - source_labels: [__journal__hostname] +
-        target_label: node +
-      - source_labels: [__journal__systemd_unit] +
-        target_labelunit +
-      - source_labels: [__journal__syslog_identifier] +
-        target_label: component +
-    pipeline_stages: +
-      - timestamp: +
-          source: current_time +
-          format: RFC3339 +
-</code> +
- +
-===== Docker Compose ===== +
- +
- +
-monitoring +
-<code yaml> +
-version: "3.8" +
- +
-services: +
- +
-  loki: +
-    imagegrafana/loki:3.5.8 +
-    ports: +
-      - "3100:3100" +
-    configs: +
-      - source: loki_config +
-        target: /etc/loki/local-config.yaml +
-    volumes: +
-      - loki_data:/loki +
-      - /etc/localtime:/etc/localtime:ro +
-      - /etc/timezone:/etc/timezone:ro +
-    command:  +
-      - -config.file=/etc/loki/local-config.yaml +
-      - -config.expand-env=true +
-      - -target=all +
-    networks: +
-      - monitoring +
-    deploy: +
-      placement: +
-        constraints: +
-          - node.role == manager +
-      resources: +
-        limits: +
-          memory: 2G  # Уменьшаем память +
-          cpus: '1.0' +
-        reservations: +
-          memory: 1G +
-          cpus: '0.5' +
-      restart_policy: +
-        condition: on-failure +
-        delay: 10s +
-        max_attempts:+
- +
-  promtail+
-    image: grafana/promtail:3.5.8 +
-    configs: +
-      - source: promtail_config +
-        target: /etc/promtail/config.yaml +
-    volumes: +
-      - /var/run/docker.sock:/var/run/docker.sock:ro +
-      - /var/log:/var/log:ro +
-      - /var/lib/docker/containers:/var/lib/docker/containers:ro +
-      - /var/log/journal:/var/log/journal:ro +
-      - /run/systemd/journal:/run/systemd/journal:ro +
-      - promtail_positions:/tmp +
-      - /etc/localtime:/etc/localtime:ro +
-      - /etc/timezone:/etc/timezone:ro +
-    command:  +
-      - -config.file=/etc/promtail/config.yaml +
-      - -client.external-labels=host=${HOSTNAME} +
-      - -config.expand-env=true +
-      #- -log.level=info +
-    environment: +
-      - HOSTNAME={{.Node.Hostname}} +
-    networks: +
-      - monitoring +
-    deploy: +
-      mode: global +
-      resources: +
-        limits: +
-          memory: 512M +
-          cpus: '0.5' +
-        reservations: +
-          memory: 256M +
-          cpus: '0.25' +
-      restart_policy: +
-        condition: any +
-        delay: 30s +
-        max_attempts: 10 +
- +
-  grafana: +
-    image: grafana/grafana:10.2.2 +
-    ports: +
-      - "3000:3000" +
-    environment: +
-      - GF_SECURITY_ADMIN_PASSWORD=admin +
-      - GF_SECURITY_ADMIN_USER=admin +
-      - GF_USERS_ALLOW_SIGN_UP=false +
-    volumes: +
-      - grafana_data:/var/lib/grafana +
-      - /etc/localtime:/etc/localtime:ro +
-      - /etc/timezone:/etc/timezone:ro +
-    networks: +
-      - monitoring +
-    deploy: +
-      placement: +
-        constraints: +
-          node.role == manager +
-      resources: +
-        limits: +
-          memory: 512M +
-          cpus: '0.5' +
-        reservations: +
-          memory: 256M +
-          cpus: '0.25' +
- +
-configs: +
-  loki_config: +
-    external: true +
-  promtail_config: +
-    external: true +
- +
-networks: +
-  monitoring: +
-    driver: overlay +
-    attachable: true +
- +
- +
-volumes: +
-  promtail_positions: +
-    driver: local +
-  loki_data: +
-    driver: local +
-  grafana_data: +
-    driver: local +
-</code>+