3 # collectd - contrib/migrate-4-5.px
4 # Copyright (C) 2010 Florian Forster
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
25 # Florian Forster <octo at collectd.org>
30 use Getopt::Long ('GetOptions');
32 use File::Basename ('dirname');
34 our $InDir = '/var/lib/collectd';
35 our $OutDir = '/tmp/collectd-5';
36 our $RRDtool = 'rrdtool';
38 our %TypesCounterToDerive = # {{{
40 apache_bytes => ["count"],
41 apache_requests => ["count"],
42 arc_counts => ["demand_data", "demand_metadata", "prefetch_data", "prefetch_metadata"],
43 arc_l2_bytes => ["read", "write"],
44 ath_stat => ["value"],
45 compression => ["uncompressed", "compressed"],
46 connections => ["value"],
49 df => ["used", "free"],
50 disk_merged => ["read", "write"],
51 disk_octets => ["read", "write"],
52 disk_ops => ["read", "write"],
53 disk_ops_complex => ["value"],
54 disk_time => ["read", "write"],
55 dns_answer => ["value"],
56 dns_notify => ["value"],
57 dns_octets => ["queries", "responses"],
58 dns_opcode => ["value"],
59 dns_qtype => ["value"],
60 dns_query => ["value"],
61 dns_question => ["value"],
62 dns_rcode => ["value"],
63 dns_reject => ["value"],
64 dns_request => ["value"],
65 dns_resolver => ["value"],
66 dns_response => ["value"],
67 dns_transfer => ["value"],
68 dns_update => ["value"],
69 dns_zops => ["value"],
70 fscache_stat => ["value"],
71 fork_rate => ["value"],
72 http_request_methods => ["count"],
73 http_requests => ["count"],
74 http_response_codes => ["count"],
75 if_collisions => ["value"],
76 if_dropped => ["rx", "tx"],
77 if_errors => ["rx", "tx"],
78 if_multicast => ["value"],
79 if_octets => ["rx", "tx"],
80 if_packets => ["rx", "tx"],
81 if_rx_errors => ["value"],
82 if_tx_errors => ["value"],
83 io_octets => ["rx", "tx"],
84 io_packets => ["rx", "tx"],
85 ipt_bytes => ["value"],
86 ipt_packets => ["value"],
88 memcached_command => ["value"],
89 memcached_octets => ["rx", "tx"],
90 memcached_ops => ["value"],
91 mysql_commands => ["value"],
92 mysql_handler => ["value"],
93 mysql_locks => ["value"],
94 mysql_log_position => ["value"],
95 mysql_octets => ["rx", "tx"],
96 nfs_procedure => ["value"],
97 nginx_requests => ["value"],
98 node_octets => ["rx", "tx"],
99 node_stat => ["value"],
100 operations => ["value"],
101 pg_blks => ["value"],
102 pg_n_tup_c => ["value"],
103 pg_scan => ["value"],
104 pg_xact => ["value"],
105 protocol_counter => ["value"],
106 ps_cputime => ["user", "syst"],
107 ps_pagefaults => ["minflt", "majflt"],
108 ps_code => ["value"],
109 ps_data => ["value"],
110 serial_octets => ["rx", "tx"],
111 swap_io => ["value"],
112 virt_cpu_total => ["ns"],
114 vmpage_action => ["value"],
115 vmpage_faults => ["minflt", "majflt"],
116 vmpage_io => ["in", "out"],
117 ); # }}} %TypesCounterToDerive
119 our %TypesRenameDataSource = # {{{
122 apache_bytes => "count",
123 apache_connections => "count",
124 apache_idle_workers => "count",
125 apache_requests => "count",
126 apache_scoreboard => "count",
127 conntrack => "entropy",
128 contextswitch => "contextswitches",
130 entropy => "entropy",
131 file_size => "bytes",
132 frequency => "frequency",
133 frequency_offset => "ppm",
134 http_request_methods => "count",
135 http_requests => "count",
136 http_response_codes => "count",
137 percent => "percent",
140 time_dispersion => "seconds",
141 timeleft => "timeleft",
142 time_offset => "seconds",
144 virt_cpu_total => "ns",
146 ); # }}} %TypesRenameDataSource
148 sub handle_file # {{{
151 my $path = join ('/', @path);
153 if (!($path =~ m/\.rrd$/))
158 my $tmp = pop (@path);
160 my ($type, $type_inst) = split (m/-/, $tmp, 2);
164 my ($plugin, $plugin_inst) = split (m/-/, $tmp, 2);
167 if ($TypesRenameDataSource{$type})
169 my $old_ds = $TypesRenameDataSource{$type};
170 print "$RRDtool tune \"$path\" --data-source-rename ${old_ds}:value\n";
173 if ($TypesCounterToDerive{$type})
175 my $ds_names = $TypesCounterToDerive{$type};
180 print "$RRDtool tune \"$path\" --data-source-type ${name}:DERIVE --minimum ${name}:0 --maximum ${name}:U\n";
184 if ((($plugin eq 'df') || ($plugin eq 'interface'))
185 && (!$plugin_inst) && ($type_inst))
187 my $dir = join ('/', @path);
188 print "mv \"$path\" \"$dir/$plugin-$type_inst/$type.rrd\"\n";
190 } # }}} sub handle_file
195 my $dir_str = join ('/', @dir_parts);
198 opendir ($dh, $dir_str) || die;
199 while (my $entry = readdir ($dh))
201 my $entry_path = "$dir_str/$entry";
203 if ($entry =~ m/^\./)
210 scan_dir (@dir_parts, $entry);
212 elsif (-f $entry_path)
214 handle_file (@dir_parts, $entry);
223 migrate-4-5.px [OPTIONS]
227 --indir <dir> Source directory
229 --outdir <dir> Destination directory
231 --rrdtool <path> Path to the RRDtool binary
236 } # }}} sub exit_usage
238 GetOptions ("indir|i=s" => \$InDir,
239 "outdir|o=s" => \$OutDir,
240 "rrdtool=s" => \$RRDtool,
241 "help|h" => \&exit_usage) or exit_usage ();
245 # vim: set sw=2 sts=2 et fdm=marker :