Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix psql_metrics error checking #78

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions files/psql_metrics
Original file line number Diff line number Diff line change
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