阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Cacti 中查询MySQL数据库占用磁盘大小并返回的php修改了

137次阅读
没有评论

共计 4750 个字符,预计需要花费 12 分钟才能阅读完成。

cacti 中查询 MySQL 数据库占用磁盘大小并返回的 php 修改了,但在 cacti 中配置了模板,可以在 device 中创建表格并且可以生成 data source 的条目,但始终没有返回数据 不知道是什么问题,暂时没有办法解决。
尝试过用 script query 和 script_server 的方式,由于还是不了解也不知道是对 cacti 的了解不够还是什么原因 始终没有返回值

哪位大神给指点下

贴这里记录下,因为之前通过 snmpwalk 的方式进行制作模板已经成功,没办法用自定义 mib 的方式进行实现吧,后面再分享

data query 中引用的 xml 文件

<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>

对应的 php 查询文件也做了修改调整了 参数 和输出方法
<?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\n”;
//        echo “cmd : index|num_index|get \n\n\n”;
//        exit(1);
// }
$host      = $_SERVER[“argv”][1];
//default user and password is monitor
$username  = “monitor”;
$password  = “monitor”;
//get all dabase name and count,expect 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”);
    }
}
?>

相关文件 xml 和 php 文件下载

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是 www.linuxidc.com

具体下载目录在 /2014 年资料 / 1 月 / 2 日 /Cacti 中查询 MySQL 数据库占用磁盘大小并返回的 php 修改了

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

Cacti 的详细介绍 :请点这里
Cacti 的下载地址 :请点这里

相关阅读

RHEL6.4 环境 Cacti 中 spine 安装 http://www.linuxidc.com/Linux/2013-11/92797.htm

RHEL6.4 中使用 Cacti+Spine 监控主机实现发送邮件报警 http://www.linuxidc.com/Linux/2013-11/92795.htm

CentOS 5.5 完整安装 Cacti+Spine http://www.linuxidc.com/Linux/2011-12/49701.htm

CentOS 6 下 Cacti 搭建文档 http://www.linuxidc.com/Linux/2013-06/86595.htm

RHEL5.9 下 Cacti 监控部署详解 http://www.linuxidc.com/Linux/2013-06/85427.htm

CentOS 6.3 下 Cacti 安装���解 http://www.linuxidc.com/Linux/2013-05/84279.htm

CentOS Linux 下快速安装配置 Cacti 中文版 http://www.linuxidc.com/Linux/2013-03/81627.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计4750字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中