Data input field in graph title
เริ่มจาก download และติดตั้งตามตัวอย่างจาก Link นี้
http://forums.cacti.net/viewtopic.php?f=5&t=42802
1. Place 'addon_data_input_field.php' at 'cacti/lib/' directory
2. Modify get_graph_title() in 'cacti/lib/functions.php' as follows:
function get_graph_title($local_graph_id) { global $config; include_once($config["library_path"] . "/addon_data_input_field.php"); $graph = db_fetch_row("select graph_local.host_id, graph_local.snmp_query_id, graph_local.snmp_index, graph_templates_graph.title from (graph_templates_graph,graph_local) where graph_templates_graph.local_graph_id=graph_local.id and graph_local.id=$local_graph_id"); if ((strstr($graph["title"], "|")) && (!empty($graph["host_id"]))) { $graph["title"] = substitute_data_input_field($graph["title"], $graph["host_id"], $local_graph_id); return expand_title($graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"], $graph["title"]); }else{ return $graph["title"]; } }
Multiple Output
ตัวอย่างนี้จะเป็นการสร้างกราฟ Tablespace usage monitor
1.ให้สร้าง Data Input Method ใหม่ชื่อว่า Oracle Tablespaces Monitor ดังรูป
2.สร้างสคริปท์ ss_oracle_tbls.php ที่ path <path_cacti>/scripts
<? /* do NOT run this script through a web browser */ if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) { die("<br><strong>This script is only meant to run at the command line.</strong>"); } /* display No errors */ error_reporting(0); if (!isset($called_by_script_server)) { array_shift($_SERVER["argv"]); print call_user_func_array("ss_oracle_tbls", $_SERVER["argv"])."\n"; } function ss_oracle_tbls ($tnsnames, $sql_path, $username, $password,$tablespacename) { putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"); putenv("TNS_ADMIN=/u01/app/oracle/product/11.2.0/db_1/network/admin"); $ret = ''; $gdb_conn = ocilogon($username, $password,$tnsnames); $gdb_statement = OCIParse ($gdb_conn, "alter session set nls_date_format='MM/DD/YYYY HH24:MI:SS' "); OCIExecute ($gdb_statement); if (! OCIExecute($gdb_statement)){ return; } include $sql_path; $gdb_statement = OCIParse ($gdb_conn, $query); OCIExecute ($gdb_statement); while (OCIFetchInto ($gdb_statement, $row, OCI_RETURN_NULLS + OCI_ASSOC)) { reset($row); $tbls_current=$row['CURR']; $tbls_free=$row['FREE']; $tbls_total=$row['TOTAL']; $tbls_curr_percent=$row['CURRENT_PERCENT']; } OCIFreeStatement($gdb_statement); $ret .= 'current:'.$tbls_current.' current_percent:'.$tbls_curr_percent.' free:'.$tbls_free.' total:'.$tbls_total.' '; return trim($ret); } ?>
3.สร้างสคริปท์ tablespace_usage.php ที่ path <path_cacti>/sql
<? $query = " SELECT DISTINCT a.tablespace_name, (SUM (a.bytes) / 1024 / 1024 - ROUND (c.free / 1024 / 1024)) curr, ( SUM (DECODE (b.maxextend, NULL, a.bytes / 1024 / 1024, b.maxextend * (SELECT VALUE FROM v\$parameter WHERE name = 'db_block_size') / 1024 / 1024)) - (SUM (a.bytes) / 1024 / 1024 - ROUND (c.Free / 1024 / 1024))) free, SUM (DECODE (b.maxextend, NULL, a.bytes / 1024 / 1024, b.maxextend * (SELECT VALUE FROM v\$parameter WHERE name = 'db_block_size') / 1024 / 1024)) total, ROUND ( 100 * (SUM (a.bytes) / 1024 / 1024 - ROUND (c.free / 1024 / 1024)) / (SUM (DECODE (b.maxextend, NULL, a.bytes / 1024 / 1024, b.maxextend * (SELECT VALUE FROM v\$parameter WHERE name = 'db_block_size') / 1024 / 1024)))) current_percent FROM dba_data_files a, sys.filext$ b, ( SELECT d.tablespace_name, SUM (NVL (c.bytes, 0)) free FROM dba_tablespaces d, dba_free_space c WHERE d.tablespace_name = c.tablespace_name(+) GROUP BY d.tablespace_name) c WHERE a.file_id = b.file#(+) AND a.tablespace_name = c.tablespace_name AND a.tablespace_name = UPPER ('$tablespacename') GROUP BY a.tablespace_name, c.free / 1024 "; ?>
4.สร้าง Data templates และ Graph templates ดังนี้
กดไปตาม Link จนถึงหน้า download จากนั้นนำไป import ยังระบบ Cacti ของท่าน
tablespace_data_template.xml
tablespace_graph_template.xml
เมื่อเปิดดู Data Templates จะเห็นว่ามีการสร้าง Internal Data Source Name มาเท่ากับ output จากสคริปท์ PHP
5. เปิดดุ Graph Templates จะเห็นว่าที่ช่อง title จะมีการใส่ parameter เข้าไปเพื่อให้แสดงว่ากราฟนี้มีข้อมูลมาจาก input อย่างไรบ้าง
|host_description|/|input_tnsnames| - Tablespace - |input_tablespace_name|
6. เปิดเมนู Management -> Data Sources แล้ว Click ที่ Add
ใส่ข้อมูล Data Source Fields -> Name ดังนี้
|host_description| - Tablespace - |input_tnsnames| : |input_tablespace_name|
7.กำหนด SQL script path ให้ตรงกับไฟล์ Tablespace_usage.php
8.เปิดเมนุ Management -> Graph Management แล้ว Click ที่ Add
เมื่อกำหนดค่าตามที่ต้องการแล้วให้กดที่ Save
หลักจากนั้นเมื่อเปิดดูรูปจะสังเกตูเห็นว่ามีข้อมูลแสดงที่ Title ออกมาอย่างครบถ้วนและข้อมูลของกราฟสามารถแสดงรายละเีอียดจากหลาย output ได้แล้ว
หมายเหตุ
จากตัวอย่างจะเป็นการ Monitor Tablespace usage ที่ไม่ได้ใช้ระบบ Auto-Extend เราจึงสังเกตุแค่ค่า Max หรือ Total space ว่ามีค่า used และ free เท่าใหร่ โดยไม่ได้สนใจว่าพร้อมสำหรับขยายอย่างไร การทำแบบนี้เป็นที่นิยมในระบบส่วนใหญ่เพราะจะได้ไม่ต้องกังวลกับ OS Disk หรือ Storage จะเต็มโดยที่เราไม่รู้ตัวหรือเปล่าเพราะกำหนดตายตัวไปแล้วว่าให้ Database ใช้ไปเท่าใหร่ แล้วค่อยมาดูว่าแต่ะละ Tablespace จะเต็ํมหรือยังจะได้ทำการ Add new datafiles
ไม่มีความคิดเห็น:
แสดงความคิดเห็น