LoginSignup
2
5

More than 5 years have passed since last update.

Zabbix監視テンプレート(NFS Client)

Last updated at Posted at 2018-04-03

Zabbix監視テンプレート(NFS Client)を作成しました。
Zabbix 3.0、NFS(クライアント側)で検証しています。

前提条件

  • /etc/logrotate.dの設定がrestartではなく、reloadを使用している事。
  • Zabbixエージェントの設定ファイルにパラメータ"Include=/etc/zabbix/zabbix_agentd.d/"を設定している事。

NFS Client

テンプレート

  • Template App NFS Client Service(テンプレートとのリンク: なし)

アプリケーション

  • NFS Client service

アイテム

  • なし

トリガー

  • なし

ディスカバリ

ディスカバリルール

# 名前 タイプ キー 更新間隔(秒) 例外の更新間隔 存在しなくなったリソースの保持期間(日) 説明 備考
1 Custom nfs mounted filesystems for discovery Zabbixエージェント custom.vfs.fs.nfs.discovery 3600 - 30 Discovery of custom file systems of different types as defined in global regular expression "Custom file systems for discovery".

フィルター

  • なし

アイテムのプロトタイプ

# 名前 トリガー キー データ型 単位 乗数の使用 更新間隔(秒) ヒストリ トレンド タイプ アプリケーション 内容 備考
1 NFS Client service {#FSNAME} is mounted 1 custom.nfs.mountpoint[{#FSNAME}] 数値 - - 30 90 365 Zabbixエージェント NFS Client service 特定ボリュームのマウント状況結果(0: OK, 1: NG)
  • ヒストリとは各収集値の保持期間
  • トレンドとは数値データタイプの1時間あたりの最低値、最高値、平均値および合計値の保持期間
  • Zabbixにリトライ回数、リトライ間隔、タイムアウト時間は存在しない

トリガーのプロトタイプ

# 深刻度 トリガー 条件式 種別 内容 備考
1 重度の障害 NFS Client service {#FSNAME} is unmounted on {HOST.NAME} custom.nfs.mountpoint[{#FSNAME}].min(#3)<>0 ファイルシステム 直近3回の特定ボリュームのマウント状況結果の戻り値(最小値)が0ではない場合

スクリプトの設置

/usr/local/bin/lld-nfs.py
#!/usr/bin/python
# coding: utf-8
# ------------------------------------------------------------------------------
# Script Name  : lld-nfs.py
# Tool Version : 1.0.0
# Argument     : -
# Option       : -h, --help     show this help message and exit
#              : -v, --version  show version and exit
#              : -t, --fstype   select virtual file system type
#              : -n, --fsname   select virtual file system name
# Usage        : $0 [Option]
# Return       : -
# -------------+-------------------------------------------+--------------------
# Date         | Changes                                   | Author
# -------------+-------------------------------------------+--------------------
# 2018/04/03   | New Creation                              | @bloodia
# ------------------------------------------------------------------------------
# --+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8

import json
import subprocess
import re
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
                       '-v', '--version',
                       action='version',
                       version='1.0.0',
                       help='show version and exit'
                   )
parser.add_argument(
                       '-t', '--fstype',
                       action='store',
                       help='select virtual file system type'
                   )
parser.add_argument(
                       '-n', '--fsname',
                       action='store',
                       help='select virtual file system name'
                   )
args = parser.parse_args()

if __name__ == '__main__':
    p1 = subprocess.Popen(['cat', '/proc/mounts'], stdout=subprocess.PIPE)
    p2 = subprocess.Popen(['awk', '{print $2,$3}'],stdin=p1.stdout,stdout=subprocess.PIPE)
    p3 = subprocess.Popen(['grep', '-v',  'sr|loop|ram'], stdin=p2.stdout, stdout=subprocess.PIPE)
    stdout, stderr = p3.communicate()
    data = list()
    for line in stdout.split('\n'):
        if line:
            fs = line.split(" ")
            fsname = fs[0]
            fstype = fs[1]
            if args.fstype:
                if fstype == args.fstype:
                    if args.fsname:
                        m = re.match(r"(%s)" % args.fsname, fsname)
                        if m:
                            data.append({"{#FSNAME}": fsname, "{#FSTYPE}": fstype})
                    else:
                        data.append({"{#FSNAME}": fsname, "{#FSTYPE}": fstype})
            else:
                data.append({"{#FSNAME}": fsname, "{#FSTYPE}": fstype})
    print(json.dumps({"data": data}, indent=4))

コンフィグの設置

/etc/zabbix/zabbix_agentd.d/userparameter_nfs.conf
# Custom Discovery Rules
UserParameter=custom.vfs.fs.nfs.discovery,/usr/local/bin/lld-nfs.py -t 'nfs'

# Custom Monitoring Items
UserParameter=custom.nfs.mountpoint[*],mountpoint -q $1 && echo 0 || echo 1

zabbix-agentの再起動(CentOS 5, 6)

[root@localhost ~]# /etc/init.d/zabbix-agent restart

zabbix-agentの再起動(CentOS 7)

[root@localhost ~]# systemctl restart zabbix-agent
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5