Showing with 45 additions and 3 deletions.
  1. +8 −0 CHANGELOG.md
  2. +29 −0 files/json2timeseriesdb
  3. +7 −2 files/psql_metrics
  4. +1 −1 metadata.json
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Minor Release 6.3.0

## Improvements
- Update json2timeseriesdb to tag Postgres metrics [#79](https://github.com/puppetlabs/puppetlabs-puppet_metrics_collector/pull/79)

## Changes:
- Fix psql_metrics error checking [#78](https://github.com/puppetlabs/puppetlabs-puppet_metrics_collector/pull/78)

# Minor Release 6.2.0

## Improvements
Expand Down
29 changes: 29 additions & 0 deletions files/json2timeseriesdb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,35 @@ def influx_tag_parser(tag)
tag.delete('broker-service')
end

if tag.include?('postgres') && tag.include?('databases')
n = tag.index('databases')
db_name = tag[n + 1]
tag_set = "#{tag_set}database=#{db_name},"
tag.delete_at(n + 1)
end

if tag.include?('postgres') && tag.include?('replication_slots')
n = tag.index('replication_slots')
slot_name = tag[n + 1]
tag_set = "#{tag_set}replication_slot=#{slot_name}"
tag.delete_at(n + 1)
end

if tag.include?('postgres') && tag.include?('replication_subs')
n = tag.index('replication_subs')
slot_name = tag[n + 1]
tag_set = "#{tag_set}replication_slot=#{slot_name}"
tag.delete_at(n + 1)
end

if tag.include?('postgres') && ['table_stats', 'index_stats', 'toast_stats'].any? {|e| tag.include?(e)}
metric = ['table_stats', 'index_stats', 'toast_stats'].find {|e| tag.include?(e)}
n = tag.index(metric)
relation = tag[n + 1]
tag_set = "#{tag_set}relation=#{relation}"
tag.delete_at(n + 1)
end

if tag.include?('Queue')
n = tag.index('Queue')
amq_destination_name = tag[n + 1]
Expand Down
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
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-puppet_metrics_collector",
"version": "6.2.0",
"version": "6.3.0",
"author": "npwalker",
"summary": "A Puppet module for gathering metrics from PE components",
"license": "Apache-2.0",
Expand Down