采用Prometheus+Grafana 监控H3C交换机状态

it不难
2022-09-17 / 0 评论 / 12 阅读 / 正在检测是否收录...

前言

部署过程

docker基本环境

docker和docker-compose一键安装脚本

docker-compose.yml

version: "3.8"
networks:
    net:
        driver: bridge

services:
  snmp-exporter:
    image: prom/snmp-exporter:latest
    container_name: ly-monitor-snmp-exporter
    restart: always
    ports:
      - "9116:9116"
    volumes:
      - "./myapp/snmp/snmp.yml:/etc/snmp_exporter/snmp.yml"
    networks:
      - net

  prometheus:
    image: prom/prometheus:latest
    container_name: ly-monitor-prometheus
    restart: always
    user: "0"
    ports:
      - "9090:9090"
    volumes:
      - "./myapp/prometheus/:/prometheus"
    command:
      - "--storage.tsdb.retention.time=180d"
      - "--config.file=/prometheus/prometheus.yml"
      - "--web.enable-lifecycle"
    networks:
      - net
    depends_on:
      - snmp-exporter

  grafana:
    image: grafana/grafana:latest
    restart: always
    container_name: ly-monitor-grafana
    user: "0"
    ports:
      - "3000:3000"
    environment:
      - "GF_SECURITY_ADMIN_PASSWORD=xxxxxx"  #grafana登录密码,自己设置
      - "GF_RENDERING_SERVER_URL=http://renderer:8081/render"
      - "GF_RENDERING_CALLBACK_URL=http://grafana:3000/"
      - "GF_LOG_FILTERS=rendering:debug"
    volumes:
      - ./data/grafana/:/var/lib/grafana
    networks:
      - net
    depends_on:
      - prometheus
      - renderer

  renderer:
    image: grafana/grafana-image-renderer:latest
    container_name: ly-monitor-renderer
    ports:
      - "8081:8081"
    environment:
      - "ENABLE_METRICS=true"
      - "RENDERING_MODE=clustered"
      - "RENDERING_CLUSTERING_MODE=context"
      - "RENDERING_CLUSTERING_MAX_CONCURRENCY=5"
    networks:
      - net

snmp-exporter配置

Dockerfile

FROM golang:latest

RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && \
    rm -Rf /var/lib/apt/lists/* && \
    apt-get update && \
    apt-get install -y libsnmp-dev p7zip-full unzip

ENV  GO111MODULE on
ENV  GOPROXY https://goproxy.cn

RUN  go install github.com/prometheus/snmp_exporter/generator@latest

WORKDIR "/opt"

generator.yml

prometheus.yaml

# my global config
global:
  scrape_interval: 60s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 60s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'snmp'
    scrape_timeout: 30s   # 采集超时10s
    scrape_interval: 1m  # 采集频率1m
    static_configs:
      - targets:
        - 10.10.10.62  #交换机ip
    metrics_path: /snmp
    params:
      module: [H3C]  #修改成2.4步自己设置的mib名称
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: snmp-exporter:9116   # 安装snmp_exporter主机的ip和端口号

生成过程

#构建镜像
cd src/generator/ &&  docker build -t  generator  .  &&  cd -

#获取mibs并放到 .src/generator/mibs 目录下
#生成snmp.yaml
docker run -it --rm -v /opt/ly-monitor/src/:/opt  --privileged  generator   /bin/bash
export MIBDIRS=/opt/generator/mibs
cd generator/ && generator generate
exit

#移动到目标位置
/bin/cp   -f src/generator/snmp.yml  myapp/snmp/

启动服务

docker-compose up -d

访问

http://ip:3000/login

FAQ

snmp_exporter获取数据报错

snmpwalk -v 3 -t 2 -u hcuser -l authPriv -a sha -A  hcxxxx234 -x des -X  hcyyyy234  192.168.4.62  ifAlias

0

评论 (0)

取消