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 $RRDtool = 'rrdtool';
36 our $RRDFilter = 'rrd_filter.px';
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 disk_merged => ["read", "write"],
50 disk_octets => ["read", "write"],
51 disk_ops => ["read", "write"],
52 disk_ops_complex => ["value"],
53 disk_time => ["read", "write"],
54 dns_answer => ["value"],
55 dns_notify => ["value"],
56 dns_octets => ["queries", "responses"],
57 dns_opcode => ["value"],
58 dns_qtype => ["value"],
59 dns_query => ["value"],
60 dns_question => ["value"],
61 dns_rcode => ["value"],
62 dns_reject => ["value"],
63 dns_request => ["value"],
64 dns_resolver => ["value"],
65 dns_response => ["value"],
66 dns_transfer => ["value"],
67 dns_update => ["value"],
68 dns_zops => ["value"],
69 fscache_stat => ["value"],
70 fork_rate => ["value"],
71 http_request_methods => ["count"],
72 http_requests => ["count"],
73 http_response_codes => ["count"],
74 if_collisions => ["value"],
75 if_dropped => ["rx", "tx"],
76 if_errors => ["rx", "tx"],
77 if_multicast => ["value"],
78 if_octets => ["rx", "tx"],
79 if_packets => ["rx", "tx"],
80 if_rx_errors => ["value"],
81 if_tx_errors => ["value"],
82 io_octets => ["rx", "tx"],
83 io_packets => ["rx", "tx"],
84 ipt_bytes => ["value"],
85 ipt_packets => ["value"],
87 memcached_command => ["value"],
88 memcached_octets => ["rx", "tx"],
89 memcached_ops => ["value"],
90 mysql_commands => ["value"],
91 mysql_handler => ["value"],
92 mysql_locks => ["value"],
93 mysql_log_position => ["value"],
94 mysql_octets => ["rx", "tx"],
95 nfs_procedure => ["value"],
96 nginx_requests => ["value"],
97 node_octets => ["rx", "tx"],
98 node_stat => ["value"],
99 operations => ["value"],
100 pg_blks => ["value"],
101 pg_n_tup_c => ["value"],
102 pg_scan => ["value"],
103 pg_xact => ["value"],
104 protocol_counter => ["value"],
105 ps_cputime => ["user", "syst"],
106 ps_pagefaults => ["minflt", "majflt"],
107 ps_code => ["value"],
108 ps_data => ["value"],
109 serial_octets => ["rx", "tx"],
110 swap_io => ["value"],
111 virt_cpu_total => ["ns"],
113 vmpage_action => ["value"],
114 vmpage_faults => ["minflt", "majflt"],
115 vmpage_io => ["in", "out"],
116 ); # }}} %TypesCounterToDerive
118 our %TypesRenameDataSource = # {{{
121 apache_bytes => "count",
122 apache_connections => "count",
123 apache_idle_workers => "count",
124 apache_requests => "count",
125 apache_scoreboard => "count",
126 conntrack => "entropy",
127 contextswitch => "contextswitches",
129 entropy => "entropy",
130 file_size => "bytes",
131 frequency => "frequency",
132 frequency_offset => "ppm",
133 http_request_methods => "count",
134 http_requests => "count",
135 http_response_codes => "count",
136 percent => "percent",
139 time_dispersion => "seconds",
140 timeleft => "timeleft",
141 time_offset => "seconds",
143 virt_cpu_total => "ns",
145 ); # }}} %TypesRenameDataSource
147 sub handle_file # {{{
150 my $path = join ('/', @path);
152 if (!($path =~ m/\.rrd$/))
157 my $tmp = pop (@path);
159 my ($type, $type_inst) = split (m/-/, $tmp, 2);
163 my ($plugin, $plugin_inst) = split (m/-/, $tmp, 2);
166 if ($TypesRenameDataSource{$type})
168 my $old_ds = $TypesRenameDataSource{$type};
169 print "$RRDtool tune \"$path\" --data-source-rename ${old_ds}:value\n";
172 if ($TypesCounterToDerive{$type})
174 my $ds_names = $TypesCounterToDerive{$type};
179 print "$RRDtool tune \"$path\" --data-source-type ${name}:DERIVE --minimum ${name}:0 --maximum ${name}:U\n";
183 if ((($plugin eq 'df') || ($plugin eq 'interface'))
184 && (!$plugin_inst) && ($type_inst))
186 my $dir = join ('/', @path);
187 print "mkdir -p \"$dir/$plugin-$type_inst\"\n";
188 if (($plugin eq 'df') and ($type eq 'df'))
190 print "$RRDFilter --infile=\"$path\" --outfile=\"$dir/$plugin-$type_inst/df_complex-free.rrd\" --map free:value\n";
191 print "$RRDFilter --infile=\"$path\" --outfile=\"$dir/$plugin-$type_inst/df_complex-used.rrd\" --map used:value\n";
195 print "mv \"$path\" \"$dir/$plugin-$type_inst/$type.rrd\"\n";
198 } # }}} sub handle_file
203 my $dir_str = join ('/', @dir_parts);
206 opendir ($dh, $dir_str) || die;
207 while (my $entry = readdir ($dh))
209 my $entry_path = "$dir_str/$entry";
211 if ($entry =~ m/^\./)
218 scan_dir (@dir_parts, $entry);
220 elsif (-f $entry_path)
222 handle_file (@dir_parts, $entry);
231 migrate-4-5.px [OPTIONS]
235 --indir <dir> Source directory
237 --rrdtool <path> Path to the RRDtool binary
239 --rrdfilter <path> Path to the rrd_filter.px script
244 } # }}} sub exit_usage
246 GetOptions ("indir|i=s" => \$InDir,
247 "rrdtool=s" => \$RRDtool,
248 "rrdfilter=s" => \$RRDFilter,
249 "help|h" => \&exit_usage) or exit_usage ();
251 print "#!/bin/bash\n\n";
255 # vim: set sw=2 sts=2 et fdm=marker :