File tree 2 files changed +12
-5
lines changed
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 32
32
33
33
34
34
# 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 )
36
36
37
37
# Arguments and defaults.
38
38
metrics_directory=" ${metrics_directory:-/ opt/ puppetlabs/ puppet-metrics-collector/ puppetserver} "
@@ -52,6 +52,13 @@ paths_regex="$(IFS='|'; echo "${valid_paths[*]}")"
52
52
find " $metrics_directory " -type f -ctime +" $retention_days " -delete
53
53
54
54
# 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 "
Original file line number Diff line number Diff line change @@ -325,7 +325,7 @@ module SystemMetrics
325
325
hostkey = @hostname . gsub ( '.' , '-' )
326
326
metrics_json = { 'timestamp' => @time_stamp_obj . utc . iso8601 , 'servers' => { } }
327
327
metrics_json [ 'servers' ] [ hostkey ] = { @metric_type => metrics_data }
328
- JSON . pretty_generate ( metrics_json )
328
+ JSON . generate ( metrics_json )
329
329
end
330
330
331
331
# Create the metric file and put the json data in it
You can’t perform that action at this time.
0 commit comments