Skip to content

Commit e02286d

Browse files
rothgartruthbk
authored andcommitted
Added multiple postgres instances and fixed pgbouncer (#372)
* Added postgress instances and fixed pgbouncer * Revert file name variable quoting
1 parent 2351697 commit e02286d

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

manifests/integrations/pgbouncer.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
$tags = [],
5252
$pgbouncers = [],
5353
) inherits datadog_agent::params {
54+
include datadog_agent
5455

5556
validate_array($tags)
5657
validate_array($pgbouncers)

manifests/integrations/postgres.pp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
$tags = [],
6262
$tables = [],
6363
$custom_metrics = {},
64+
$instances = undef,
6465
) inherits datadog_agent::params {
6566
include datadog_agent
6667

@@ -74,6 +75,24 @@
7475
$dst = "${datadog_agent::conf_dir}/postgres.yaml"
7576
}
7677

78+
if !$instances and $host {
79+
$_instances = [{
80+
'host' => $host,
81+
'password' => $password,
82+
'dbname' => $dbname,
83+
'port' => $port,
84+
'username' => $username,
85+
'use_psycopg2' => $use_psycopg2,
86+
'tags' => $tags,
87+
'tables' => $tables,
88+
'custom_metrics' => $custom_metrics,
89+
}]
90+
} elsif !$instances{
91+
$_instances = []
92+
} else {
93+
$_instances = $instances
94+
}
95+
7796
file { $dst:
7897
ensure => file,
7998
owner => $datadog_agent::params::dd_user,

templates/agent-conf.d/postgres.yaml.erb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ instances:
1111
# - optional_tag1
1212
# - optional_tag2
1313
#
14-
- host: <%= @host %>
15-
port: <%= @port %>
16-
username: <%= @username %>
17-
password: <%= @password %>
18-
dbname: <%= @dbname %>
19-
<% if @use_psycopg2 == true -%>
14+
<%- (Array(@_instances)).each do |instance| -%>
15+
- host: <%= instance['host'] %>
16+
port: <%= instance['port'] %>
17+
username: <%= instance['username'] %>
18+
password: <%= instance['password'] %>
19+
dbname: <%= instance['dbname'] %>
20+
<% if instance['use_psycopg2'] == true -%>
2021
use_psycopg2: true
2122
<% end -%>
22-
<% if @tags and ! @tags.empty? -%>
23+
<% if instance['tags'] and ! instance['tags'].empty? -%>
2324
tags:
24-
<%- Array(@tags).each do |tag| -%>
25+
<%- Array(instance['tags'] ).each do |tag| -%>
2526
<%- if tag != '' -%>
2627
- <%= tag %>
2728
<%- end -%>
@@ -37,9 +38,9 @@ instances:
3738
# relations:
3839
# - my_table
3940
# - my_other_table
40-
<% if @tables and ! @tables.empty? -%>
41+
<% if instance['tables'] and ! instance['tables'].empty? -%>
4142
relations:
42-
<%- Array(@tables).each do |table| -%>
43+
<%- Array(instance['tables'] ).each do |table| -%>
4344
<%- if table != '' -%>
4445
- <%= table %>
4546
<%- end -%>
@@ -57,9 +58,9 @@ instances:
5758
# - [name, name] # captures the content of the "name" column as a tag for the 2 metrics defined
5859
# - [address, localisation] # captures the content of "address" column as a tag and renames this tag "localisation"
5960
#
60-
<% if @custom_metrics and ! @custom_metrics.empty? -%>
61+
<% if instance['custom_metrics'] and ! instance['custom_metrics'].empty? -%>
6162
custom_metrics:
62-
<%- Array(@custom_metrics).each do |n, custom_metric| -%>
63+
<%- Array(instance['custom_metrics'] ).each do |n, custom_metric| -%>
6364
- query: <%= custom_metric["query"] %>
6465
relation: <%= custom_metric["relation"]? "true" : "false" %>
6566
metrics:
@@ -76,3 +77,4 @@ instances:
7677
<%- end -%>
7778
<%- end -%>
7879
<% end -%>
80+
<% end -%>

0 commit comments

Comments
 (0)