postgres module: connect via uri (#5758)
* add connection via URI support * update config * update readme * change link
Ilya Mashchenko committed
Apr 1, 2019 at 12:25 UTC
53fbf2eb9b13d6f3b31c13a890df85f727c06d23
3 files changed
+13
-3
collectors/python.d.plugin/postgres/README.md
+2
@@ -49,6 +49,8 @@ Following charts are drawn:
49
50
### configuration
51
52
+For all available options please see module [configuration file](postgres.conf).
53
+
54
```yaml
55
socket:
56
name : 'socket'
collectors/python.d.plugin/postgres/postgres.chart.py
+5
@@ -23,6 +23,7 @@ DEFAULT_CONNECT_TIMEOUT = 2 # seconds
23
DEFAULT_STATEMENT_TIMEOUT = 5000 # ms
24
25
26
+CONN_PARAM_DSN = 'dsn'
27
CONN_PARAM_HOST = 'host'
28
CONN_PARAM_PORT = 'port'
29
CONN_PARAM_DATABASE = 'database'
@@ -824,6 +825,10 @@ class Service(SimpleService):
825
def build_conn_params(self):
826
conf = self.configuration
827
828
+ # connection URIs: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
829
+ if conf.get(CONN_PARAM_DSN):
830
+ return {'dsn': conf[CONN_PARAM_DSN]}
831
+
832
params = {
833
CONN_PARAM_HOST: conf.get(CONN_PARAM_HOST),
834
CONN_PARAM_PORT: conf.get(CONN_PARAM_PORT, DEFAULT_PORT),
collectors/python.d.plugin/postgres/postgres.conf
+6
-3
@@ -63,6 +63,10 @@
63
#
64
# Connections can be configured with the following options:
65
#
66
+# dsn : 'connection URI' # see https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
67
+#
68
+# OR
69
+#
70
# database : 'example_db_name'
71
# user : 'example_user'
72
# password : 'example_pass'
@@ -70,14 +74,14 @@
74
# port : 5432
75
# connect_timeout : 2 # in seconds, default is 2
76
# statement_timeout : 2000 # in ms, default is 2000
73
-#
74
-# SSL connection parameters (https://www.postgresql.org/docs/current/libpq-ssl.html)
77
# sslmode : mode # one of [disable, allow, prefer, require, verify-ca, verify-full]
78
# sslrootcert : path/to/rootcert # the location of the root certificate file
79
# sslcrl : path/to/crl # the location of the CRL file
80
# sslcert : path/to/cert # the location of the client certificate file
81
# sslkey : path/to/key # the location of the client key file
82
#
83
+# SSL connection parameters description: https://www.postgresql.org/docs/current/libpq-ssl.html
84
+#
85
# Additionally, the following options allow selective disabling of charts
86
#
87
# table_stats : false
@@ -128,4 +132,3 @@ tcpipv6:
132
user : 'postgres'
133
host : '::1'
134
port : 5432
131
-