SNMP Exporterをお試し。
環境は、SNMP ExporterもPrometheusもCentOS 7上で直接バイナリを実行している。(非K8s環境)
SNMPエージェントについてはDockerで動作するArista EOSを使用。
Prometheusバージョンは2.23を使用。
実行用バイナリの入手
2020.12.29時点で0.19.0(2020.08.31リリース)
CentOS上で動かすので「snmp_exporter-0.19.0.linux-amd64.tar.gz」をダウンロードする。
$ curl -LO https://github.com/prometheus/snmp_exporter/releases/download/v0.19.0/snmp_export er-0.19.0.linux-amd64.tar.gz
Blackbox Exporterと同じように、実行バイナリと設定YAMLが含まれる。
[zaki@cloud-dev prometheus]$ tar xf snmp_exporter-0.19.0.linux-amd64.tar.gz [zaki@cloud-dev prometheus]$ cd snmp_exporter-0.19.0.linux-amd64/ [zaki@cloud-dev snmp_exporter-0.19.0.linux-amd64]$ [zaki@cloud-dev snmp_exporter-0.19.0.linux-amd64]$ ls -lh 合計 15M -rw-r--r--. 1 zaki zaki 12K 8月 31 21:15 LICENSE -rw-r--r--. 1 zaki zaki 63 8月 31 21:15 NOTICE -rw-r--r--. 1 zaki zaki 616K 8月 31 21:15 snmp.yml -rwxr-xr-x. 1 zaki zaki 14M 8月 31 21:07 snmp_exporter
なお、設定に使用するsnmp.yml
は人手で作成せずにgeneratorを使って生成するとのこと。(未検証)
設定YAML、0.19.0だと616KBもあるけど、masterブランチのファイルは現時点で1.16MBもある。。
SNMP Exporterの実行
snmp_exporter
を引数無しで実行すれば、実行時のカレントディレクトリにあるsnmp.yml
を設定ファイルとして自動で読み込んで起動し、9116/TCPでListenする。
[zaki@cloud-dev snmp_exporter-0.19.0.linux-amd64]$ ls LICENSE NOTICE snmp.yml snmp_exporter [zaki@cloud-dev snmp_exporter-0.19.0.linux-amd64]$ ./snmp_exporter level=info ts=2020-12-29T03:09:58.262Z caller=main.go:149 msg="Starting snmp_exporter" version="(version=0.19.0, branch=HEAD, revision=9dcbc02f59648b21fcf632de1b62a30df70f4649)" level=info ts=2020-12-29T03:09:58.262Z caller=main.go:150 build_context="(go=go1.14.7, user=root@387afaad41d6, date=20200831-12:07:03)" level=info ts=2020-12-29T03:09:58.305Z caller=main.go:243 msg="Listening on address" address=:9116
起動オプションは以下の通り。
--config.file=
で設定ファイル名を指定も可能。
$ ./snmp_exporter --help usage: snmp_exporter [<flags>] Flags: -h, --help Show context-sensitive help (also try --help-long and --help-man). --snmp.wrap-large-counters Wrap 64-bit counters to avoid floating point rounding. --config.file="snmp.yml" Path to configuration file. --web.listen-address=":9116" Address to listen on for web interface and telemetry. --dry-run Only verify configuration is valid and exit. --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error] --log.format=logfmt Output format of log messages. One of: [logfmt, json]
snmp.ymlが無いとエラー
$ ls -a . .. .snmp.yml LICENSE NOTICE snmp_exporter $ ./snmp_exporter level=info ts=2020-12-29T02:47:13.169Z caller=main.go:149 msg="Starting snmp_exporter" version="(version=0.19.0, branch=HEAD, revision=9dcbc02f59648b21fcf632de1b62a30df70f4649)" level=info ts=2020-12-29T02:47:13.169Z caller=main.go:150 build_context="(go=go1.14.7, user=root@387afaad41d6, date=20200831-12:07:03)" level=error ts=2020-12-29T02:47:13.169Z caller=main.go:156 msg="Error parsing config file" err="open snmp.yml: no such file or directory"
webアクセス
SNMP Exporterが実行中の状態で9116/TCPへブラウザでアクセスするとこんな感じ。
ここで、「Target」に前日作ったSNMPエージェントを有効にしたArista EOSのコンテナのアドレスを入力してみると、以下の通り。
(ウェルノウンポートでないので、ポート番号まで記載する。192.168.0.18:45161
という感じ)
# HELP ifNumber The number of network interfaces (regardless of their current state) present on this system. - 1.3.6.1.2.1.2.1 # TYPE ifNumber gauge ifNumber 0 # HELP snmp_scrape_duration_seconds Total SNMP time scrape took (walk and processing). # TYPE snmp_scrape_duration_seconds gauge snmp_scrape_duration_seconds 0.007350904 # HELP snmp_scrape_pdus_returned PDUs returned from walk. # TYPE snmp_scrape_pdus_returned gauge snmp_scrape_pdus_returned 2 # HELP snmp_scrape_walk_duration_seconds Time SNMP walk/bulkwalk took. # TYPE snmp_scrape_walk_duration_seconds gauge snmp_scrape_walk_duration_seconds 0.007298412 # HELP sysUpTime 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 # TYPE sysUpTime gauge sysUpTime 5.545402e+06
sysUpTime
の値である「5.545402e+06」についてはintにすると「5545402」。
これは参照時のArista EOSコンテナのUp Timeが15 hour ago(docker ps
で確認)なので値はだいたい一致している。
リロードすれば値は増加する。
arista_sw
デフォルトのif_mib
でなく、対象機器に合わせてarista_sw
を指定してみると以下の通り。
スクロールバーからも分かる通り、様々な値を参照できている。
※ この辺かなりわかってなくて、snmp.yml
の定義済み設定からそれっぽい項目をピックアップした。Ciscoであればcisco_wlc
というものがある。
[zaki@cloud-dev snmp_exporter-0.19.0.linux-amd64]$ grep -n ^[a-z] snmp.yml 2:apcups: 2324:arista_sw: 3560:cisco_wlc: 4660:ddwrt: 6084:if_mib: 7335:infrapower_pdu: 7419:keepalived: 8904:nec_ix: 11173:paloalto_fw: 12738:printer_mib: 12948:raritan: 13083:servertech_sentry3: 13616:synology: 16206:ubiquiti_airfiber: 18054:ubiquiti_airmax: 19361:ubiquiti_unifi:
Prometheusから参照
設定サンプルはSNMP Exporterのページに載っているが、今回はArista EOS用の設定を指定するためparams.module
に[arista_sw]
を記載。
replacement
はPrometheusから見たSNMP Exporterのアドレスで、targets
にはSNMP Exporterから見たSNMPエージェント(今回はArista EOSのNW機器)のアドレスを指定する。
以下の内容をscrape_configs
に追加。
- job_name: 'snmp' static_configs: - targets: - 192.168.0.18:45161 # SNMP device. metrics_path: /snmp params: module: [arista_sw] relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.0.18:9116 # The SNMP exporter's real hostname:port.
Targetsはこの通り、SNMPの設定が追加される。
NW機器なので転送量とか見れたらいいんだけどちょっとよくわからなかったので、ぱっと見で値が入ってそうなhrStorageUsed
を指定。
KubernetesでExporterを動かす場合
SNMP ExporterのHelmチャートがあるので、これを使うのが楽だと思う。
$ helm install snmp prometheus-community/prometheus-snmp-exporter -n monitoring
Exporterしか動かしてないけどこの通り。
[zaki@cloud-dev ~]$ helm ls -n monitoring NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION blackbox monitoring 1 2020-12-25 14:21:31.954695693 +0900 JSTdeployed prometheus-blackbox-exporter-4.10.1 0.18.0 snmp monitoring 1 2020-12-25 17:25:15.075107984 +0900 JSTdeployed prometheus-snmp-exporter-0.1.1 0.19.0 [zaki@cloud-dev ~]$ kubectl get pod -n monitoring NAME READY STATUS RESTARTS AGE blackbox-prometheus-blackbox-exporter-6fcb969596-75ffg 1/1 Running 0 4d snmp-prometheus-snmp-exporter-5b688cff9-2tfg4 1/1 Running 1 3d21h
なお、PrometheusからSNMP Exporterへの疎通と、SNMP ExporterからNWデバイスへの疎通があれば良いので、PrometheusをKubernetes上で動作させていたとしても、SNMP Exporterも同じKubernetesで動作させなければいけないというわけではない。
SNMP Exporterで使用するsnmp.yml
にどんなSNMPの値を扱うかを定義し、Prometheusの設定でどのホストにあるSNMPエージェントの値を参照するか、という構成のようだ。