From 7a6c603a26cfdf85365d1d9cf8e269763af7d7bb Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 5 Mar 2009 09:30:06 +0100 Subject: [PATCH] contrib/collection3: Add the "DataDir" config option. --- contrib/collection3/etc/collection.conf | 1 + .../collection3/lib/Collectd/Graph/Common.pm | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/contrib/collection3/etc/collection.conf b/contrib/collection3/etc/collection.conf index cc13b4c3..b7e76b2b 100644 --- a/contrib/collection3/etc/collection.conf +++ b/contrib/collection3/etc/collection.conf @@ -1,3 +1,4 @@ +#DataDir "/var/lib/collectd/rrd" GraphWidth 400 #UnixSockAddr "/var/run/collectd-unixsock" diff --git a/contrib/collection3/lib/Collectd/Graph/Common.pm b/contrib/collection3/lib/Collectd/Graph/Common.pm index 6f26fd82..0deefd63 100644 --- a/contrib/collection3/lib/Collectd/Graph/Common.pm +++ b/contrib/collection3/lib/Collectd/Graph/Common.pm @@ -5,9 +5,11 @@ use warnings; use vars (qw($ColorCanvas $ColorFullBlue $ColorHalfBlue)); +use Collectd::Unixsock (); use Carp (qw(confess cluck)); use CGI (':cgi'); use Exporter; +use Collectd::Graph::Config (qw(gc_get_scalar)); $ColorCanvas = 'FFFFFF'; $ColorFullBlue = '0000FF'; @@ -41,7 +43,7 @@ $ColorHalfBlue = 'B7B7F7'; flush_files )); -our $DataDir = '/var/lib/collectd/rrd'; +our $DefaultDataDir = '/var/lib/collectd/rrd'; return (1); @@ -144,6 +146,7 @@ sub filename_to_ident sub ident_to_filename { my $ident = shift; + my $data_dir = gc_get_scalar ('DataDir', $DefaultDataDir); my $ret = ''; @@ -153,7 +156,7 @@ sub ident_to_filename } else { - $ret .= "$DataDir/"; + $ret .= "$data_dir/"; } if (!$ident->{'hostname'}) @@ -255,12 +258,13 @@ sub get_all_hosts { my $dh; my @ret = (); + my $data_dir = gc_get_scalar ('DataDir', $DefaultDataDir); - opendir ($dh, "$DataDir") or confess ("opendir ($DataDir): $!"); + opendir ($dh, "$data_dir") or confess ("opendir ($data_dir): $!"); while (my $entry = readdir ($dh)) { next if ($entry =~ m/^\./); - next if (!-d "$DataDir/$entry"); + next if (!-d "$data_dir/$entry"); push (@ret, sanitize_hostname ($entry)); } closedir ($dh); @@ -284,6 +288,7 @@ sub get_all_plugins my @hosts = @_; my $ret = {}; my $dh; + my $data_dir = gc_get_scalar ('DataDir', $DefaultDataDir); if (!@hosts) { @@ -293,14 +298,14 @@ sub get_all_plugins for (@hosts) { my $host = $_; - opendir ($dh, "$DataDir/$host") or next; + opendir ($dh, "$data_dir/$host") or next; while (my $entry = readdir ($dh)) { my $plugin; my $plugin_instance = ''; next if ($entry =~ m/^\./); - next if (!-d "$DataDir/$host/$entry"); + next if (!-d "$data_dir/$host/$entry"); if ($entry =~ m#^([^-]+)-(.+)$#) { @@ -336,7 +341,8 @@ sub get_all_plugins sub get_files_for_host { my $host = sanitize_hostname (shift); - return (get_files_from_directory ("$DataDir/$host", 2)); + my $data_dir = gc_get_scalar ('DataDir', $DefaultDataDir); + return (get_files_from_directory ("$data_dir/$host", 2)); } # get_files_for_host sub _filter_ident @@ -382,6 +388,7 @@ sub get_files_by_ident my $ident = shift; my $all_files; my @ret = (); + my $data_dir = gc_get_scalar ('DataDir', $DefaultDataDir); #if ($ident->{'hostname'}) #{ @@ -389,7 +396,7 @@ sub get_files_by_ident #} #else #{ - $all_files = get_files_from_directory ($DataDir, 3); + $all_files = get_files_from_directory ($data_dir, 3); #} @ret = grep { _filter_ident ($ident, $_) == 0 } (@$all_files); -- 2.30.2