Code: Select all
# PREREQUISITES
#
# This assumes you've already installed the templates from Percona.
# Steps to do this are documented here:
# https://www.percona.com/doc/percona-monitoring-plugins/LATEST/cacti/index.html
#
# PROBLEM
#
# The Cacti graph templates from Percona use the AVERAGE consolidation
# function. This means that on the Weekly (30 Minute Average) graph,
# for example, the average result over thirty minute periods is
# displayed as the maximum value in the graph (and in the legend below
# the graph). The Weekly (30 Minute Average) Round Robin Archive has
# both the AVERAGE and MAX consolidation functions selected by default,
# so it's possible to modify the Percona graph templates to pull MAX
# data from the RRD files.
#
# SOLUTION
#
# First generate a new definition file with unique hashes. This will
# prevent overwriting the default Percona host, data, and graph
# templates if you've already imported them.
/usr/share/cacti/resource/percona/bin/pmp-cacti-make-hashes --refresh /usr/share/cacti/resource/percona/definitions/mysql.def > /usr/share/cacti/resource/percona/definitions/mysql-MAX.def
# If you also want to be able to define a port per graph template
# (useful if you have multiple MySQL servers that listen on different
# ports, or customize the size of the graphs (the default Cacti graphs
# are pretty small), use the --mpds, --graph_height, and --graph_width
# options. More details are here:
# https://www.percona.com/doc/percona-monitoring-plugins/LATEST/cacti/installing-templates.html
#
# If you don't want to require a port for each graph template or don't
# want to change the size of the graphs, just remove the options from
# the command.
/usr/share/cacti/resource/percona/bin/pmp-cacti-template --script /usr/share/cacti/scripts/ss_get_mysql_stats.php /usr/share/cacti/resource/percona/definitions/mysql-MAX.def --mpds port --graph_height 240 --graph_width 1100 > /usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml
# This will replace the default AVERAGE (id 1) consolidation function
# on all graph template items of types LINE1, LINE2, LINE3, AREA, and
# STACK with MAX (id 3) and rename the new template.
sed -i ':a;N;$!ba;s/<graph_type_id>\([4-8]\)<\/graph_type_id>\n\t\t\t\t<consolidation_function_id>1<\/consolidation_function_id>/<graph_type_id>\1<\/graph_type_id>\n\t\t\t\t<consolidation_function_id>3<\/consolidation_function_id>/g' /usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml
# Rename the host template, data templates, and graph templates to
# clarify their purpose.
sed -i 's/Percona MySQL Server HT/Percona MySQL Server HT MAX/g' /usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml
sed -i 's/GT/GT MAX/g' /usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml
sed -i 's/DT/DT MAX/g' /usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml
# Import the template into Cacti.
php /usr/share/cacti/cli/import_template.php --filename=/usr/share/cacti/resource/percona/templates/cacti_host_template_percona_mysql_server_ht_MAX_0.8.6i-sver1.1.6.xml --with-user-rras='1:2:3:4'
# Now navigate to your Cacti web UI, open the Graph Templates page, and
# click on any of the Percona graph templates. You should see "MAX" in
# the CF Type column on each graph. Now your graphs will display peak
# values for sample periods instead of averages.
#
# You may want to go to Data Sources/RRAs and rename the RRAs to reflect
# this change. For example, change "Weekly (30 Minute Average)" to
# "Weekly (30 Minute Peak)".