Skip to content

Commit

Permalink
Fix psql_error checking
Browse files Browse the repository at this point in the history
This commit updates the psql_metrics collection script to fix an
issue with error checking. Previously, the script sanitized the
hostname that output data was stored under by replacing "." characters
with "-" characters. But, the error checking routine attempted to
look up data using the un-sanitized hostname. This caused error
checking to always register a failure even when data collection
was successful, which resulted in email spam from cron.

Ref. #71
Fixes #77
  • Loading branch information
Sharpie committed Jan 21, 2021
1 parent bd61333 commit 55e705b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions files/psql_metrics
Expand Up @@ -557,10 +557,15 @@ EOS
# NOTE: A little odd, since tk_metrics uses the certname. But, this
# matches what system_metrics does.
hostname = PSQLMetrics::Exec.exec_cmd('/bin/sh', '-c', 'hostname').stdout.strip
# Sanitized to accommodate the dot-delimited naming scheme used
# by the Graphite time-series database. This is the wrong place to
# do this as it destroys useful hostname info, but we do it anyway
# to be consistent with the other metrics collection scripts.
server_name = hostname.gsub('.', '-')
timestamp = Time.now.utc

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

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

if data[:servers][hostname][:postgres].key?(:error)
if data[:servers][server_name][:postgres].key?(:error)
return 1
else
return 0
Expand Down

0 comments on commit 55e705b

Please sign in to comment.