首页 公告 项目 RSS

使用snmp-exporter监控h3c路由器

March 9, 2023 本文有 1104 个字 需要花费 3 分钟阅读

简介

家里的h3c路由器是支持snmp的,所以就想着监控起来,型号是ER3200G3

找mib

首先要找mib,貌似h3c的mib都是通用的,我是从下面这个地址下载的

https://www.h3c.com/en/Products_and_Solutions/InterConnect/Operating_System/Comware_V7/MIB/MIB/201808/1106576_748048_0.htm

配置路由器

路由器这边首先开启snmp,我是v1到v3全开的,然后本地引擎ID随便输入一个比如800007DB03360102101100其他的保持默认

编译generator

首先clone项目

git clone https://github.com/prometheus/snmp_exporter.git

进入到generator工具目录

cd snmp_exporter/generator

安装依赖

apt install golang libsnmp-dev

编译

go build

创建generator.yml

下面是我的generator.yml

mmodules:
  # Default IF-MIB interfaces table with ifIndex.
  if_mib:
    walk: 
      - 1.3.6.1.2.1.1.3 # 启动时间
      - 1.3.6.1.2.1.31.1.1.1.6 # 入方向字节数
      - 1.3.6.1.2.1.31.1.1.1.10 # 出方向字节数
      - 1.3.6.1.2.1.2.2.1.8 # 端口运行状态
      - 1.3.6.1.2.1.4.20.1.1 # 获取所有的接口ip
      - 1.3.6.1.4.1.25506.2.6.1.1.1.1.6 # 获取单板CPU利用率
      - 1.3.6.1.4.1.25506.2.6.1.1.1.1.8 # 获取单板内存利用率
    auth:
      community: public

h3c路由器常用mib清单在下面

https://www.h3c.com/cn/Service/Document_Software/TechnicalInfo/PorductMaintanInfo/Router/DailyMainten/MIBList/

随便选择一个清单列表,然后找到你需要的oid就好了,然后填到上面的generator.yml中

如果你不确定oid是不是可以使用,你可以安装snmpwalk,然后使用下面的命令确认下

snmpwalk -v 2c -c public 10.10.100.1 1.3.6.1.4.1.25506.8.35.9.1.2.1.2

-v 表示的是snmp的版本,-c 表示团体名,之后就是ip,最后是oid

生成snmp.yaml

把最上面的mib文件解压,然后把里面所有的单独文件都放到项目里面的mib文件夹中

生成

./generator generate -o snmp.yml

安装snmp-exporter

编写deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: h3c-snmp-exporter
  namespace: app
spec:
  selector:
    matchLabels:
      app: h3c-snmp-exporter
  template:
    metadata:
      labels:
        app: h3c-snmp-exporter
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: h3c-snmp-exporter
        image: prom/snmp-exporter:v0.21.0
        ports:
        - containerPort: 9116
        env:
          - name: TZ
            value: "Asia/Shanghai"
        args:
          - "--config.file=/h3c-snmp-exporter/snmp.yml"
        volumeMounts:
          - mountPath: /h3c-snmp-exporter/snmp.yml
            name: h3c-snmp-exporter-config
            subPath: snmp.yml
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
      volumes:
        - name: h3c-snmp-exporter-config
          configMap: 
            name: h3c-snmp-exporter-config
            items:
              - key: snmp.yml
                path: snmp.yml

编写configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: h3c-snmp-exporter-config
  namespace: app
data:
  snmp.yml: |-
    # WARNING: This file was auto-generated using snmp_exporter generator, manual changes will be lost.
    if_mib:
      walk:
      - 1.3.6.1.2.1.2.2.1.8
      - 1.3.6.1.2.1.31.1.1.1.10
      - 1.3.6.1.2.1.31.1.1.1.6
      - 1.3.6.1.2.1.4.20.1.1
      - 1.3.6.1.4.1.25506.2.6.1.1.1.1.6
      - 1.3.6.1.4.1.25506.2.6.1.1.1.1.8
      get:
      - 1.3.6.1.2.1.1.3.0
      metrics:
      - name: sysUpTime
        oid: 1.3.6.1.2.1.1.3
        type: gauge
        help: The time (in hundredths of a second) since the network management portion
          of the system was last re-initialized. - 1.3.6.1.2.1.1.3
      - name: ifOperStatus
        oid: 1.3.6.1.2.1.2.2.1.8
        type: gauge
        help: The current operational state of the interface - 1.3.6.1.2.1.2.2.1.8
        indexes:
        - labelname: ifIndex
          type: gauge
        enum_values:
          1: up
          2: down
          3: testing
          4: unknown
          5: dormant
          6: notPresent
          7: lowerLayerDown
      - name: ifHCOutOctets
        oid: 1.3.6.1.2.1.31.1.1.1.10
        type: counter
        help: The total number of octets transmitted out of the interface, including framing
          characters - 1.3.6.1.2.1.31.1.1.1.10
        indexes:
        - labelname: ifIndex
          type: gauge
      - name: ifHCInOctets
        oid: 1.3.6.1.2.1.31.1.1.1.6
        type: counter
        help: The total number of octets received on the interface, including framing
          characters - 1.3.6.1.2.1.31.1.1.1.6
        indexes:
        - labelname: ifIndex
          type: gauge
      - name: ipAdEntAddr
        oid: 1.3.6.1.2.1.4.20.1.1
        type: InetAddressIPv4
        help: The IPv4 address to which this entry's addressing information pertains.
          - 1.3.6.1.2.1.4.20.1.1
        indexes:
        - labelname: ipAdEntAddr
          type: InetAddressIPv4
      - name: hh3cEntityExtCpuUsage
        oid: 1.3.6.1.4.1.25506.2.6.1.1.1.1.6
        type: gauge
        help: The CPU usage for this entity - 1.3.6.1.4.1.25506.2.6.1.1.1.1.6
        indexes:
        - labelname: hh3cEntityExtPhysicalIndex
          type: gauge
      - name: hh3cEntityExtMemUsage
        oid: 1.3.6.1.4.1.25506.2.6.1.1.1.1.8
        type: gauge
        help: The memory usage for the entity - 1.3.6.1.4.1.25506.2.6.1.1.1.1.8
        indexes:
        - labelname: hh3cEntityExtPhysicalIndex
          type: gauge
      auth:
        community: public    

编写service

apiVersion: v1
kind: Service
metadata:
  name: h3c-snmp-exporter
  namespace: app
spec:
  type: ClusterIP
  selector:
    app: h3c-snmp-exporter
  ports:
  - port: 80
    targetPort: 9116
    name: http

然后是kustomization.yaml

resources:
- deploy.yaml
- svc.yaml
- configmap.yaml

argocd 部分

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: h3c-snmp-exporter
spec:
  destination:
    name: ''
    namespace: ''
    server: 'https://kubernetes.default.svc'
  source:
    path: k8s/h3c-snmp-exporter
    repoURL: 'https://xxxxx.xxx.xx/bboysoul/kubernetes-yaml'
    targetRevision: HEAD
  project: default
  syncPolicy:
    automated: null

配置prometheus

      - job_name: 'h3c-snmp-exporter'
        static_configs:
          - targets:
            - 10.10.100.1  # SNMP device.
        metrics_path: /snmp
        params:
          module: [if_mib]
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: h3c-snmp-exporter

添加grafana dashboard

这个就没有什么好说的了

最后吐槽两句

如果的产品过了保修期,那么你打h3c的客服,他们是不会帮助你的,你只能论坛发帖子,草

欢迎关注我的博客www.bboy.app

Have Fun