Cacti queries the disk size occupied by the MySQL database and the returned php changes

Source: Internet
Author: User

Cacti queries the disk size occupied by the mysql database and returns php modifications. However, with the template configured in cacti, you can create tables in the device and generate data source entries, but there is no returned data and I don't know what the problem is. There is no solution for the moment.
I tried to use the script query and script_server methods. Because I still don't know, I don't know about cacti, or why I never returned a value.

Which of the following experts will give you some advice?

Paste the record here, because the template has been successfully created by using snmpwalk, and you cannot implement it by using a custom mib. I will share it later.

Xml file referenced in data query

<Interface>
<Name> get mysql databases </name>
<Script_path> | path_php_binary |-q | path_cacti |/scripts/flashapp_mysql_space.php </script_path>
<Arg_prepend> | host_hostname | </arg_prepend>
<Arg_index> index </arg_index>
<Arg_query> query </arg_query>
<Arg_get> get </arg_get>
<Arg_num_indexes> num_index </arg_num_indexes>
<Output_delimeter >:</output_delimeter>
<Index_order> hrDataBasesIndex </index_order>
<Index_order_type> numeric </index_order_type>
<Index_title_format> | chosen_order_field | </index_title_format>
<Fields>
<HrDataBasesIndex>
<Name> DataBasesIndex </name>
<Direction> input </direction>
<Query_name> index </query_name>
</HrDataBasesIndex>
<HrDataBasesDescr>
<Name> Description </name>
<Direction> input </direction>
<Query_name> desc </query_name>
</HrDataBasesDescr>
<HrDataBasesSize>
<Name> Total Size </name>
<Direction> output </direction>
<Query_name> space </query_name>
</HrDataBasesSize>

</Fields>
</Interface>

The corresponding php Query file has also been modified to adjust the parameters and output methods.
<? Php
/*
* Flashapp_mysql_space.php
*-------------------------------------------------
* Enable cacti to read mysql database size
* Originally by tongyuan at flashapp dot cn-2013/12/24
*
* Usage:
* Flashapp_mysql_space.php db_host <index | num_nidex>
* Flashapp_mysql_spqce.php db_host query index | desc
* Flashapp_mysql_spqce.php db_host get space database_name
*
* Mysql user must have permissions to do this.
* Give myuser/show databases/and/select/permissions.
*
* Examle:
* Grant select, process, super, show databases on *.*\
* To monitor @ '192. 168.11.0/255.255.255.0 'identified by 'monitor ';
*
*/
$ Debug = 0;
// If ($ _ SERVER ["argc"]! = 5 ){
// Echo "Error. Wrong parameter count or paramenter wrong. \ n ";
// Echo "Usage:". $ _ SERVER ["argv"] [0];
// Echo "<dbhost> <dbuser> <dbpasswd> <cmd> \ n ";
// Echo "cmd: index | num_index | get \ n ";
// Exit (1 );
//}
$ Host = $ _ SERVER ["argv"] [1];
// Default user and password is monitor
$ Username = "monitor ";
$ Password = "monitor ";
// Get all dabase name and count, please CT system database.
If ($ _ SERVER ["argc"]> = 3 ){

$ Cmd = $ _ SERVER ["argv"] [2];
If (@ mysql_connect ($ host, $ username, $ password )){
$ AlldataBase = @ mysql_query ("show databases ");
$ DataBaseNum = 0;
$ DataBase = array ();
While ($ row = @ mysql_fetch_array ($ alldataBase )){
If ($ row [0]! = "Information_schema"
& $ Row [0]! = "Mysql"
& $ Row [0]! = "Performance_schema"
& $ Row [0]! = "Test "){
$ DataBase [] = $ row [0];
$ DataBaseNum + = 1;
}
}

If ($ debug) {echo "all dataBase Number is:"; print_r ($ dataBaseNum); echo "\ n ";}
If ($ debug) {echo "all dataBase is:"; print_r ($ dataBase); echo "\ n ";}

// Output index
If ($ cmd = 'index') {foreach ($ dataBase as $ d) {echo $ d. "\ n" ;}exit (0 );}
// Output index_number
If ($ cmd = "num_index") {echo $ dataBaseNum. "\ n ";}

If ($ cmd = "query" | $ cmd = "get "){
$ Arg = $ _ SERVER ["argv"] [3];
// Get databses space
If ($ dataBaseNum = 0) {exit (0 );}
Foreach ($ dataBase as $ row ){
$ Resault = @ mysql_query ("select sum (DATA_LENGTH) + sum (INDEX_LENGTH) from information_schema.tables where table_schema = '". $ row ."'");
$ Space = @ mysql_fetch_row ($ resault) [0];
$ DataBaseSpace [] = $ space? $ Space: "0 ";
}
/* DEBUG */if ($ debug) {echo "All dataBase space is:"; print_r ($ dataBaseSpace); echo "\ n ";}
// Output database space
If ($ cmd = "query" & ($ arg = "index" | $ arg = "desc ")){
Foreach ($ dataBase as $ key => $ value ){
Echo $ value. ":". $ value. "\ n ";
}
Exit (0 );
}

If ($ cmd = "get" & $ arg = "space "){
$ Get_database = $ _ SERVER ["argv"] [4];
Foreach ($ dataBase as $ key => $ value ){
If ($ value = $ get_database ){
Echo $ dataBaseSpace [$ key];
}
}
}
}
} Else {
Die ("Can't connected to Server! \ N ");
}
}
?>

Download xml and PHP files:

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is in the/June/Cacti directory. query the disk size occupied by the MySQL database and the returned php modified

For the download method, see

Cacti details: click here
Cacti: click here

Install spine in Cacti in RHEL6.4 Environment

In RHEL6.4, the Cacti + Spine monitoring host is used to send mail alarms.

CentOS 5.5 complete installation of Cacti + Spine

Cacti construction document under CentOS 6

Detailed description of Cacti monitoring deployment under RHEL5.9

How to install Cacti in CentOS 6.3

Quick installation and configuration of Cacti in CentOS Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.