Grafana & PrometheusでIX2207 SNMP監視
参考
IXシリーズMIB
Grafanaのインストはここを参考に
インストコマンドたち
code:install prometheus
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
Description=Prometheus Server
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
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はここ
ISDN-MIBと依存関係があるのでそれも持ってくる
code:install mib
この辺りがうまくいかなかったのでMacbookでgeneratorを使用した
generateしたものをmacからbmaxにrsyncで送ってやる
code:install snmp exporter
mkdir ~/.snmp
ln -s /etc/snmp/ex-mib /home/matac/.snmp/mibs
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:
- job_name: "snmp"
static_configs:
- targets:
- '192.168.2.1'
metrics_path: /snmp
params:
module:
- ix2207
auth:
- ix2207
relabel_configs:
target_label: __param_target
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116
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:
lookup: picoName
lookup: ifAlias
lookup: ifDescr
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