Grafana & PrometheusでIX2207 SNMP監視
参考
https://izuminmin.com/network/snmp-exporter-grafana/
IXシリーズMIB
https://jpn.nec.com/univerge/ix/Manual/index.html#mib
https://changineer.info/network/nec_ix/nec_ix_snmp_mib.html
Grafanaのインストはここを参考に
https://grafana.com/docs/grafana/latest/setup-grafana/installation/
インストコマンドたち
code:install prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.46.0/prometheus-2.46.0.linux-amd64.tar.gz
sha256sum prometheus-2.46.0.linux-amd64.tar.gz
sudo tar xvfz prometheus-2.46.0.linux-amd64.tar.gz -C /opt/
sudo useradd -m prometheus
cd /opt/prometheus-2.46.0.linux-amd64/
sudo vim /etc/systemd/system/prometheus.service
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
code:/etc/systemd/system/prometheus.service
Unit
Description=Prometheus Server
Service
Type=simple
Restart=always
User=prometheus
ExecStart=/opt/prometheus-2.46.0.linux-amd64/prometheus --config.file=/opt/prometheus-2.46.0inux-amd64/prometheus.yml --storage.tsdb.path=/opt/prometheus-2.46.linux-amd64/data
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
Install
WantedBy=multi-user.target
code:install snmp
yay -Sy net-snmp
snmpwalk -v 2c -c ix2207 192.168.2.1
sudo mkdir -p /etc/snmp/ex-mib
sudo vim /etc/snmp/snmp.conf
code:/etc/snmp/snmp.conf
MIBDIRS /usr/share/snmp/mibs:/etc/snmp/ex-mib
mibs all
NEC IXシリーズのMIBはここ
https://jpn.nec.com/univerge/ix/Manual/index.html#mib
ISDN-MIBと依存関係があるのでそれも持ってくる
https://www.circitor.fr/Mibs/Html/I/ISDN-MIB.php
code:install mib
sudo wget https://jpn.nec.com/univerge/ix/Manual/MIB/PICO-SMI-MIB.txt
sudo wget https://jpn.nec.com/univerge/ix/Manual/MIB/PICO-SMI-ID-MIB.txt
sudo wget https://jpn.nec.com/univerge/ix/Manual/MIB/PICO-IPSEC-FLOW-MONITOR-MIB.txt
sudo wget https://www.circitor.fr/Mibs/Mib/I/ISDN-MIB.mib
この辺りがうまくいかなかったのでMacbookでgeneratorを使用した
generateしたものをmacからbmaxにrsyncで送ってやる
code:install snmp exporter
mkdir ~/.snmp
ln -s /etc/snmp/ex-mib /home/matac/.snmp/mibs
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
vim ~/.zshrc
go install github.com/prometheus/snmp_exporter/generator@latest
code:.zshrc
# Golang
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
code:error
# github.com/prometheus/snmp_exporter/generator
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:33:28: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:57:30: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:58:28: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:113:22: undefined: initSNMP
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:125:11: undefined: getMIBTree
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/tree.go:39:18: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/tree.go:47:25: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/tree.go:203:39: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/tree.go:227:38: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/tree.go:254:52: undefined: Node
go/pkg/mod/github.com/prometheus/snmp_exporter@v0.23.0/generator/main.go:125:11: too many errors
code:install grafana
yay -Sy grafana
sudo systemctl daemon-reload
sudo systemctl enable --now grafana
設定ファイルたち
code:/opt/prometheus-2.46.0.linux-amd64/prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # 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: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: "localhost:9090"
- job_name: "snmp"
static_configs:
- targets:
- '192.168.2.1'
metrics_path: /snmp
params:
module:
- ix2207
auth:
- ix2207
relabel_configs:
- source_labels: __address__
target_label: __param_target
- source_labels: __param_target
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116
これはGeneratorで生成された設定ファイル
code:/opt/snmp_exporter-0.23.0.linux-amd64/snmp.yml
# WARNING: This file was auto-generated using snmp_exporter generator, manual changes will be lost.
auths:
ix2207:
community: ix2207
security_level: noAuthNoPriv
auth_protocol: MD5
priv_protocol: DES
version: 2
modules:
ix2207:
get:
- 1.3.6.1.4.1.119.2.3.84.2.1.1.0
metrics:
- name: picoCelsius
oid: 1.3.6.1.4.1.119.2.3.84.2.1.1
type: gauge
help: Indicates the temperature of the equipment inside, in degree (Celsius).
- 1.3.6.1.4.1.119.2.3.84.2.1.1
retries: 3
timeout: 3s
code:/home/matac/go/bin/generator.yml
auths:
ix2207:
version: 2
community: ix2207
modules:
ix2207:
walk:
- picoCelsius
retries: 3
timeout: 3s
lookups:
- source_indexes: picoIndex
lookup: picoName
- source_indexes: ifIndex
lookup: ifAlias
- source_indexes: ifIndex
lookup: ifDescr
- source_indexes: ifIndex
lookup: ifName
lookupsでインデックスから値を特定している
例えばGrafanaでインターフェース名を出力したい時に使える
上記設定のwalkにMIBのsub tree nameを追記する
./generator generateする
https://gyazo.com/f06856175ddf1521370ff502d88fab7b
とりあえず温度だけ表示できたので色々追加していく。
こんなもんかな
https://gyazo.com/7f917fa097a164c206e0c72200ec430f
あんまりスイッチの監視項目がない?
MIB ifInOctets, ifOutOctetsなどはトータルの値なのでインターバルを設定する必要がある。
さらに一つのパネルで複数のメトリクスを表示する時はLegendを設定してあげると良い
ここの値はDisplay Nameでも変更できるがメトリクスごとには変更できない
https://gyazo.com/00696f97ac0528685f6f0a49f4796732