单机部署-loki日志收集-prometheus系统监控

使用docekr-compose一键部署,适合一台物理服务器部署解决监控和日志问题。资源占用比较少。还可以再加上告警。

使用了loki、promtail、node_exporter、prometheus、grafana
统一在grafana页面查询日志,查看监控情况。
grafanan - dashboard - import - ID: 11074

version: "3"

networks:
  loki:

services:
  loki:
    image: grafana/loki:2.8.0
    restart: always
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml
    networks:
      - loki

  promtail:
    image: grafana/promtail:2.8.0
    restart: always
    volumes:
      # chmod a+rw /var/run/docker.sock
      - /var/run/docker.sock:/var/run/docker.sock
      - ./promtail-config.yaml:/etc/promtail/config.yaml
    command: -config.file=/etc/promtail/config.yaml
    networks:
      - loki

  node_exporter:
    image: bitnami/node-exporter:1.5.0
    command:
      - '--path.rootfs=/host'
    network_mode: host
    pid: host
    restart: unless-stopped
    volumes:
      - '/:/host:ro,rslave'

  prometheus:
    image: bitnami/prometheus:2.44.0
    restart: always
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus-config.yaml:/opt/bitnami/prometheus/conf/prometheus.yml
    networks:
      - loki

  grafana:
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    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
        - name: Prometheus
          type: prometheus
          access: proxy
          url: http://prometheus:9090
          editable: false
        EOF
        /run.sh
    image: grafana/grafana:8.3.3
    restart: always
    ports:
      - "3000:3000"
    networks:
      - loki

promtail-config.yaml

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: flog_scrape 
    docker_sd_configs:
      - host: unix:///var/run/docker.sock
        refresh_interval: 5s
    relabel_configs:
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: 'container'

prometheus-config.yaml

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["your host ip:9100"]

你可能感兴趣的:(grafana,prometheus,loki)