Script to modify the data files of Munin

この記事は先日の記事の英語版です。リクエストが有ったので翻訳してみました。

When you update the node name in the munin.conf, you must modify the data files names. If you installed the package, the default directory structure is the following.

Data directory /var/lib/munin
HTML files /var/www/html/munin

The data files of monitoring nodes exist in the following locations.

  • /var/lib/munin/state--.storable
  • /var/lib/munin//-.rrd
  • /var/www/html/munin///

Also It's a good idea that you delete the graph data following directory:

  • /var/lib/munin/munin-cgi-graph///

If the host name or group name has been updated, you must modify their data files in accordance with naming rules.

The bulk update with the script

The bulk update script is following:

This script allows you to:

  • When you change the node name in the munin.conf, update its data files.
  • When you delete the node name from the munin.conf, delete its data files.

How to use is the following:

  1. Adding execute permission
  2. Setting datadir, htmldir and cgitmpdir
  3. Update the ''munin.conf''
  4. Run this script

It is run interactively.

Environment is assumed the following.

  • CentOS6(RHEL6) 64bit / Ubuntu
  • Munin2.0
Examples
[hoge.example.com]
    address hoge.example.com
    use_node_name yes

to

[hoge.example.jp]
    address hoge.example.jp
    use_node_name yes

$ sudo /opt/sbin/munin-modify-data.sh
Please select the action
1) rename
2) delete
3) exit
Enter menu number> 1
Please enter OLD GROUP name > example.com
Please enter OLD NODE name > hoge.example.com
Please enter NEW GROUP name [example.com] > example.jp
Please enter NEW NODE name [hoge.example.com] > hoge.example.jp

OLD Group: example.com
OLD Node : hoge.example.com
New Group: example.jp
New Node : hoge.example.jp

OK? [y/n]: y
Waiting for the munin-update and munin-html processes to finish.

move state files:
        /var/lib/munin/state-example.com-hoge.example.com.storable >>> /var/lib/munin/state-example.jp-hoge.example.jp.storable
rename data files:
        rename example.com/hoge.example.com example.jp/hoge.example.jp /var/lib/munin/example.com/hoge.example.com-*
move html files:
        /var/www/html/munin/example.com/hoge.example.com/ >>> /var/www/html/munin/example.jp/hoge.example.jp/
delete graph directory:
        /var/lib/munin/cgi-tmp/munin-cgi-graph/example.com/hoge.example.com/

delete the empty directory '/var/lib/munin/example.com'
delete the empty directory '/var/www/html/munin/example.com'
delete the empty directory '/var/lib/munin/cgi-tmp/munin-cgi-graph/example.com'
  • Changing the node name('Group:hoge Host:hoge-ap' to 'Group:hoge Host:foo-ap')
[hoge;hoge-ap]
    address hoge-ap.internal
    use_node_name yes

to

[hoge;foo-ap]
    address foo-ap.internal
    use_node_name yes

$ sudo munin-modify-data.sh
Please select the action
1) rename
2) delete
3) exit
Enter menu number> 1
Please enter OLD GROUP name > hoge
Please enter OLD NODE name > hoge-ap
Please enter NEW GROUP name [hoge] >
Please enter NEW NODE name [hoge-ap] > foo-ap

OLD Group: hoge
OLD Node : hoge-ap
New Group: hoge
New Node : foo-ap

OK? [y/n]: y
Waiting for the munin-update and munin-html processes to finish.
.......
move state files:
        /var/lib/munin/state-hoge-hoge-ap.storable >>> /var/lib/munin/state-hoge-foo-ap.storable
rename data files:
        rename hoge/hoge-ap hoge/foo-ap /var/lib/munin/hoge/hoge-ap-*
move html files:
        /var/www/html/munin/hoge/hoge-ap/ >>> /var/www/html/munin/hoge/foo-ap/
delete graph directory:
        /var/lib/munin/cgi-tmp/munin-cgi-graph/hoge/hoge-ap/

delete the empty directory '/var/lib/munin/cgi-tmp/munin-cgi-graph/hoge'
  • Deleting data files.
$ sudo munin-modify-data.sh
Please select the action
1) rename
2) delete
3) exit
Enter menu number> 2
Please enter DELETE GROUP name > hoge
Please enter DELETE NODE name > foo-ap

DELETE Group: hoge
DELETE Node : foo-ap

OK? [y/n]: y
Waiting for the munin-update and munin-html processes to finish.
...
delete state files:
        /var/lib/munin/state-hoge-foo-ap.storable
delete data files:
        /var/lib/munin/hoge/foo-ap-*
delete html files:
        /var/www/html/munin/hoge/foo-ap/
delete graph directory:
        /var/lib/munin/cgi-tmp/munin-cgi-graph/hoge/foo-ap/

delete the empty directory '/var/lib/munin/hoge'
delete the empty directory '/var/www/html/munin/hoge'
delete the empty directory '/var/lib/munin/cgi-tmp/munin-cgi-graph/hoge'

The flow is following:

  • If the munin-update or munin-html processes are running, waiting for its to finish.(It may be better to disable the cron.)
  • If you no longer have node in the original group by moving the node, it will also delete the directory of the group.
  • If you no longer have node in the original group by deleting the node, it also delete the directory group.

Please be careful with the steps, so do not look until consistency of strict data. If you can tolerate loss of temporary data during data migration:

  1. Disable cron
  2. modify setting in the munin.conf
  3. Run this script
  4. Enable cron

Additionally

I was thinking also that it's run by passing information in the argument of the command, but the interactive execution is easy to use for me. It may be good to be usable by batch processing.