snmp-exporter安装使用说明

前置环境

yum install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-deve
yum install gcc-c++

安装go

建议不要安装最新版本,go1.17版本对go get做了严格定义,只能用go install,go install下载安装不了snmp-exporter
本地安装go1.15.6

tar -C /usr/local -xzf go1.15.6.linux-amd64.tar.gz
#将go文件加入PATH,方便使用快捷键
export PATH=$PATH:/usr/local/go/bin
#启用 Go Modules功能
export GO111MODULE=on
#设置代理

安装snmp_exporter generate

下载安装命令
go get -v github.com/prometheus/snmp_exporter/generatorgithub.com/prometheus/snmp_exporter

[root@K8s-Master go]# go get -v github.com/prometheus/snmp_exporter/generatorgithub.com/prometheus/snmp_exporter 

(download)github.com/go-kit/kit (download)
# cd .; git clone -- https://github.com/go-kit/kit /root/go/src/github.com/go-kit/kitfatal: unable to access 'https://github.com/go-kit/kit/': Encountered end of filepackage github.com/go-kit/kit/log: exit status 128cannot find package "github.com/go-kit/kit/log/level" in any of:
        /usr/local/go/src/github.com/go-kit/kit/log/level (from $GOROOT)          
        /root/go/src/github.com/go-kit/kit/log/level (from $GOPATH)github.com/prometheus/common (download)
# cd .; git clone -- https://github.com/prometheus/common /root/go/src/github.com/prometheus/commonerror: RPC failed; result=35, HTTP code = 0fatal: The remote end hung up unexpectedlypackage github.com/prometheus/common/promlog: exit status 128cannot find package "github.com/prometheus/common/promlog/flag" in any of:       
      /usr/local/go/src/github.com/prometheus/common/promlog/flag (from $GOROOT)       
      /root/go/src/github.com/prometheus/common/promlog/flag (from $GOPATH)github.com/gosnmp/gosnmp (download)
# cd .; git clone -- https://github.com/gosnmp/gosnmp /root/go/src/github.com/gosnmp/gosnmpfatal: unable to access 'https://github.com/gosnmp/gosnmp/': Encountered end of filepackage github.com/gosnmp/gosnmp: exit status 128get "gopkg.in/yaml.v2": found meta tag 
get.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at //gopkg.in/yaml.v2?go-get=1gopkg.in/yaml.v2 (download)
get "gopkg.in/alecthomas/kingpin.v2": found meta tag get.metaImport{Prefix:"gopkg.in/alecthomas/kingpin.v2", VCS:"git", RepoRoot:"https://gopkg.in/alecthomas/kingpin.v2"} at //gopkg.in/alecthomas/kingpin.v2?go-get=1
gopkg.in/alecthomas/kingpin.v2 (download)
github.com/alecthomas/template (download)
github.com/alecthomas/units (download)
[root@K8s-Master go]#

可以通过go env查看默认下载路径

[root@K8s-Master go]# go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/root/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build510619153=/tmp/go-build -gno-record-gcc-switches"

GOPATH就是默认安装路径,默认安装在/root/go
进入路径

cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator

安装mibs库

主要的配置文件是generator.yml
默认的配置需要一些库支持
这些库可以make mibs下载,下载可能会报错
在这里插入图片描述
在这里插入图片描述
下载完成后修改运行库
export MIBDIRS=mibs

export MIBDIRS=mibs

如果不需要用他的mib库,可以直接导入自己需要的库
在路径下

[root@K8s-Master generator]# pwd
/root/go/src/github.com/prometheus/snmp_exporter/generator

使用方法

指定mib库
本地导的库(test_v8),光指定运行这个库会报oid节点不识别,需要同时指定一个snmp的公共库(/usr/share/snmp/mibs)
export MIBDIRS=test_v8:/usr/share/snmp/mibs
修改配置文件

[root@K8s-Master generator]# cat generator.yml
modules:
  test:
    walk:
      - 1.3.6.1.4.1.28556.2.1.1.1.1      
    version: 2
    auth:
      community: public

需要注意的是modules下面模块的名字,test是自定义,本地测试的是v2版本,团体字是public

v3的配置
参考
https://blog.csdn.net/weixin_39172380/article/details/106812717

生成snmp.yml文件
./generator generate

./generator generate
level=info ts=2021-09-22T08:43:30.843Z caller=net_snmp.go:144 msg="Loading MIBs" from=test_v8:/usr/share/snmp/mibs
level=info ts=2021-09-22T08:43:30.899Z caller=main.go:52 msg="Generating config for module" module=test
level=info ts=2021-09-22T08:43:30.905Z caller=main.go:67 msg="Generated metrics" module=test metrics=259
level=info ts=2021-09-22T08:43:30.923Z caller=main.go:92 msg="Config written" file=/root/go/src/github.com/prometheus/snmp_exporter/generator/snmp.yml

最后会生成snmp.yml,里面会有具体节点
在这里插入图片描述

测试运行

上面步骤只是生成一个运行的配置文件,运行还要再安装一个snmp-exporter
安装参考
参考链接
在这里插入图片描述
直接解压后,删除原来的snmp.yml文件
把上面生成的文件,拷贝到解压后的路径下

[root@K8s-Master snmp_exporter]# rm snmp.yml
rm: remove regular file ‘snmp.yml’? y
[root@K8s-Master snmp_exporter]#
[root@K8s-Master snmp_exporter]# ls
LICENSE  NOTICE  snmp_exporter  snmp.yml.backup
[root@K8s-Master snmp_exporter]#
[root@K8s-Master snmp_exporter]#
[root@K8s-Master snmp_exporter]# cp /root/go/src/github.com/prometheus/snmp_exporter/generator/snmp.yml snmp.yml
[root@K8s-Master snmp_exporter]#

运行

[root@K8s-Master snmp_exporter]# ./snmp_exporter
level=info ts=2021-09-22T07:52:21.901Z caller=main.go:149 msg="Starting snmp_exporter" version="(version=0.19.0, branch=HEAD, revision=9dcbc02f59648b21fcf632de1b62a30df70f4649)"
level=info ts=2021-09-22T07:52:21.901Z caller=main.go:150 build_context="(go=go1.14.7, user=root@387afaad41d6, date=20200831-12:07:03)"
level=info ts=2021-09-22T07:52:21.902Z caller=main.go:243 msg="Listening on address" address=:9116

在web上访问9116端口
在这里插入图片描述
module就是generator.yml的modules名字,目标就是需要监测节点的设备
/

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值