zzgzyyz 发表于 2015-9-7 12:07:58

Cacti磁盘使用百分比

  
  http://blog.chinaunix.net/uid-1886735-id-2810683.html
  http://bbs.chinaunix.net/thread-2090625-1-1.html
  cacti 监控磁盘按使用率报警接入方法 (2007-11-28 11:35)

分类: Monitor  


  vim include/config_arrays.php

$custom_data_source_types = array(
      "CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
      "ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
      "ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
      "CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
      "SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
      "CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
      "CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
      "CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit",
      "VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source");
vim plugins/thold/thold-functions.php
                            switch ($cdef['value']) {
                               case 'CURRENT_DATA_SOURCE':
                                  $cdef['value'] = $oldvalue; // get_current_value($rra, $ds, 0);
                                  break;
                               case 'VALUE_OF_HDD_TOTAL':
                                  $cdef['value'] = get_current_value($rra, 'hdd_total', 0);
                                  break;
在cacti界面添加 cdef模块
cdef=CURRENT_DATA_SOURCE,100,*,VALUE_OF_HDD_TOTAL,/

最后添加监控磁盘模块时候选择hdd_used 就OK拉!
=============================================
http://bbs.chinaunix.net/thread-1167896-1-1.html
本文本自王先进's blog,原文链接http://www.wangxianjin.cn/?action=show&id=83转载请注明出处。
cacti本身的模板只可以监控硬盘的使用大小,而不能监控使用非分率,所以我们要自定义cdef来监控硬盘使用率,并借助thold插件实现报警功能。网上找的资料都是在cacti.0.8.6版上实现的,而我用的是cacti.0.8.7版。因此,根据实际情况做如下改动:
在cacti目录下,vi global_arrays.php
搜索custom_data_source_types,修改这一段如下:
$custom_data_source_types = array(
"CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
"ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
"ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
"SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
"SIMILAR_DATA_SOURCES_DUPS" => "All Similar Data Sources (Include Duplicates)",
"CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
"CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
"CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
"CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit",
"VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source");
在cacti界面的Graph Management-cdefs新建cdef模块,名字自己起,添加字段如下:
Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Custom String: 100
Item #3 Operator: *
Item #4 Special Data Source: VALUE_OF_HDD_TOTAL
Item #5 Operator: /

也就是说
cdef=CURRENT_DATA_SOURCE,100,*,VALUE_OF_HDD_TOTAL,/

这样就可以在Threshold Templates里面添加监控硬盘的模块了,我添加的是Host MIB - Hard Drive Space ,最后在Threshold CDEF里面选择刚自定义的cdef,这样就可以正常监控硬盘使用率了。
=============================================
http://bbs.chinaunix.net/thread-2018771-1-1.html

=============================================
http://seo.wangxianjin.com/?p=107
=============================================
http://forums.cacti.net/viewtopic.php?t=20486
Hi,
i wanted to make a threshold based on % of used disk space (i saw few suggestions about this but none of them worked for me). However, i was able to do it after little modifications of cacti and threshold plugin
I'm polling disk total capacity and present usage using standard template Host MIB - Available Disk Space (screen01)
Step 1: I created new CDEF (screen02)
cdef=CURRENT_DATA_SOURCE,100,*,VALUE_OF_HDD_TOTAL,/
To get 'VALUE_OF_HDD_TOTAL' please add one line to file include/config_arrays.php

Code:
$custom_data_source_types = array(
      "CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
      "ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
      "ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
      "CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
      "SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
      "CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
      "CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
      "CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit",
      "VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ add this line
Step 2: After adding new CDEF, one more modification to file plugins/thold/thold-functions.php is needed:

Code:
                              switch ($cdef['value']) {
                               case 'CURRENT_DATA_SOURCE':
                                  $cdef['value'] = $oldvalue; // get_current_value($rra, $ds, 0);
                                  break;
                               case 'VALUE_OF_HDD_TOTAL':
                                  $cdef['value'] = get_current_value($rra, 'hdd_total', 0);
                                  break;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ add 3 last lines

Step 3: After that, i created threshold template for data field "hdd_used " (screen03)
Step 4: At the bottom, select CDEF you created in step 1 ("Threshold CDEF Apply this CDEF before returning the data"). Save and wait 2 polling cycles. After that you should see current value in %! (screen04)
Forgive me my poor english.

Attachments:http://forums.cacti.net/download/file.php?id=8727&sid=1660d7d7ff909911d276cd15443f9e4b
screen01.GIF [ 30.82 KiB | Viewed 16370 times ] http://forums.cacti.net/download/file.php?id=8728&sid=1660d7d7ff909911d276cd15443f9e4b
screen02.GIF [ 8.68 KiB | Viewed 16370 times ] http://forums.cacti.net/download/file.php?id=8729&sid=1660d7d7ff909911d276cd15443f9e4b
screen03.GIF [ 8.37 KiB | Viewed 16370 times ] http://forums.cacti.net/download/file.php?id=8730&sid=1660d7d7ff909911d276cd15443f9e4b
screen04.GIF [ 42.11 KiB | Viewed 16370 times ]




=============================================
=============================================  =============================================
  http://north-m.blogspot.com/2011/11/cacti_4861.html
修改cacti脚本, 增加磁盘使用百分比



最近在部署cacti用来monitor各数据库服务器, 想要设置一个磁盘空间报警, 当分区满90的时候发alert mail, 但是看了现在已经设置的monitor disk space的data source, 里面并没有类似于used_percent项, 又懒得再去找其他的template, 变自己修改已经有的脚本来实现.
首先找到对应的data query:
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://lh5.googleusercontent.com/oIViFfSroqe-6rjd2Dm1gM5M4ovemfxznFdPmMX_PM3YIcagD7iDfX01_KK1DHYMND8F0bham7nkiX8ezlhtsSsQqfz5OI_UNcTsmfckwT0MM1e2wys
我们知道了这个data query对应的xml文件, 于是找到这个xml文件, 编辑, 在field中增加一项:
<fields>
                <hrStorageIndex>
                        <name>Index</name>
                        <direction>input</direction>
                        <query_name>index</query_name>
                </hrStorageIndex>
......               
                <hrStorageUsedPercent>
                        <name>Used Percent</name>
                        <direction>output</direction>
                        <query_name>used_percent</query_name>
                </hrStorageUsedPercent>
从这个文件中我们也可以看出, 所用的php文件:
<script_path>|path_cacti|/scripts/ss_host_disk.php</script_path>
对应编辑这个php文件(不会php, 只能看着改了):
if ($cmd == "index") {
$return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
for ($i=0;($i<sizeof($return_arr));$i++) {
print $return_arr[$i] . "\n";
}
}elseif ($cmd == "num_indexes") {
$return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
print sizeof($return_arr);
}elseif ($cmd == "query") {
$arg = $arg1;
$arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
$arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER));
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!" . $arr[$i] . "\n";
}
}elseif ($cmd == "get") {
$arg = $arg1;
$index = $arg2;
if ($arg == "used_percent")
{
    $sau_used = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'"));
$snmp_used = cacti_snmp_get($hostname, $snmp_community, $oids["used"] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
if($snmp_data_used<0){
$used = (abs($snmp_used) + 2147483647) * $sau_used;
} else {
$used = $snmp_used * $sau_used;
}
$sau_total = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'"));
$snmp_total = cacti_snmp_get($hostname, $snmp_community, $oids["total"] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
if($snmp_total<0){
$total = (abs($snmp_total) + 2147483647) * $sau_total;
} else {
$total = $snmp_total * $sau_total;
}
return number_format($used * 100 / $total, 2);
}
if (($arg == "total") || ($arg == "used")) {
$sau = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'"));
$snmp_data = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
if($snmp_data<0){
return (abs($snmp_data) + 2147483647) * $sau;
} else {
return $snmp_data * $sau;
}
}else{
return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER);
}
}
接下来就可以到cacti中操作了:
在data template中增加一个:
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://lh4.googleusercontent.com/euGWZamdm7pDc5BC4xygHOiLJ5KF7bu0v7-A29n1Qlz2_AwfEXSt4HYehwq1YSho_Wbju27dbhOz-C0iMT31pNHchp6LKbOA86OPwyHfTe_5P9DCLlo
在data query中关联graph template以及 date template的地方:
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://lh4.googleusercontent.com/h5xMvQ1m41cqE71hjlx3iNGO2iTVvqSDYa7CUywYoEmtXBkDxL8qb2zWCPT9TGdkU6GuIwapq3iUsBhyt7v7YUJ3KsTYEO-rnRrAIM-fhrpQ5XPuHKw
然后修改graph template(其实应该没有必要这么加, 因为这个百分比相对于磁盘大小来说实在太小了, 在同一张图里面根本显示不出来, 只是我现在没研究透, 就全加了):
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://lh5.googleusercontent.com/eoWXg-Pzu-qJqUBruApKdNIJsnuunJ4NBINMpfEB7lroHgjfz3og7fP_qW5wW-JtOUfJKLY-Wb6Ys1uKHrng-iO5iUHPnLSPxYApFDI5RzfbPQdPWBY
然后我们就可以添加threshold了.

============================================================
http://hi.baidu.com/shulei1234/blog/item/19b5b63e8c17e6e054e723bf.html





Cacti监控磁盘
2010-05-07 0:06

1 cacti 模板 snmpdiskio-0.94
   wget http://forums.cacti.net/download.php?id=5233

2 修改/etc/snmp/snmpd.conf加入下面几行, 记得重启snmpd
   exec .1.3.6.1.4.1.2021.54 hdNum /usr/local/bin/snmpdiskio hdNum
   exec .1.3.6.1.4.1.2021.55 hdIndex /usr/local/bin/snmpdiskio hdIndex
   exec .1.3.6.1.4.1.2021.56 hdDescr /usr/local/bin/snmpdiskio hdDescr
   exec .1.3.6.1.4.1.2021.57 hdInBlocks /usr/local/bin/snmpdiskio hdInBlocks
   exec .1.3.6.1.4.1.2021.58 hdOutBlocks /usr/local/bin/snmpdiskio hdOutBlocks

3 将下载的snmpdisjio.tar.gz解开
   tar zxvf snmpdiskio-0.9.4.tar.gz

4 将 cp snmpdiskio /usr/local/bin/.
   cp partition.xml /cacti目录/resource/snmp_queries/.

5 进入cacti,导入模板
cacti-->console--->Import/Export--->Import Templates

"cacti_data_query_snmp_disk_statistics.xml
   cacti_graph_template_disk_io_bytessec.xml"

  6 进入cacti,建立一个新Graph
  From:http://blog.chinaunix.net/u/2914/showart_1981487.html
页: [1]
查看完整版本: Cacti磁盘使用百分比