-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathpostgres.pp
More file actions
154 lines (149 loc) · 5.74 KB
/
postgres.pp
File metadata and controls
154 lines (149 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Class: datadog_agent::integrations::postgres
#
# This class will install the necessary configuration for the postgres integration
#
# Parameters:
# $password
# The password for the datadog user
# $host
# The host postgres is running on
# $dbname
# The postgres database name
# $port
# The postgres port number
# $username
# The username for the datadog user
# $ssl
# Boolean to enable SSL
# $use_psycopg2
# Boolean to flag connecting to postgres with psycopg2 instead of pg8000.
# Warning, psycopg2 doesn't support ssl mode.
# $collect_function_metrics
# Boolean to enable collecting metrics regarding PL/pgSQL functions from pg_stat_user_functions.
# $collect_count_metrics
# Boolean to enable collecting count metrics, default value is True for backward compatibility but they might be slow,
# suggested value is False.
# $collect_activity_metrics
# Boolean to enable collecting metrics regarding transactions from pg_stat_activity, default value is False.
# Please make sure the user has sufficient privileges to read from pg_stat_activity before enabling this option.
# $collect_database_size_metrics
# Boolean to enable collecting database size metrics. Default value is True but they might be slow with large databases
# $collect_default_database
# Boolean to enable collecting statistics from the default database 'postgres' in the check metrics, default to false
# $tags
# Optional array of tags
# $tables
# Track per relation/table metrics. Array of strings.
# Warning: this can collect lots of metrics per relation
# (10 + 10 per index)
# $tags
# Optional array of tags
# $custom_metrics
# A hash of custom metrics with the following keys - query, metrics,
# relation, descriptors. Refer to this guide for details on those fields:
# https://help.datadoghq.com/hc/en-us/articles/208385813-Postgres-custom-metric-collection-explained
#
# Sample Usage:
#
# class { 'datadog_agent::integrations::postgres' :
# host => 'localhost',
# dbname => 'postgres'
# username => 'datadog',
# password => 'some_pass',
# ssl => false,
# custom_metrics => {
# a_custom_query => {
# query => "select tag_column, %s from table",
# relation => false,
# metrics => {
# value_column => ["value_column.datadog.tag", "GAUGE"]
# },
# descriptors => [
# ["tag_column", "tag_column.datadog.tag"]
# ]
# }
# }
# }
#
# Hiera Usage:
#
# datadog_agent::integrations::postgres::instances:
# - host: 'localhost'
# dbname: 'postgres'
# username: 'datadog'
# password: 'some_pass'
# ssl: false
# custom_metrics:
# a_custom_query:
# query: 'select tag_column, %s from table'
# relation: false
# metrics:
# value_column: ["value_column.datadog.tag", "GAUGE"]
# descriptors:
# - ["tag_column", "tag_column.datadog.tag"]
#
class datadog_agent::integrations::postgres(
Optional[String] $password = undef,
String $host = 'localhost',
String $dbname = 'postgres',
Variant[String, Integer] $port = '5432',
String $username = 'datadog',
Boolean $ssl = false,
Boolean $use_psycopg2 = false,
Boolean $collect_function_metrics = false,
Boolean $collect_count_metrics = false,
Boolean $collect_activity_metrics = false,
Boolean $collect_database_size_metrics = false,
Boolean $collect_default_database = false,
Array[String] $tags = [],
Array[String] $tables = [],
Hash $custom_metrics = {},
Optional[Array] $instances = undef,
) inherits datadog_agent::params {
include datadog_agent
validate_legacy('Array[String]', 'validate_array', $tags)
validate_legacy('Array[String]', 'validate_array', $tables)
validate_legacy('Boolean', 'validate_bool', $use_psycopg2)
$legacy_dst = "${datadog_agent::conf_dir}/postgres.yaml"
if !$::datadog_agent::agent5_enable {
$dst = "${datadog_agent::conf6_dir}/postgres.d/conf.yaml"
file { $legacy_dst:
ensure => 'absent'
}
} else {
$dst = $legacy_dst
}
if !$instances and $host {
$_instances = [{
'host' => $host,
'password' => $password,
'dbname' => $dbname,
'port' => $port,
'username' => $username,
'ssl' => $ssl,
'use_psycopg2' => $use_psycopg2,
'tags' => $tags,
'tables' => $tables,
'custom_metrics' => $custom_metrics,
'collect_function_metrics' => $collect_function_metrics,
'collect_count_metrics' => $collect_count_metrics,
'collect_activity_metrics' => $collect_activity_metrics,
'collect_database_size_metrics' => $collect_database_size_metrics,
'collect_default_database' => $collect_default_database,
}]
} elsif !$instances{
$_instances = []
} else {
$_instances = $instances
}
file { $dst:
ensure => file,
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0600',
content => template('datadog_agent/agent-conf.d/postgres.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name],
}
create_resources('datadog_agent::integrations::postgres_custom_metric', $custom_metrics)
}