Skip to content

Commit

Permalink
add service_registry options (none|consul|etcd|both)
Browse files Browse the repository at this point in the history
* also add node_exporter_enabled, pg_exporter_enabled,
  pgbouncer_exporter_enabled options
  • Loading branch information
Vonng committed Feb 18, 2021
1 parent 162bb69 commit 73af7ea
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 63 deletions.
22 changes: 16 additions & 6 deletions pigsty.yml
Expand Up @@ -441,6 +441,7 @@ all: # top-level namespace, match all hosts
#------------------------------------------------------------------------------
# DCS PROVISION
#------------------------------------------------------------------------------
service_registry: consul # none | consul | etcd | both
dcs_type: consul # consul | etcd | both
dcs_name: pigsty # consul dc name | etcd initial cluster token
# dcs server dict in name:ip format
Expand Down Expand Up @@ -529,8 +530,8 @@ all: # top-level namespace, match all hosts
pg_conf: tiny.yml # user provided patroni config template path

# - pgbouncer - #
pgbouncer_port: 6432 # default pgbouncer port
pgbouncer_poolmode: transaction # default pooling mode: transaction pooling
pgbouncer_port: 6432 # pgbouncer port (6432 by default)
pgbouncer_poolmode: transaction # pooling mode: (transaction pooling by default)
pgbouncer_max_db_conn: 100 # important! do not set this larger than postgres max conn or conn limit


Expand Down Expand Up @@ -695,13 +696,22 @@ all: # top-level namespace, match all hosts
#------------------------------------------------------------------------------
# MONITOR PROVISION
#------------------------------------------------------------------------------
# - monitor options -
pg_exporter_config: pg_exporter-demo.yaml # default config files for pg_exporter
# - common - #
exporter_metrics_path: /metrics # default metric path for pg related exporter
exporter_binary_install: false # install exporter via copy local binary (from files/{pg,node}_exporter)

# - node exporter - #
node_exporter_enabled: true # setup node_exporter on instance
node_exporter_port: 9100 # default port for node exporter

# - pg/pgb exporter - #
pg_exporter_config: pg_exporter-demo.yaml # default config files for pg_exporter
pg_exporter_enabled: true # setup pg_exporter on instance
pgbouncer_exporter_enabled: true # setup pgbouncer_exporter on instance
pg_exporter_port: 9630 # default port for pg exporter
pgbouncer_exporter_port: 9631 # default port for pgbouncer exporter
exporter_metrics_path: /metrics # default metric path for pg related exporter
pg_localhost: /var/run/postgresql # localhost unix socket path
pg_localhost: /var/run/postgresql # localhost unix socket dir for connection



#------------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions roles/consul/defaults/main.yml
Expand Up @@ -7,4 +7,7 @@ dcs_disable_purge: false # set to true to disable purge functionality f

consul_data_dir: /var/lib/consul # default data directory
consul_exists: false # default value for inner variable (DO NOT CHANGE!)

# where or whether to register services definition
service_registry: consul # none | consul | etcd | both
...
3 changes: 3 additions & 0 deletions roles/grafana/defaults/main.yml
Expand Up @@ -30,4 +30,7 @@ grafana_plugins: # default grafana plugins list
grafana_git_plugins:
- https://github.com/Vonng/grafana-echarts


# - reference - #
service_registry: consul # none | consul | etcd | both
...
2 changes: 1 addition & 1 deletion roles/grafana/tasks/main.yml
Expand Up @@ -142,12 +142,12 @@
#--------------------------------------------------------------#
- name: Register Grafana Service
tags: grafana_register
when: service_registry == 'consul'
block:
- name: Register consul grafana service
template: src=svc-grafana.json.j2 dest=/etc/consul.d/svc-grafana.json owner=consul group=admin mode=0660

- name: Reload consul
systemd: name=consul state=reloaded enabled=yes daemon_reload=yes


...
1 change: 1 addition & 0 deletions roles/haproxy/defaults/main.yml
Expand Up @@ -17,5 +17,6 @@ haproxy_weight_fallback: 1 # assign a small weight for primar
# (in case of singleton replica failure, primary can still take read-only )

# - reference - #
service_registry: consul # none | consul | etcd | both
exporter_metrics_path: /metrics # url path to expose metrics
...
10 changes: 6 additions & 4 deletions roles/haproxy/tasks/main.yml
Expand Up @@ -4,6 +4,7 @@
#--------------------------------------------------------------#
- name: Haproxy installation
tags: haproxy_install
when: haproxy_enabled
block:
- name: Make sure haproxy is installed
package: name=haproxy state=present
Expand All @@ -16,13 +17,12 @@
copy: src=haproxy.service dest=/usr/lib/systemd/system/haproxy.service



#--------------------------------------------------------------#
# render haproxy configuration
#--------------------------------------------------------------#
- name: Setup Haproxy
tags: haproxy_config
when: haproxy_enabled|bool
when: haproxy_enabled
block:
- name: Fetch postgres cluster memberships
connection: local
Expand All @@ -41,7 +41,7 @@
#--------------------------------------------------------------#
- name: Restart Haproxy
tags: haproxy_launch
when: haproxy_enabled|bool
when: haproxy_enabled
block:
- name: Launch haproxy load balancer service
tags: haproxy_restart
Expand All @@ -59,7 +59,7 @@
#--------------------------------------------------------------#
- name: Reload Haproxy
tags: haproxy_reload
when: haproxy_enabled|bool
when: haproxy_enabled
block:
- name: Reload haproxy load balancer service
ignore_errors: true
Expand All @@ -75,8 +75,10 @@
#--------------------------------------------------------------#
- name: Register haproxy consul service
tags: haproxy_register
when: haproxy_enabled and service_registry == 'consul'
ignore_errors: true
block:

- name: Copy haproxy service definition
template:
src: svc-{{ item }}.json.j2
Expand Down
38 changes: 28 additions & 10 deletions roles/monitor/README.md
Expand Up @@ -19,14 +19,32 @@ tasks:
[defaults/main.yml](defaults/main.yml)

```yaml
# default user/pass/db to monitor
pg_monitor_username: 'dbuser_monitor'
pg_monitor_password: 'dbuser_monitor'
default_database: 'postgres'

# default exporter settings
exporter_metric_path: "/metrics"
node_exporter_port: 9100
pg_exporter_port: 9630
pgbouncer_exporter_port: 9631
---
#------------------------------------------------------------------------------
# MONITOR PROVISION
#------------------------------------------------------------------------------
# - common - #
exporter_metrics_path: /metrics # default metric path for pg related exporter
exporter_binary_install: false # install exporter via copy local binary (from files/{pg,node}_exporter)

# - node exporter - #
node_exporter_enabled: true # setup node_exporter on instance
node_exporter_port: 9100 # default port for node exporter

# - pg/pgb exporter - #
pg_exporter_config: pg_exporter-demo.yaml # default config files for pg_exporter
pg_exporter_enabled: true # setup pg_exporter on instance
pgbouncer_exporter_enabled: true # setup pgbouncer_exporter on instance
pg_exporter_port: 9630 # default port for pg exporter
pgbouncer_exporter_port: 9631 # default port for pgbouncer exporter

# - postgres variables reference - #
pg_port: 5432 # postgres port (5432 by default)
pgbouncer_port: 6432 # pgbouncer port (6432 by default)
pg_localhost: /var/run/postgresql # localhost unix socket dir for connection
pg_default_database: postgres # default database will be used as primary monitor target
pg_monitor_username: dbuser_monitor # system monitor username, for postgres and pgbouncer
pg_monitor_password: DBUser.Monitor # system monitor user's password
service_registry: consul # none | consul | etcd | both
...
```
36 changes: 24 additions & 12 deletions roles/monitor/defaults/main.yml
@@ -1,16 +1,28 @@
---
# - postgres monitor settings - #
exporter_metric_path: /metrics
node_exporter_port: 9100
pg_exporter_port: 9630
pg_exporter_config: pg_exporter.yaml
pgbouncer_exporter_port: 9631
pg_localhost: /var/run/postgresql
#------------------------------------------------------------------------------
# MONITOR PROVISION
#------------------------------------------------------------------------------
# - common - #
exporter_metrics_path: /metrics # default metric path for pg related exporter
exporter_binary_install: false # install exporter via copy local binary (from files/{pg,node}_exporter)

# - node exporter - #
node_exporter_enabled: true # setup node_exporter on instance
node_exporter_port: 9100 # default port for node exporter

# - pg/pgb exporter - #
pg_exporter_config: pg_exporter-demo.yaml # default config files for pg_exporter
pg_exporter_enabled: true # setup pg_exporter on instance
pgbouncer_exporter_enabled: true # setup pgbouncer_exporter on instance
pg_exporter_port: 9630 # default port for pg exporter
pgbouncer_exporter_port: 9631 # default port for pgbouncer exporter

# - postgres variables reference - #
pg_port: 5432
pgbouncer_port: 6432
pg_default_database: postgres
pg_monitor_username: dbuser_monitor
pg_monitor_password: DBUser.Monitor
pg_port: 5432 # postgres port (5432 by default)
pgbouncer_port: 6432 # pgbouncer port (6432 by default)
pg_localhost: /var/run/postgresql # localhost unix socket dir for connection
pg_default_database: postgres # default database will be used as primary monitor target
pg_monitor_username: dbuser_monitor # system monitor username, for postgres and pgbouncer
pg_monitor_password: DBUser.Monitor # system monitor user's password
service_registry: consul # none | consul | etcd | both
...
4 changes: 3 additions & 1 deletion roles/monitor/tasks/main.yml
Expand Up @@ -3,18 +3,20 @@
# Setup pg_exporter
#==============================================================#
- import_tasks: pg_exporter.yml
when: pg_exporter_enabled


#==============================================================#
# Setup pgbouncer_exporter
#==============================================================#
- import_tasks: pgbouncer_exporter.yml
when: pgbouncer_exporter_enabled


#==============================================================#
# Setup node_exporter
#==============================================================#
- import_tasks: node_exporter.yml

when: node_exporter_enabled

...
15 changes: 12 additions & 3 deletions roles/monitor/tasks/node_exporter.yml
@@ -1,7 +1,7 @@
---
#==============================================================#
#------------------------------------------------------------------------------
# Setup node_exporter
#==============================================================#
#------------------------------------------------------------------------------
- name: Setup node_exporter
tags: node_exporter
block:
Expand All @@ -17,7 +17,16 @@
- name: Wait for node_exporter online
wait_for: host=localhost port={{ node_exporter_port }} state=started timeout=10

- name: Register node-exporter service

#------------------------------------------------------------------------------
# Register node_exporter
#------------------------------------------------------------------------------
# currently only consul registry is implemented
- name: Register node_exporter
tags: node_exporter_register
when: service_registry == 'consul'
block:
- name: Register node-exporter service to consul
template:
src: svc-node-exporter.json.j2
dest: /etc/consul.d/svc-node-exporter.json
Expand Down
13 changes: 11 additions & 2 deletions roles/monitor/tasks/pg_exporter.yml
@@ -1,7 +1,7 @@
---
#==============================================================#
#------------------------------------------------------------------------------
# Setup pg_exporter
#==============================================================#
#------------------------------------------------------------------------------
- name: Setup pg_exporter
tags: pg_exporter
block:
Expand All @@ -24,6 +24,15 @@
ignore_errors: true
wait_for: host=localhost port={{ pg_exporter_port }} state=started timeout=10


#------------------------------------------------------------------------------
# Register pg_exporter
#------------------------------------------------------------------------------
- name: Setup pg_exporter
tags: pg_exporter_register
when: service_registry == 'consul'
block:

- name: Register pg-exporter consul service
template:
src: svc-pg-exporter.json.j2
Expand Down
13 changes: 11 additions & 2 deletions roles/monitor/tasks/pgbouncer_exporter.yml
@@ -1,7 +1,7 @@
---
#==============================================================#
#------------------------------------------------------------------------------
# Setup pgbouncer_exporter
#==============================================================#
#------------------------------------------------------------------------------
- name: Setup pgbouncer_exporter
tags: pgbouncer_exporter
block:
Expand All @@ -18,6 +18,15 @@
ignore_errors: true
wait_for: host=localhost port={{ pgbouncer_exporter_port }} state=started timeout=10


#------------------------------------------------------------------------------
# Register pgbouncer_exporter
#------------------------------------------------------------------------------
# currently only consul registry is implemented
- name: Setup pgbouncer_exporter
tags: node_exporter_register
when: service_registry == 'consul'
block:
- name: Register pgb-exporter consul service
template:
src: svc-pgbouncer-exporter.json.j2
Expand Down
3 changes: 3 additions & 0 deletions roles/nameserver/defaults/main.yml
Expand Up @@ -4,4 +4,7 @@
#------------------------------------------------------------------------------
dns_records:
- 10.10.10.10 pigsty y.pigsty yum.pigsty

# - reference - #
service_registry: consul # none | consul | etcd | both
...
23 changes: 15 additions & 8 deletions roles/nameserver/tasks/main.yml
Expand Up @@ -28,13 +28,20 @@
wait_for: host=localhost port=53 state=started


# optional (register consul service)
# # - register - #
# - name: Register consul dnsmasq service
# template: src=svc-dnsmasq.json.j2 dest=/etc/consul.d/svc-dnsmasq.json owner=consul group=admin mode=0660

# # - reload - #
# - name: Reload consul
# systemd: name=consul state=reloaded enabled=yes daemon_reload=yes
#------------------------------------------------------------------------------
# Register Dnsmasq Service
#------------------------------------------------------------------------------
- name: Register dnsmasq service
tags: nameserver
when: service_registry == 'consul'
ignore_errors: true
block:
# - register - #
- name: Register consul dnsmasq service
template: src=svc-dnsmasq.json.j2 dest=/etc/consul.d/svc-dnsmasq.json owner=consul mode=0660

# - reload - #
- name: Reload consul
systemd: name=consul state=reloaded enabled=yes daemon_reload=yes

...
6 changes: 2 additions & 4 deletions roles/nginx/defaults/main.yml
Expand Up @@ -12,8 +12,6 @@ repo_home: /www # default repo dir location
repo_address: yum.pigsty # local repo host (ip or hostname, including port if not using 80)
repo_port: 80 # repo server listen address, must same as repo_address!

# - reference : dcs metadata - #
dcs_type: consul # default dcs server type: consul
consul_check_interval: 15s # default service check interval
consul_check_timeout: 1s # default service check timeout
# - reference - #
service_registry: consul # none | consul | etcd | both
...
5 changes: 3 additions & 2 deletions roles/nginx/tasks/main.yml
Expand Up @@ -101,13 +101,14 @@
#------------------------------------------------------------------------------
- name: Register nginx exporter
tags: nginx_register
when: service_registry == 'consul'
ignore_errors: true
block:
- name: Register cosnul nginx service
template: src=svc-nginx.json.j2 dest=/etc/consul.d/svc-nginx.json owner=consul group=admin mode=0660
template: src=svc-nginx.json.j2 dest=/etc/consul.d/svc-nginx.json owner=consul mode=0660

- name: Register consul nginx-exporter service
template: src=svc-nginx-exporter.json.j2 dest=/etc/consul.d/svc-nginx-exporter.json owner=consul group=admin mode=0660
template: src=svc-nginx-exporter.json.j2 dest=/etc/consul.d/svc-nginx-exporter.json owner=consul mode=0660

- name: Reload consul
systemd: name=consul state=reloaded enabled=yes daemon_reload=yes
Expand Down

0 comments on commit 73af7ea

Please sign in to comment.