Skip to content

Commit 778873e

Browse files
Merge pull request #78 from Sharpie/fix_psql_metrics
Fix psql_metrics error checking
2 parents bd61333 + 9cea5f5 commit 778873e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

files/psql_metrics

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,15 @@ EOS
557557
# NOTE: A little odd, since tk_metrics uses the certname. But, this
558558
# matches what system_metrics does.
559559
hostname = PSQLMetrics::Exec.exec_cmd('/bin/sh', '-c', 'hostname').stdout.strip
560+
# Sanitized to accommodate the dot-delimited naming scheme used
561+
# by the Graphite time-series database. This is the wrong place to
562+
# do this as it destroys useful hostname info, but we do it anyway
563+
# to be consistent with the other metrics collection scripts.
564+
server_name = hostname.gsub('.', '-')
560565
timestamp = Time.now.utc
561566

562567
metrics = PSQLMetrics.new(**@options)
563-
data = {servers: {hostname.gsub('.', '-') => {postgres: metrics.to_h}},
568+
data = {servers: {server_name => {postgres: metrics.to_h}},
564569
timestamp: timestamp.iso8601}
565570

566571
if (output_dir = @options[:output_dir])
@@ -573,7 +578,7 @@ EOS
573578
$stdout.puts(JSON.generate(data))
574579
end
575580

576-
if data[:servers][hostname][:postgres].key?(:error)
581+
if data[:servers][server_name][:postgres].key?(:error)
577582
return 1
578583
else
579584
return 0

0 commit comments

Comments
 (0)