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';
37 our %TypesCounterToDerive = # {{{
39 apache_bytes => ["count"],
40 apache_requests => ["count"],
41 arc_counts => ["demand_data", "demand_metadata", "prefetch_data", "prefetch_metadata"],
42 arc_l2_bytes => ["read", "write"],
43 ath_stat => ["value"],
44 compression => ["uncompressed", "compressed"],
45 connections => ["value"],
48 disk_merged => ["read", "write"],
49 disk_octets => ["read", "write"],
50 disk_ops => ["read", "write"],
51 disk_ops_complex => ["value"],
52 disk_time => ["read", "write"],
53 dns_answer => ["value"],
54 dns_notify => ["value"],
55 dns_octets => ["queries", "responses"],
56 dns_opcode => ["value"],
57 dns_qtype => ["value"],
58 dns_query => ["value"],
59 dns_question => ["value"],
60 dns_rcode => ["value"],
61 dns_reject => ["value"],
62 dns_request => ["value"],
63 dns_resolver => ["value"],
64 dns_response => ["value"],
65 dns_transfer => ["value"],
66 dns_update => ["value"],
67 dns_zops => ["value"],
68 fscache_stat => ["value"],
69 fork_rate => ["value"],
70 http_request_methods => ["count"],
71 http_requests => ["count"],
72 http_response_codes => ["count"],
73 if_collisions => ["value"],
74 if_dropped => ["rx", "tx"],
75 if_errors => ["rx", "tx"],
76 if_multicast => ["value"],
77 if_octets => ["rx", "tx"],
78 if_packets => ["rx", "tx"],
79 if_rx_errors => ["value"],
80 if_tx_errors => ["value"],
81 io_octets => ["rx", "tx"],
82 io_packets => ["rx", "tx"],
83 ipt_bytes => ["value"],
84 ipt_packets => ["value"],
86 memcached_command => ["value"],
87 memcached_octets => ["rx", "tx"],
88 memcached_ops => ["value"],
89 mysql_commands => ["value"],
90 mysql_handler => ["value"],
91 mysql_locks => ["value"],
92 mysql_log_position => ["value"],
93 mysql_octets => ["rx", "tx"],
94 nfs_procedure => ["value"],
95 nginx_requests => ["value"],
96 node_octets => ["rx", "tx"],
97 node_stat => ["value"],
98 operations => ["value"],
100 pg_n_tup_c => ["value"],
101 pg_scan => ["value"],
102 pg_xact => ["value"],
103 protocol_counter => ["value"],
104 ps_cputime => ["user", "syst"],
105 ps_pagefaults => ["minflt", "majflt"],
106 ps_code => ["value"],
107 ps_data => ["value"],
108 serial_octets => ["rx", "tx"],
109 swap_io => ["value"],
110 virt_cpu_total => ["ns"],
112 vmpage_action => ["value"],
113 vmpage_faults => ["minflt", "majflt"],
114 vmpage_io => ["in", "out"],
115 ); # }}} %TypesCounterToDerive
117 our %TypesRenameDataSource = # {{{
120 apache_bytes => "count",
121 apache_connections => "count",
122 apache_idle_workers => "count",
123 apache_requests => "count",
124 apache_scoreboard => "count",
125 conntrack => "entropy",
126 contextswitch => "contextswitches",
128 entropy => "entropy",
129 file_size => "bytes",
130 frequency => "frequency",
131 frequency_offset => "ppm",
132 http_request_methods => "count",
133 http_requests => "count",
134 http_response_codes => "count",
135 percent => "percent",
138 time_dispersion => "seconds",
139 timeleft => "timeleft",
140 time_offset => "seconds",
142 virt_cpu_total => "ns",
144 ); # }}} %TypesRenameDataSource
146 sub handle_file # {{{
149 my $path = join ('/', @path);
151 if (!($path =~ m/\.rrd$/))
156 my $tmp = pop (@path);
158 my ($type, $type_inst) = split (m/-/, $tmp, 2);
162 my ($plugin, $plugin_inst) = split (m/-/, $tmp, 2);
165 if ($TypesRenameDataSource{$type})
167 my $old_ds = $TypesRenameDataSource{$type};
168 print "$RRDtool tune \"$path\" --data-source-rename ${old_ds}:value\n";
171 if ($TypesCounterToDerive{$type})
173 my $ds_names = $TypesCounterToDerive{$type};
178 print "$RRDtool tune \"$path\" --data-source-type ${name}:DERIVE --minimum ${name}:0 --maximum ${name}:U\n";
182 if ((($plugin eq 'df') || ($plugin eq 'interface'))
183 && (!$plugin_inst) && ($type_inst))
185 my $dir = join ('/', @path);
186 print "mkdir -p \"$dir/$plugin-$type_inst\"\n";
187 print "mv \"$path\" \"$dir/$plugin-$type_inst/$type.rrd\"\n";
189 } # }}} sub handle_file
194 my $dir_str = join ('/', @dir_parts);
197 opendir ($dh, $dir_str) || die;
198 while (my $entry = readdir ($dh))
200 my $entry_path = "$dir_str/$entry";
202 if ($entry =~ m/^\./)
209 scan_dir (@dir_parts, $entry);
211 elsif (-f $entry_path)
213 handle_file (@dir_parts, $entry);
222 migrate-4-5.px [OPTIONS]
226 --indir <dir> Source directory
228 --rrdtool <path> Path to the RRDtool binary
233 } # }}} sub exit_usage
235 GetOptions ("indir|i=s" => \$InDir,
236 "rrdtool=s" => \$RRDtool,
237 "help|h" => \&exit_usage) or exit_usage ();
241 # vim: set sw=2 sts=2 et fdm=marker :