服务器问题

云服务器怎样设计Grafana+VictoriaMetrics监控方案

一、VictoriaMetrics安装

1. 单节点部署

  1. bash
    # 下载VictoriaMetrics
    wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.91.3/victoria-metrics-linux-amd64-v1.91.3.tar.gz
    tar xzf victoria-metrics-linux-amd64-v1.91.3.tar.gz

    # 创建存储目录
    mkdir -/data/victoria-metrics

    # 启动服务
    ./victoria-metrics \
    -storageDataPath=/data/victoria-metrics \
    -retentionPeriod=3 \
    -httpListenAddr=:8428

2. 集群部署配置

  1. yaml
    # docker-compose.yml
    version:'3'
    services:
      vmstorage:
        image: victoriametrics/vmstorage
        command:
    -"--storageDataPath=/storage"
        volumes:
    - storage-data:/storage

      vmselect:
        image: victoriametrics/vmselect
        depends_on:
    - vmstorage
        command:
    -"--storageNode=vmstorage:8400"

      vminsert:
        image: victoriametrics/vminsert
        depends_on:
    - vmstorage
        command:
    -"--storageNode=vmstorage:8400"

二、Grafana配置

1. Grafana安装

  1. bash
    # 添加Grafana源
    wget --- https://packages.grafana.com/gpg.key | apt-key add -
    echo "deb https://packages.grafana.com/oss/deb stable main"| tee /etc/apt/sources.list.d/grafana.list

    # 安装Grafana
    apt update
    apt install -y grafana

    # 启动服务
    systemctl enable grafana-server
    systemctl start grafana-server

2. 数据源配置

  1. json
    {
    "name":"VictoriaMetrics",
    "type":"prometheus",
    "url":"http://localhost:8428",
    "access":"proxy",
    "basicAuth":false,
    "isDefault":true
    }

三、数据采集配置

1. vmagent配置

  1. yaml
    # vmagent.yml
    global:
      scrape_interval:15s
      evaluation_interval:15s

    scrape_configs:
    - job_name:'node'
        static_configs:
    - targets:['localhost:9100']

    - job_name:'mysql'
        static_configs:
    - targets:['localhost:9104']

2. 服务发现配置

  1. yaml
    # service-discovery.yml
    scrape_configs:
    - job_name:'kubernetes-pods'
        kubernetes_sd_configs:
    - role: pod
        relabel_configs:
    - source_labels:[__meta_kubernetes_pod_annotation_prometheus_io_scrape]
            action: keep
            regex:true

四、告警配置

1. 告警规则

  1. yaml
    # rules.yml
    groups:
    - name: server_alerts
      rules:
    - alert:HighCPUUsage
        expr:100-(avg by(instance)(irate(node_cpu_seconds_total{mode="idle"}[5m]))*100)>80
    for:5m
        labels:
          severity: warning
        annotations:
          summary:"High CPU usage on {{$labels.instance}}"

2. 告警通知

  1. json
    // Grafana告警通道配置
    {
    "name":"webhook",
    "type":"webhook",
    "settings":{
    "url":"http://alert-webhook:8080/notify",
    "httpMethod":"POST"
    }
    }

五、Dashboard配置

1. 系统监控面板

  1. json
    {
    "dashboard":{
    "panels":[
    {
    "title":"CPU Usage",
    "type":"graph",
    "datasource":"VictoriaMetrics",
    "targets":[
    {
    "expr":"100 - (avg by (instance) (irate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
    }
    ]
    }
    ]
    }
    }

2. 性能监控面板

  1. json
    {
    "dashboard":{
    "panels":[
    {
    "title":"Memory Usage",
    "type":"gauge",
    "datasource":"VictoriaMetrics",
    "targets":[
    {
    "expr":"node_memory_MemUsed_bytes / node_memory_MemTotal_bytes * 100"
    }
    ]
    }
    ]
    }
    }

六、性能优化

1. VictoriaMetrics优化

  1. bash
    # VictoriaMetrics启动参数优化
    ./victoria-metrics \
    -storageDataPath=/data/victoria-metrics \
    -memory.allowedPercent=60 \
    -search.maxUniqueTimeseries=1000000 \
    -search.maxQueryDuration=30s

2. Grafana性能调优

  1. ini
    # grafana.ini
    [server]
    http_port =3000
    root_url = https://grafana.example.com

    [database]
    type = mysql
    host = localhost:3306
    name = grafana
    user = grafana
    password = password

    [session]
    provider = redis
    provider_config = addr=127.0.0.1:6379



免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:bkook@qq.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
上一篇:云服务器怎样搭建Harbor私有镜像仓库
下一篇:云服务器怎样部署Graylog日志分析平台
0

在线
客服

在线客服服务时间:9:00-18:00

客服
热线

19899115815
7*24小时客服服务热线

关注
微信

关注官方微信
顶部