docker 部署 Prometheus

1、部署node_exporter数据采集
 docker run -d --name=node-exporter \
   --restart=always \
    -p 9100:9100 \
    -v "/proc:/host/proc:ro" \
    -v "/sys:/host/sys:ro" \
    -v "/:/rootfs:ro" \
   prom/node-exporter

访问: http://192.168.4.12:9100/metrics

2、部署Prometheus 监控

1、编写配置文件
# vim /opt/prometheus.yml global: scrape_interval: 60s evaluation_interval: 60s scrape_configs: - job_name: prometheus static_configs: - targets: ['localhost:9090'] labels: instance: prometheus - job_name: linux static_configs: - targets: ['172.17.2.4:9100'] labels: instance: localhost
2、启动 docker run
-d --name=prometheus \ -v /opt/prometheus.yml:/etc/prometheus/prometheus.yml \ --restart=always \ -p 9090:9090 \ prom/prometheus 3、访问:
http://192.168.4.12:9090
http:
//192.168.4.12:9090/graph http://192.168.4.12:9090/targets

3、部署Grafana可视化工具

1、创建目录,存储数据
#  mkdir  /data/grafana
#  chmod 777  /data/grafana

2、启动 docker run
-d --name=grafana \ -v /data/grafana:/var/lib/grafana \ --restart=always \ -p 3000:3000 \ grafana/grafana

4、监控主机

 5、监控网络设备

1)手动生成snmp.yml配置文件

                                         手动生成snmp.yml配置文件
1)安装环境
# docker run -d --name centos7 centos:centos7.9.2009
# docker exec -it centos7 bash
# yum install epel-release.noarch
# yum install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel

2)获取华为路由器oid信息
# snmpwalk -v 2c -c 密码 ip oid
# snmpwalk -v 2c -c 123456 192.168.18.111 system   系统信息

3)下载snmp-exporter
# cd /opt
# yum install golang git
# git clone https://github.com/prometheus/snmp_exporter.git

4)设置go国内代理
# go env -w GO111MODULE=on 
# go env -w GOPROXY=https://goproxy.cn,direct

5)生成generator
# cd go/snmp_exporter/generator
# go build

6)上传mib文件
# cp -a /opt/huawei/*mib  mibs/

7)修改generator.yml
# vim generator.yml
modules:
  if_mib:
    walk:
      - sysDescr
      - 1.3.6.1.2.1.1.3                     #sysUpTimeInstance
      - sysName

    version: 2
    auth:
      community: 123456

    lookups:
      - source_indexes: [ifIndex]
        lookup: ifAlias
      - source_indexes: [ifIndex]
        lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr
      - source_indexes: [ifIndex]
        lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
      - source_indexes: [entPhysicalIndex]
        lookup: 1.3.6.1.2.1.47.1.1.1.1.7 #entPhysicalName

    overrides:
      ifAlias:
        ignore: true # Lookup metric
      ifDescr:
        ignore: true # Lookup metric
      ifName:
        ignore: true # Lookup metric
      ifType:
        ignore: true # Lookup metric
      entPhysicalIndex:
        ignore: true # Lookup metric
      entPhysicalName:
        ignore: true # Lookup metric

8)生成snmp.yml文件
# export MIBDIRS=mibs
# ./generator generate
备注:export MIBDIRS=/root/go/snmp_exporter/generator/mibs:/root/go/snmp_exporter/generator/mibs/huawei_6200

 

mib文件下载:https://support.huawei.com/enterprise/zh/software/257821125-ESW2000613484

2)docker启动snmp_exporter

# docker cp centos7://opt/snmp_exporter/generator/snmp.yml /data/snmp/
# docker run -d --name snmp-exporter --restart=always \ -v /data/snmp:/etc/snmp_exporter \ -p 9116:9116 prom/snmp-exporter

验证采集路由器信息

http://192.168.4.12:9116/snmp?module=if_mib&target=192.168.18.111

3)编写prometheus.yml文件

global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: linux
    static_configs:
      - targets: ['172.17.2.3:9100']
        labels:
          instance: localhost

  - job_name: snmp
    scrape_interval: 300s
    scrape_timeout: 30s
    static_configs:
      - targets:
        - 192.168.18.111
    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: 192.168.4.12:9116
        replacement: 172.17.2.5:9116

4)重启prometheus容器

# docker restart prometheus

5)查看状态

 6)设置模板

模板下载:https://grafana.com/grafana/dashboards/

 

 

 

 

 

 

 

 

 

 

 

6、查看docker容器run启动参数

方法1:runlike
安装
# yum install -y python-pip
# pip install runlike
# yum install -y python3-pip
# pip3 install runlike
使用
# runlike -p 容器id或名

方法2:get_command_4_run_container
安装
# docker pull cucker/get_command_4_run_container
# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock cucker/get_command_4_run_container 容器id或名
别名
# echo "alias docker_get='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock cucker/get_command_4_run_container'" >> ~/.bashrc
. ~/.bashrc
# docker_get mysql

 

posted on 2023-05-09 18:01  五光十色  阅读(2232)  评论(0编辑  收藏  举报

导航