Skip to content

Commit e72cbf3

Browse files
committed
(maint) Sync system_metrics directory naming
This patch updates `psql_metrics` and `vmware_metrics` such that output directories are created from the hostname without replacing `.` by `-`. This change matches the behavior of the `system_metrics` script. A missing `timestamp` key is also added to the output of `psql_metrics`.
1 parent ffb3060 commit e72cbf3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

files/psql_metrics

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,17 @@ EOS
556556

557557
# NOTE: A little odd, since tk_metrics uses the certname. But, this
558558
# matches what system_metrics does.
559-
hostname = PSQLMetrics::Exec.exec_cmd('/bin/sh', '-c', 'hostname').stdout.strip.gsub('.', '-')
559+
hostname = PSQLMetrics::Exec.exec_cmd('/bin/sh', '-c', 'hostname').stdout.strip
560+
timestamp = Time.now.utc
560561

561562
metrics = PSQLMetrics.new(**@options)
562-
data = {servers: {hostname => {postgres: metrics.to_h}}}
563+
data = {servers: {hostname.gsub('.', '-') => {postgres: metrics.to_h}},
564+
timestamp: timestamp.iso8601}
563565

564566
if (output_dir = @options[:output_dir])
565567
host_dir = File.join(output_dir, hostname)
566568
FileUtils.mkdir_p(host_dir) unless File.directory?(host_dir)
567-
output_file = File.join(host_dir, Time.now.utc.strftime('%Y%m%dT%H%M%SZ') + '.json')
569+
output_file = File.join(host_dir, timestamp.strftime('%Y%m%dT%H%M%SZ') + '.json')
568570

569571
File.write(output_file, JSON.generate(data))
570572
else

files/vmware_metrics

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module PuppetMetricsCollector
4343

4444
# NOTE: A little odd, since tk_metrics uses the certname. But, this
4545
# matches what system_metrics does.
46-
@hostname = exec_cmd('/bin/sh', '-c', 'hostname').strip.gsub('.', '-')
46+
@hostname = exec_cmd('/bin/sh', '-c', 'hostname').strip
4747
end
4848

4949
# Gather VMware metrics
@@ -70,12 +70,12 @@ module PuppetMetricsCollector
7070
end
7171

7272
{servers: {
73-
@hostname => {
73+
@hostname.gsub('.', '-') => {
7474
vmware: result}},
7575
timestamp: Time.now.utc.iso8601}
7676
rescue => e
7777
{servers: {
78-
@hostname => {
78+
@hostname.gsub('.', '-') => {
7979
vmware: {
8080
error: "#{e.class}: #{e.message}"}}},
8181
timestamp: Time.now.utc.iso8601}

0 commit comments

Comments
 (0)