Class: ActivePostgres::Components::Monitoring

Inherits:
Base
  • Object
show all
Defined in:
lib/active_postgres/components/monitoring.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #secrets, #ssh_executor

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ActivePostgres::Components::Base

Instance Method Details

#installObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/active_postgres/components/monitoring.rb', line 6

def install
  puts 'Installing postgres_exporter for monitoring...'

  ensure_monitoring_user

  config.all_hosts.each do |host|
    install_on_host(host)
  end

  install_grafana_if_enabled
end

#install_on_standby(standby_host) ⇒ Object



49
50
51
52
# File 'lib/active_postgres/components/monitoring.rb', line 49

def install_on_standby(standby_host)
  puts "Installing postgres_exporter on standby #{standby_host}..."
  install_on_host(standby_host)
end

#restartObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/active_postgres/components/monitoring.rb', line 38

def restart
  puts 'Restarting postgres_exporter...'

  config.all_hosts.each do |host|
    ssh_executor.execute_on_host(host) do
      execute :sudo, 'systemctl', 'restart', 'prometheus-postgres-exporter'
      execute :sudo, 'systemctl', 'restart', 'prometheus-node-exporter' if node_exporter_enabled?
    end
  end
end

#uninstallObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_postgres/components/monitoring.rb', line 18

def uninstall
  puts 'Uninstalling postgres_exporter...'

  config.all_hosts.each do |host|
    ssh_executor.execute_on_host(host) do
      execute :sudo, 'systemctl', 'stop', 'prometheus-postgres-exporter'
      execute :sudo, 'systemctl', 'disable', 'prometheus-postgres-exporter'
      execute :sudo, 'apt-get', 'remove', '-y', 'prometheus-postgres-exporter'

      if node_exporter_enabled?
        execute :sudo, 'systemctl', 'stop', 'prometheus-node-exporter'
        execute :sudo, 'systemctl', 'disable', 'prometheus-node-exporter'
        execute :sudo, 'apt-get', 'remove', '-y', 'prometheus-node-exporter'
      end
    end
  end

  uninstall_grafana_if_enabled
end