Skip to content

Commit 013e8cf

Browse files
committed
Merge pull request #23644 from Fryguy/mounted_log_collection
Support /mnt/log_collection mount point for log collection
2 parents ca0ad55 + a94dd81 commit 013e8cf

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

tools/collect_logs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
To collect logs manually, please use the collect_archive_logs.sh and/or collect_current_logs.sh scripts within this collect_logs directory depending on the information that is requested.
1+
To collect logs manually, please use the collect_archive_logs.sh and/or collect_current_logs.sh scripts within this collect_logs directory depending on the information that is requested.
22
Use the exclude_files file to add any files you don't want included in log collection.
3+
4+
If you need NFS, Samba, or some other type of shared storage to collect logs, you can mount the storage to the /mnt/log_collection directory, and we will use that instead of the /var/www/miq/vmdb/log directory.

tools/collect_logs/collect_all_logs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ require File.expand_path("../../config/environment", __dir__)
44
require "optimist"
55
require "awesome_spawn"
66
require "manageiq-ssh-util"
7+
require "pathname"
78

89
class CollectAllLogs
910
def initialize(opts = {})
1011
@remote_user = opts.fetch(:remote_user, "root")
1112
@remote_password = opts.fetch(:remote_password, nil)
12-
@vmdb_log_dir = Rails.root.join("log")
13-
@target_log_dir = vmdb_log_dir.join("evm_current_region_#{MiqRegion.my_region&.id}_#{Time.now.utc.strftime("%Y%m%d_%H%M%S")}")
13+
14+
log_collection_mount = Pathname.new("/mnt/log_collection")
15+
@base_log_dir = log_collection_mount.mountpoint? ? log_collection_mount.join("log") : Rails.root.join("log")
16+
@target_log_dir = @base_log_dir.join("evm_current_region_#{MiqRegion.my_region&.id}_#{Time.now.utc.strftime("%Y%m%d_%H%M%S")}")
1417
end
1518

1619
def self.collect_all_logs!(opts = {})
@@ -19,7 +22,7 @@ class CollectAllLogs
1922

2023
def collect_all_logs
2124
# Create the directory to copy all log bundles into
22-
target_log_dir.mkdir
25+
target_log_dir.mkpath
2326

2427
active_miq_servers = MiqServer.active_miq_servers
2528

@@ -38,7 +41,7 @@ class CollectAllLogs
3841
abort("Collecting logs from [#{active_miq_servers.count}] servers in #{MiqRegion.my_region.description}...Failed") if results.none?(&:success?)
3942

4043
# Tar up all of the logs we have collected from the servers
41-
`cd #{vmdb_log_dir} && tar cfJ #{target_log_dir.basename}.tar.xz #{target_log_dir.basename} 2>&1`
44+
`cd #{base_log_dir} && tar cfJ #{target_log_dir.basename}.tar.xz #{target_log_dir.basename} 2>&1`
4245

4346
# Cleanup the directory that we created the tar from
4447
FileUtils.rm_r(target_log_dir)
@@ -48,7 +51,7 @@ class CollectAllLogs
4851

4952
private
5053

51-
attr_reader :remote_user, :remote_password, :target_log_dir, :vmdb_log_dir
54+
attr_reader :remote_user, :remote_password, :target_log_dir, :base_log_dir
5255

5356
def collect_logs(miq_server)
5457
server_ident = miq_server.hostname || miq_server.ipaddress

tools/collect_logs/collect_archive_logs.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@
33
# save directory from which command is initiated
44
collect_logs_directory=$(pwd)
55

6-
# make the vmdb/log directory the current directory
7-
vmdb_logs_directory="/var/www/miq/vmdb"
8-
pushd ${vmdb_logs_directory}
6+
# determine where to write the logs to
7+
if mountpoint /mnt/log_collection >/dev/null; then
8+
base_log_dir="/mnt/log_collection"
9+
else
10+
base_log_dir="/var/www/miq/vmdb"
11+
fi
12+
pushd ${base_log_dir}
13+
mkdir -p log
914

10-
# eliminiate any prior collected logs to make sure that only one collection is current
15+
# eliminate any prior collected logs to make sure that only one collection is current
1116
rm -f log/evm_full_archive_$(uname -n)* log/evm_archived_$(uname -n)*
1217

13-
#Source in the file so that we can call postgresql functions
18+
# Source in the file so that we can call postgresql functions
1419
source /etc/default/evm
1520

1621
tarball="log/evm_archive_$(uname -n)_$(date +%Y%m%d_%H%M%S).tar.xz"
1722

1823
if [[ -n "$APPLIANCE_PG_DATA" && -d "$APPLIANCE_PG_DATA/log" ]]; then
1924
echo "This ManageIQ appliance has a Database server and is running version: $(psql --version)"
2025
echo " Log collection starting:"
21-
XZ_OPT=-9 tar -cJvf ${tarball} --sparse --warning=no-file-changed -X $collect_logs_directory/exclude_files BUILD GUID VERSION log/* config/* /var/log/* log/apache/* $APPLIANCE_PG_DATA/log/* $APPLIANCE_PG_DATA/postgresql.conf
26+
XZ_OPT=-9 tar -cJvf ${tarball} --sparse --warning=no-file-changed -X $collect_logs_directory/exclude_files BUILD GUID VERSION log/* config/* /var/log/* log/apache/* $APPLIANCE_PG_DATA/log/* $APPLIANCE_PG_DATA/postgresql.conf
2227
else
2328
echo "This ManageIQ appliance is not a Database server"
2429
echo " Log collection starting:"
@@ -29,4 +34,4 @@ fi
2934
popd
3035

3136
# let the user know where the archive is
32-
echo "Archive Written To: ${vmdb_logs_directory}/${tarball}"
37+
echo "Archive Written To: ${base_log_dir}/${tarball}"

tools/collect_logs/collect_current_logs.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
# save directory from which command is initiated
44
collect_logs_directory=$(pwd)
55

6-
# make the vmdb/log directory the current directory
7-
vmdb_logs_directory="/var/www/miq/vmdb"
8-
pushd ${vmdb_logs_directory}
6+
# determine where to write the logs to
7+
if mountpoint /mnt/log_collection >/dev/null; then
8+
base_log_dir="/mnt/log_collection"
9+
else
10+
base_log_dir="/var/www/miq/vmdb"
11+
fi
12+
pushd ${base_log_dir}
13+
mkdir -p log
914

10-
# eliminiate any prior collected logs to make sure that only one collection is current
15+
# eliminate any prior collected logs to make sure that only one collection is current
1116
rm -f log/evm_full_archive_$(uname -n)* log/evm_current_$(uname -n)*
1217

13-
#Source in the file so that we can call postgresql functions
18+
# Source in the file so that we can call postgresql functions
1419
source /etc/default/evm
1520

1621
tarball="log/evm_current_$(uname -n)_$(date +%Y%m%d_%H%M%S).tar.xz"
@@ -29,4 +34,4 @@ fi
2934
popd
3035

3136
# let the user know where the archive is
32-
echo "Archive Written To: ${vmdb_logs_directory}/${tarball}"
37+
echo "Archive Written To: ${base_log_dir}/${tarball}"

0 commit comments

Comments
 (0)