經常遇到一些需要監控的指標,從零開始做比較麻煩,借用cacti工具可以快速實現這類需求。
1、準備監控數據(可以5分鐘刷新一次)格式如下
a:100 b:100 c:100 d:100 e:100
2、準備perl腳本
get_content.pl
#!/usr/bin/perl
if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}
if ( exists $ARGV[0]) {
if ($ret)
{
print "no ($ret)\n";
exit 1;
}
my $ua = LWP::UserAgent->new(timeout => 5);
my $response = $ua->request(HTTP::Request->new('GET',$ARGV[0]));
my @content = split (/\n/, $response->content);
print <span style="font-family: Arial, Helvetica, sans-serif;">$content[0]</span>;
print "\n";
}
3、導入模板文件
<cacti>
<hash_000025c35dc317aadf8219dabae7c29fd98694>
<name>Url Status</name>
<graph>
<t_title></t_title>
<title>|host_description| - Nginx Clients Stat</title>
<t_image_format_id></t_image_format_id>
<image_format_id>1</image_format_id>
<t_height></t_height>
<height>120</height>
<t_width></t_width>
<width>500</width>
<t_slope_mode></t_slope_mode>
<slope_mode>on</slope_mode>
<t_auto_scale></t_auto_scale>
<auto_scale>on</auto_scale>
<t_auto_scale_opts></t_auto_scale_opts>
<auto_scale_opts>2</auto_scale_opts>
<t_auto_scale_log></t_auto_scale_log>
<auto_scale_log></auto_scale_log>
<t_scale_log_units></t_scale_log_units>
<scale_log_units></scale_log_units>
<t_auto_scale_rigid></t_auto_scale_rigid>
<auto_scale_rigid></auto_scale_rigid>
<t_auto_padding></t_auto_padding>
<auto_padding>on</auto_padding>
<t_export></t_export>
<export>on</export>
<t_upper_limit></t_upper_limit>
<upper_limit>100</upper_limit>
<t_lower_limit></t_lower_limit>
<lower_limit>0</lower_limit>
<t_base_value></t_base_value>
<base_value>1000</base_value>
<t_unit_value></t_unit_value>
<unit_value></unit_value>
<t_unit_exponent_value></t_unit_exponent_value>
<unit_exponent_value></unit_exponent_value>
<t_vertical_label></t_vertical_label>
<vertical_label></vertical_label>
</graph>
<items>
<hash_10002508f6db75c900100b68f5e707ea7651bf>
<task_item_id>hash_0800256aa36fa51315e2d6d15b708307f2c53c</task_item_id>
<color_id>005D57</color_id>
<alpha>FF</alpha>
<graph_type_id>4</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>A</text_format>
<hard_return></hard_return>
<sequence>1</sequence>
</hash_10002508f6db75c900100b68f5e707ea7651bf>
<hash_100025d0e3bbf50c29a3069342cd408826b753>
<task_item_id>hash_0800256aa36fa51315e2d6d15b708307f2c53c</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>4</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Current:</text_format>
<hard_return></hard_return>
<sequence>2</sequence>
</hash_100025d0e3bbf50c29a3069342cd408826b753>
<hash_100025161e34504642f56fef3225d5b506b8ae>
<task_item_id>hash_0800256aa36fa51315e2d6d15b708307f2c53c</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Average:</text_format>
<hard_return></hard_return>
<sequence>3</sequence>
</hash_100025161e34504642f56fef3225d5b506b8ae>
<hash_100025da81390a6e5ba8a4f31aec4875cafb02>
<task_item_id>hash_0800256aa36fa51315e2d6d15b708307f2c53c</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>3</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Max:</text_format>
<hard_return>on</hard_return>
<sequence>4</sequence>
</hash_100025da81390a6e5ba8a4f31aec4875cafb02>
<hash_10002587617c277de94698bdc3d784e2257595>
<task_item_id>hash_080025729d4b3fa3813f2974ce01b29ca6850e</task_item_id>
<color_id>4444FF</color_id>
<alpha>FF</alpha>
<graph_type_id>4</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>B</text_format>
<hard_return></hard_return>
<sequence>5</sequence>
</hash_10002587617c277de94698bdc3d784e2257595>
<hash_100025e88db2dfe01d9a68242f3b00af85da06>
<task_item_id>hash_080025729d4b3fa3813f2974ce01b29ca6850e</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>4</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Current:</text_format>
<hard_return></hard_return>
<sequence>6</sequence>
</hash_100025e88db2dfe01d9a68242f3b00af85da06>
<hash_10002591cbdb8c81005e78564efaa2c7045408>
<task_item_id>hash_080025729d4b3fa3813f2974ce01b29ca6850e</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Average:</text_format>
<hard_return></hard_return>
<sequence>7</sequence>
</hash_10002591cbdb8c81005e78564efaa2c7045408>
<hash_100025659f92f53f26f1dbb9ae3238e9fca3e8>
<task_item_id>hash_080025729d4b3fa3813f2974ce01b29ca6850e</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>3</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Max:</text_format>
<hard_return>on</hard_return>
<sequence>8</sequence>
</hash_100025659f92f53f26f1dbb9ae3238e9fca3e8>
<hash_100025ad886e1f4f835761fddf7979e06cc06b>
<task_item_id>hash_08002550e895b90a6d17b7a212997b7cb1afba</task_item_id>
<color_id>F24AC8</color_id>
<alpha>FF</alpha>
<graph_type_id>4</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>C</text_format>
<hard_return></hard_return>
<sequence>9</sequence>
</hash_100025ad886e1f4f835761fddf7979e06cc06b>
<hash_1000252a650f2015d0cd2075a13090e99c2e88>
<task_item_id>hash_08002550e895b90a6d17b7a212997b7cb1afba</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>4</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Current:</text_format>
<hard_return></hard_return>
<sequence>10</sequence>
</hash_1000252a650f2015d0cd2075a13090e99c2e88>
<hash_100025d960bb2d2aa8e2013f1a6e6ec005f348>
<task_item_id>hash_08002550e895b90a6d17b7a212997b7cb1afba</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Average:</text_format>
<hard_return></hard_return>
<sequence>11</sequence>
</hash_100025d960bb2d2aa8e2013f1a6e6ec005f348>
<hash_10002576e9b62101708aee0815b2e01508d41a>
<task_item_id>hash_08002550e895b90a6d17b7a212997b7cb1afba</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>3</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Max:</text_format>
<hard_return>on</hard_return>
<sequence>12</sequence>
</hash_10002576e9b62101708aee0815b2e01508d41a>
<hash_1000251210e4ae921055593929a9f41703cf25>
<task_item_id>hash_08002575698c6bd226db0b7cd67089e651f382</task_item_id>
<color_id>00CF00</color_id>
<alpha>FF</alpha>
<graph_type_id>4</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>D</text_format>
<hard_return></hard_return>
<sequence>13</sequence>
</hash_1000251210e4ae921055593929a9f41703cf25>
<hash_10002544359da88929bda518ca1c8809708993>
<task_item_id>hash_08002575698c6bd226db0b7cd67089e651f382</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>4</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Current:</text_format>
<hard_return></hard_return>
<sequence>14</sequence>
</hash_10002544359da88929bda518ca1c8809708993>
<hash_100025ac404e13020ab6f400dca560f37922d1>
<task_item_id>hash_08002575698c6bd226db0b7cd67089e651f382</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>1</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Average:</text_format>
<hard_return></hard_return>
<sequence>15</sequence>
</hash_100025ac404e13020ab6f400dca560f37922d1>
<hash_10002515ec3c66d07404a13ad6e3c8178cd8f0>
<task_item_id>hash_08002575698c6bd226db0b7cd67089e651f382</task_item_id>
<color_id>0</color_id>
<alpha>FF</alpha>
<graph_type_id>9</graph_type_id>
<consolidation_function_id>3</consolidation_function_id>
<cdef_id>0</cdef_id>
<value></value>
<gprint_id>hash_060025e9c43831e54eca8069317a2ce8c6f751</gprint_id>
<text_format>Max:</text_format>
<hard_return></hard_return>
<sequence>16</sequence>
</hash_10002515ec3c66d07404a13ad6e3c8178cd8f0>
</items>
<inputs>
<hash_0900259eefdb6640f3f9fa2f6bfdf9135b0cd0>
<name>Data Source [d]</name>
<description>d</description>
<column_name>task_item_id</column_name>
<items>hash_0000251210e4ae921055593929a9f41703cf25|hash_00002544359da88929bda518ca1c8809708993|hash_000025ac404e13020ab6f400dca560f37922d1|hash_00002515ec3c66d07404a13ad6e3c8178cd8f0</items>
</hash_0900259eefdb6640f3f9fa2f6bfdf9135b0cd0>
<hash_090025308e8e7eed3de1b7c06a8b0106f685e9>
<name>Data Source [b]</name>
<description>b</description>
<column_name>task_item_id</column_name>
<items>hash_00002587617c277de94698bdc3d784e2257595|hash_000025e88db2dfe01d9a68242f3b00af85da06|hash_00002591cbdb8c81005e78564efaa2c7045408|hash_000025659f92f53f26f1dbb9ae3238e9fca3e8</items>
</hash_090025308e8e7eed3de1b7c06a8b0106f685e9>
<hash_090025b0c0622d26d92272f75b7b080b4db020>
<name>Data Source [c]</name>
<description>c</description>
<column_name>task_item_id</column_name>
<items>hash_000025ad886e1f4f835761fddf7979e06cc06b|hash_0000252a650f2015d0cd2075a13090e99c2e88|hash_000025d960bb2d2aa8e2013f1a6e6ec005f348|hash_00002576e9b62101708aee0815b2e01508d41a</items>
</hash_090025b0c0622d26d92272f75b7b080b4db020>
<hash_090025ea7f568913627a2846e874fc99ed9e4f>
<name>Data Source [a]</name>
<description>a</description>
<column_name>task_item_id</column_name>
<items>hash_00002508f6db75c900100b68f5e707ea7651bf|hash_000025d0e3bbf50c29a3069342cd408826b753|hash_000025161e34504642f56fef3225d5b506b8ae|hash_000025da81390a6e5ba8a4f31aec4875cafb02</items>
</hash_090025ea7f568913627a2846e874fc99ed9e4f>
</inputs>
</hash_000025c35dc317aadf8219dabae7c29fd98694>
<hash_010025e0657ab786701649f57bdd91b48a2f14>
<name>url_status</name>
<ds>
<t_name></t_name>
<name>|host_description| - Nginx Clients Stat</name>
<data_input_id>hash_030025960615ed5ce72756b8e7a787439d0a2d</data_input_id>
<t_rra_id></t_rra_id>
<t_rrd_step></t_rrd_step>
<rrd_step>60</rrd_step>
<t_active></t_active>
<active>on</active>
<rra_items>hash_150025c21df5178e5c955013591239eb0afd46|hash_1500250d9c0af8b8acdc7807943937b3208e29|hash_1500256fc2d038fb42950138b0ce3e9874cc60|hash_150025e36f3adb9f152adfa5dc50fd2b23337e</rra_items>
</ds>
<items>
<hash_08002575698c6bd226db0b7cd67089e651f382>
<t_data_source_name></t_data_source_name>
<data_source_name>d</data_source_name>
<t_rrd_minimum></t_rrd_minimum>
<rrd_minimum>0</rrd_minimum>
<t_rrd_maximum></t_rrd_maximum>
<rrd_maximum>0</rrd_maximum>
<t_data_source_type_id></t_data_source_type_id>
<data_source_type_id>1</data_source_type_id>
<t_rrd_heartbeat></t_rrd_heartbeat>
<rrd_heartbeat>120</rrd_heartbeat>
<t_data_input_field_id></t_data_input_field_id>
<data_input_field_id>hash_070025170a796e21241e35063ecf3a62a62269</data_input_field_id>
</hash_08002575698c6bd226db0b7cd67089e651f382>
<hash_08002550e895b90a6d17b7a212997b7cb1afba>
<t_data_source_name></t_data_source_name>
<data_source_name>c</data_source_name>
<t_rrd_minimum></t_rrd_minimum>
<rrd_minimum>0</rrd_minimum>
<t_rrd_maximum></t_rrd_maximum>
<rrd_maximum>0</rrd_maximum>
<t_data_source_type_id></t_data_source_type_id>
<data_source_type_id>1</data_source_type_id>
<t_rrd_heartbeat></t_rrd_heartbeat>
<rrd_heartbeat>120</rrd_heartbeat>
<t_data_input_field_id></t_data_input_field_id>
<data_input_field_id>hash_070025cf6292f045b8cec3ec1784f559d5883e</data_input_field_id>
</hash_08002550e895b90a6d17b7a212997b7cb1afba>
<hash_080025729d4b3fa3813f2974ce01b29ca6850e>
<t_data_source_name></t_data_source_name>
<data_source_name>b</data_source_name>
<t_rrd_minimum></t_rrd_minimum>
<rrd_minimum>0</rrd_minimum>
<t_rrd_maximum></t_rrd_maximum>
<rrd_maximum>0</rrd_maximum>
<t_data_source_type_id></t_data_source_type_id>
<data_source_type_id>1</data_source_type_id>
<t_rrd_heartbeat></t_rrd_heartbeat>
<rrd_heartbeat>120</rrd_heartbeat>
<t_data_input_field_id></t_data_input_field_id>
<data_input_field_id>hash_0700252520eb79ec6e083c89a1056140fd741b</data_input_field_id>
</hash_080025729d4b3fa3813f2974ce01b29ca6850e>
<hash_0800256aa36fa51315e2d6d15b708307f2c53c>
<t_data_source_name></t_data_source_name>
<data_source_name>a</data_source_name>
<t_rrd_minimum></t_rrd_minimum>
<rrd_minimum>0</rrd_minimum>
<t_rrd_maximum></t_rrd_maximum>
<rrd_maximum>0</rrd_maximum>
<t_data_source_type_id></t_data_source_type_id>
<data_source_type_id>1</data_source_type_id>
<t_rrd_heartbeat></t_rrd_heartbeat>
<rrd_heartbeat>120</rrd_heartbeat>
<t_data_input_field_id></t_data_input_field_id>
<data_input_field_id>hash_070025cccbd578f0c2868c1e0a6f5f3329fc0b</data_input_field_id>
</hash_0800256aa36fa51315e2d6d15b708307f2c53c>
</items>
<data>
<item_000>
<data_input_field_id>hash_0700258cd1791fab89b88a3ff3ca112c6534b7</data_input_field_id>
<t_value>on</t_value>
<value>url</value>
</item_000>
</data>
</hash_010025e0657ab786701649f57bdd91b48a2f14>
<hash_030025960615ed5ce72756b8e7a787439d0a2d>
<name>url_status</name>
<type_id>1</type_id>
<input_string>/usr/bin/perl <path_cacti>/scripts/get_content.pl <stub_status_url></input_string>
<fields>
<hash_0700258cd1791fab89b88a3ff3ca112c6534b7>
<name>URL of nginx stub status</name>
<update_rra></update_rra>
<regexp_match></regexp_match>
<allow_nulls></allow_nulls>
<type_code></type_code>
<input_output>in</input_output>
<data_name>stub_status_url</data_name>
</hash_0700258cd1791fab89b88a3ff3ca112c6534b7>
<hash_070025cccbd578f0c2868c1e0a6f5f3329fc0b>
<name>a</name>
<update_rra>on</update_rra>
<regexp_match></regexp_match>
<allow_nulls></allow_nulls>
<type_code></type_code>
<input_output>out</input_output>
<data_name>a</data_name>
</hash_070025cccbd578f0c2868c1e0a6f5f3329fc0b>
<hash_0700252520eb79ec6e083c89a1056140fd741b>
<name>b</name>
<update_rra>on</update_rra>
<regexp_match></regexp_match>
<allow_nulls></allow_nulls>
<type_code></type_code>
<input_output>out</input_output>
<data_name>b</data_name>
</hash_0700252520eb79ec6e083c89a1056140fd741b>
<hash_070025170a796e21241e35063ecf3a62a62269>
<name>d</name>
<update_rra>on</update_rra>
<regexp_match></regexp_match>
<allow_nulls></allow_nulls>
<type_code></type_code>
<input_output>out</input_output>
<data_name>d</data_name>
</hash_070025170a796e21241e35063ecf3a62a62269>
<hash_070025cf6292f045b8cec3ec1784f559d5883e>
<name>c</name>
<update_rra>on</update_rra>
<regexp_match></regexp_match>
<allow_nulls></allow_nulls>
<type_code></type_code>
<input_output>out</input_output>
<data_name>c</data_name>
</hash_070025cf6292f045b8cec3ec1784f559d5883e>
</fields>
</hash_030025960615ed5ce72756b8e7a787439d0a2d>
<hash_150025c21df5178e5c955013591239eb0afd46>
<name>Daily (5 Minute Average)</name>
<x_files_factor>0.5</x_files_factor>
<steps>1</steps>
<rows>600</rows>
<timespan>86400</timespan>
<cf_items>1|2|3|4</cf_items>
</hash_150025c21df5178e5c955013591239eb0afd46>
<hash_1500250d9c0af8b8acdc7807943937b3208e29>
<name>Weekly (30 Minute Average)</name>
<x_files_factor>0.5</x_files_factor>
<steps>6</steps>
<rows>700</rows>
<timespan>604800</timespan>
<cf_items>1|2|3|4</cf_items>
</hash_1500250d9c0af8b8acdc7807943937b3208e29>
<hash_1500256fc2d038fb42950138b0ce3e9874cc60>
<name>Monthly (2 Hour Average)</name>
<x_files_factor>0.5</x_files_factor>
<steps>24</steps>
<rows>775</rows>
<timespan>2678400</timespan>
<cf_items>1|2|3|4</cf_items>
</hash_1500256fc2d038fb42950138b0ce3e9874cc60>
<hash_150025e36f3adb9f152adfa5dc50fd2b23337e>
<name>Yearly (1 Day Average)</name>
<x_files_factor>0.5</x_files_factor>
<steps>288</steps>
<rows>797</rows>
<timespan>33053184</timespan>
<cf_items>1|2|3|4</cf_items>
</hash_150025e36f3adb9f152adfa5dc50fd2b23337e>
<hash_060025e9c43831e54eca8069317a2ce8c6f751>
<name>Normal</name>
<gprint_text>%8.2lf %s</gprint_text>
</hash_060025e9c43831e54eca8069317a2ce8c6f751>
</cacti>