zabbix監(jiān)控aix db2數(shù)據(jù)庫(kù)

記一次工作中使用zabbix監(jiān)控aix db2數(shù)據(jù)庫(kù)的經(jīng)歷篙耗。
記憶要點(diǎn):

1.使用自定義perl腳本筋岛;

2.由于zabbix用戶權(quán)限的原因汪疮,無(wú)法調(diào)用db2用戶獲取數(shù)據(jù)庫(kù)的數(shù)據(jù)返咱,所以在zabbix配置文件中設(shè)置已root用戶啟動(dòng)

首先,創(chuàng)建腳本哥放,我這里的名稱為db2stat.pl歼指,腳本權(quán)限為755,確保有可執(zhí)行權(quán)限
復(fù)制代碼

#!/usr/bin/perl -wT

use File::Spec;

# Set this to path of db2 executable
$ENV{'PATH'} = "/opt/IBM/db2/V9.7/bin";  #db2可執(zhí)行文件的路徑
$dbuser = 'db2inst';              #定義db2數(shù)據(jù)庫(kù)的用戶 
# Directory where snapshots are cached.
my $SNAPSHOT_DIR = File::Spec->tmpdir();

# Get database name and timeout args
my $timeout = shift @ARGV;
my $dbname = shift @ARGV;

# Untaint
if ($dbname =~ /^([-\w.]+)$/) {
  $dbname = $1;
} else {
  die "Bad dbname argument";
}

if ($timeout =~ /^(\d+)$/) {
  $timeout = $1;
} else {
  die "Bad timeout value";
}

# Generate stat file name
my $statfile = "$SNAPSHOT_DIR/$dbname.txt";
my $tmpstatfile = "$SNAPSHOT_DIR/$dbname.txt.tmp";

# Regenerate stats if file too old
if (! -f $statfile or (time - (stat($statfile))[10]) > $timeout) {
  # first touch file to prevent another perform in next moment
  system("/usr/bin/touch $statfile");
  system("/usr/bin/su - $dbuser -c 'db2 update monitor switches using bufferpool ON lock ON sort ON statement ON table ON uow ON' >/dev/null 2>$1"); # 開(kāi)啟db2快照開(kāi)關(guān)
  #then generate tmp data
  system("/usr/bin/su - $dbuser -c 'db2 get snapshot for database on $dbname' >$tmpstatfile"); # 將獲取的快照數(shù)據(jù)保存到本地
  #finally swap files
  system("/usr/bin/cp -p $tmpstatfile $statfile");
}

# Generate regular expressions to match from args
while (@ARGV) {
  my $key = shift(@ARGV);
  my $value = shift(@ARGV);
  if (defined $value) {
    # Add preceding line match
    push(@RE, qr/\s*\Q$key\E\s*=\s*\Q$value\E\s*/);
  } else {
    # Add stat line match
    push(@RE, qr/\s*\Q$key\E\s*=\s*(.+)\s*/);
  }
}

# Try to find value with preceding line matches and stat line match
my $idx = 0;
open(DATA, "<$statfile");

while (<DATA>) {

  my $line = $_;
  if ($line =~ $RE[$idx]) {
    my $match = $1;
    # Return the match if all expressions have been matched
    $idx++;
    if ($idx == scalar @RE) {
      print "$match\n";
      exit 0;
    }
  }

  # Reset matches if empty line
  if ($line eq "") {
    $idx = 0;
  }
}

2.然后根據(jù)快照中的數(shù)據(jù)按照zabbix的格式定義鍵值婶芭,數(shù)據(jù)格式东臀,以下面為例

db2監(jiān)控樣式
復(fù)制代碼

# User parameters for DB2 snapshot statistics

# Simple statistics
UserParameter=db2stat.database_status[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Database status"
UserParameter=db2stat.apps_connected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Applications connected currently"
UserParameter=db2stat.apps_executing[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Appls. executing in db manager currently"
UserParameter=db2stat.locks_held[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Locks held currently"
UserParameter=db2stat.deadlocks_detected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Deadlocks detected"
UserParameter=db2stat.lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock escalations"
UserParameter=db2stat.excl_lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Exclusive lock escalations"
UserParameter=db2stat.agts_waiting_on_locks[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Agents currently waiting on locks"
UserParameter=db2stat.lock_timeouts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock Timeouts"
UserParameter=db2stat.log_space_used[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Log space used by the database (Bytes)"
UserParameter=db2stat.package_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache inserts"
UserParameter=db2stat.package_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache overflows"
UserParameter=db2stat.catalog_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache inserts"
UserParameter=db2stat.catalog_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache overflows"
UserParameter=db2stat.commit_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Commit statements attempted"
UserParameter=db2stat.rollback_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rollback statements attempted"
UserParameter=db2stat.dynamic_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Dynamic statements attempted"
UserParameter=db2stat.static_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Static statements attempted"
UserParameter=db2stat.failed_statement_operations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Failed statement operations"
UserParameter=db2stat.select_sql_statements_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Select SQL statements executed"
UserParameter=db2stat.xquery_statements_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Xquery statements executed"
UserParameter=db2stat.updates_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Update/Insert/Delete statements executed"
"db2stat.conf" 56 lines, 5523 characters
# User parameters for DB2 snapshot statistics

# Simple statistics
UserParameter=db2stat.database_status[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Database status"
UserParameter=db2stat.apps_connected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Applications connected currently"
UserParameter=db2stat.apps_executing[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Appls. executing in db manager currently"
UserParameter=db2stat.locks_held[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Locks held currently"
UserParameter=db2stat.deadlocks_detected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Deadlocks detected"
UserParameter=db2stat.lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock escalations"
UserParameter=db2stat.excl_lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Exclusive lock escalations"
UserParameter=db2stat.agts_waiting_on_locks[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Agents currently waiting on locks"
UserParameter=db2stat.lock_timeouts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock Timeouts"
UserParameter=db2stat.log_space_used[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Log space used by the database (Bytes)"
UserParameter=db2stat.package_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache inserts"
UserParameter=db2stat.package_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache overflows"
UserParameter=db2stat.catalog_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache inserts"
UserParameter=db2stat.catalog_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache overflows"
UserParameter=db2stat.commit_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Commit statements attempted"
UserParameter=db2stat.rollback_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rollback statements attempted"
UserParameter=db2stat.dynamic_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Dynamic statements attempted"
UserParameter=db2stat.static_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Static statements attempted"
UserParameter=db2stat.failed_statement_operations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Failed statement operations"
# User parameters for DB2 snapshot statistics

# Simple statistics
UserParameter=db2stat.database_status[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Database status"
UserParameter=db2stat.apps_connected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Applications connected currently"
UserParameter=db2stat.apps_executing[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Appls. executing in db manager currently"
UserParameter=db2stat.locks_held[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Locks held currently"
UserParameter=db2stat.deadlocks_detected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Deadlocks detected"
UserParameter=db2stat.lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock escalations"
UserParameter=db2stat.excl_lock_escalations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Exclusive lock escalations"
UserParameter=db2stat.agts_waiting_on_locks[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Agents currently waiting on locks"
UserParameter=db2stat.lock_timeouts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock Timeouts"
UserParameter=db2stat.log_space_used[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Log space used by the database (Bytes)"
UserParameter=db2stat.package_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache inserts"
UserParameter=db2stat.package_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Package cache overflows"
UserParameter=db2stat.catalog_cache_inserts[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache inserts"
UserParameter=db2stat.catalog_cache_overflows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Catalog cache overflows"
UserParameter=db2stat.commit_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Commit statements attempted"
UserParameter=db2stat.rollback_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rollback statements attempted"
UserParameter=db2stat.dynamic_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Dynamic statements attempted"
UserParameter=db2stat.static_statements_attempted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Static statements attempted"
UserParameter=db2stat.failed_statement_operations[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Failed statement operations"
UserParameter=db2stat.select_sql_statements_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Select SQL statements executed"
UserParameter=db2stat.xquery_statements_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Xquery statements executed"
UserParameter=db2stat.updates_executed[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Update/Insert/Delete statements executed"
UserParameter=db2stat.rows_deleted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rows deleted"
UserParameter=db2stat.rows_inserted[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rows inserted"
UserParameter=db2stat.rows_updated[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rows updated"
UserParameter=db2stat.rows_selected[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rows selected"
UserParameter=db2stat.rows_read[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Rows read"
UserParameter=db2stat.direct_reads[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Direct reads"
UserParameter=db2stat.direct_writes[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Direct writes"
UserParameter=db2stat.direct_reads_time[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Direct reads elapsed time (ms)"
UserParameter=db2stat.direct_writes_time[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Direct write elapsed time (ms)"
UserParameter=db2stat.log_space_available[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Log space available to the database (Bytes)"
UserParameter=db2stat.lock_wait[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Lock waits"
UserParameter=db2stat.total_sort[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Total sorts"
UserParameter=db2stat.sort_overfows[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Sort overflows"

# File System statistics
UserParameter=db2stat.storage_path_free_space[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Storage path free space (bytes)"
UserParameter=db2stat.file_system_used_space[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "File system used space (bytes)"
UserParameter=db2stat.file_system_total_space[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "File system total space (bytes)"

# Memory heap statistics
UserParameter=db2stat.package_cache_heap_size[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Node number" "$3" "Memory Pool Type" "Package Cache Heap" "Current size (bytes)"
UserParameter=db2stat.catalog_cache_heap_size[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Node number" "$3" "Memory Pool Type" "Catalog Cache Heap" "Current size (bytes)"

# Buffer Poll statistics
UserParameter=db2stat.buffer_pool_data_logical_reads[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Buffer pool data logical reads"
UserParameter=db2stat.buffer_pool_index_logical_reads[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Buffer pool index logical reads"
UserParameter=db2stat.buffer_pool_index_physical_reads[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Buffer pool index physical reads"
UserParameter=db2stat.buffer_pool_data_physical_reads[*],/usr/local/zabbix/scripts/db2stat.pl "$1" "$2" "Buffer pool data physical reads"

3.在zabbix web端添加監(jiān)控項(xiàng)着饥,由于工作環(huán)境加密的原因犀农,無(wú)法添加圖片,以下面鍵值為例

  db2stat.rows_updated[{$REFRESH_INTERVAL},{$DATABASE_NAME}]

在主機(jī)宏中添加對(duì)應(yīng)的數(shù)據(jù)庫(kù)的名字宰掉,指定數(shù)據(jù)的刷新間隔時(shí)間呵哨,

等待幾分鐘,查看有無(wú)監(jiān)控?cái)?shù)據(jù)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末轨奄,一起剝皮案震驚了整個(gè)濱河市孟害,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌挪拟,老刑警劉巖挨务,帶你破解...
    沈念sama閱讀 210,914評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異玉组,居然都是意外死亡谎柄,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,935評(píng)論 2 383
  • 文/潘曉璐 我一進(jìn)店門惯雳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)朝巫,“玉大人,你說(shuō)我怎么就攤上這事石景∨常” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 156,531評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵潮孽,是天一觀的道長(zhǎng)揪荣。 經(jīng)常有香客問(wèn)我,道長(zhǎng)往史,這世上最難降的妖魔是什么嗤瞎? 我笑而不...
    開(kāi)封第一講書人閱讀 56,309評(píng)論 1 282
  • 正文 為了忘掉前任,我火速辦了婚禮幅垮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘名眉。我一直安慰自己,他們只是感情好凰棉,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,381評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布损拢。 她就那樣靜靜地躺著,像睡著了一般撒犀。 火紅的嫁衣襯著肌膚如雪福压。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 49,730評(píng)論 1 289
  • 那天或舞,我揣著相機(jī)與錄音荆姆,去河邊找鬼。 笑死映凳,一個(gè)胖子當(dāng)著我的面吹牛胆筒,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播诈豌,決...
    沈念sama閱讀 38,882評(píng)論 3 404
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼仆救,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了矫渔?” 一聲冷哼從身側(cè)響起彤蔽,我...
    開(kāi)封第一講書人閱讀 37,643評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎庙洼,沒(méi)想到半個(gè)月后顿痪,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,095評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡油够,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,448評(píng)論 2 325
  • 正文 我和宋清朗相戀三年蚁袭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片叠聋。...
    茶點(diǎn)故事閱讀 38,566評(píng)論 1 339
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡撕阎,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出碌补,到底是詐尸還是另有隱情虏束,我是刑警寧澤,帶...
    沈念sama閱讀 34,253評(píng)論 4 328
  • 正文 年R本政府宣布厦章,位于F島的核電站镇匀,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏袜啃。R本人自食惡果不足惜汗侵,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,829評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧晰韵,春花似錦发乔、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 30,715評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至只恨,卻和暖如春译仗,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背官觅。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 31,945評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工纵菌, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人休涤。 一個(gè)月前我還...
    沈念sama閱讀 46,248評(píng)論 2 360
  • 正文 我出身青樓咱圆,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親滑绒。 傳聞我的和親對(duì)象是個(gè)殘疾皇子闷堡,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,440評(píng)論 2 348