Skip to content

Commit 2386c44

Browse files
authored
Merge pull request #61 from jarretlavallee/fix/master/pretty
Reduce the size of files on disk
2 parents 6ee4aa9 + cf37de0 commit 2386c44

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

files/metrics_tidy

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ done
3232

3333

3434
# Guard against deleting or archiving files outside of a Puppet service metrics directory.
35-
valid_paths=(puppetserver puppetdb orchestrator ace bolt activemq)
35+
valid_paths=(puppetserver puppetdb orchestrator ace bolt activemq system_processes system_memory system_cpu)
3636

3737
# Arguments and defaults.
3838
metrics_directory="${metrics_directory:-/opt/puppetlabs/puppet-metrics-collector/puppetserver}"
@@ -52,6 +52,13 @@ paths_regex="$(IFS='|'; echo "${valid_paths[*]}")"
5252
find "$metrics_directory" -type f -ctime +"$retention_days" -delete
5353

5454
# Compress the remaining files in a Puppet service metrics directory.
55-
# The return code of a pipeline is the rightmost command, which means we trigger our trap if tar fails
56-
find "$metrics_directory" -type f -name "*json" | \
57-
tar --create --gzip --file "${metrics_directory}/${metrics_type}-$(date +%Y.%m.%d.%H.%M.%S).tar.gz" --files-from -
55+
# Store the list of files in a temp file so that `tar` and `rm` will operate on the same files
56+
metrics_tmp="$(mktemp)"
57+
find "$metrics_directory" -type f -name "*json" >"$metrics_tmp"
58+
tar --create --gzip --file "${metrics_directory}/${metrics_type}-$(date +%Y.%m.%d.%H.%M.%S).tar.gz" \
59+
--files-from "$metrics_tmp"
60+
61+
# Cleanup the backed up json files so that we do not duplicate files in the tarballs.
62+
# We can assume that the json files have no spaces as they are created by our scripts
63+
xargs -a "$metrics_tmp" rm
64+
rm "$metrics_tmp"

files/system_metrics

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ module SystemMetrics
325325
hostkey = @hostname.gsub('.', '-')
326326
metrics_json = {'timestamp' => @time_stamp_obj.utc.iso8601, 'servers' => {}}
327327
metrics_json['servers'][hostkey] = {@metric_type => metrics_data}
328-
JSON.pretty_generate(metrics_json)
328+
JSON.generate(metrics_json)
329329
end
330330

331331
# Create the metric file and put the json data in it

0 commit comments

Comments
 (0)