2017-05-24 7 views
1

Contexte

Je suis en train d'exporter retard de réplication PostgreSQL en ajoutant une déclaration personnalisée <Query> ma config PostgreSQL (config d'origine de Stackdriver PostgreSQL Plugin) dans agents Stackdriver-collectd configuration répertoire.Export métriques de PostgreSQL collectd personnalisé à GCP Stackdriver surveillance

/opt/stackdriver/collectd/etc/postgresql.conf:

# This is the monitoring configuration for PostgreSQL. 
# Make sure the statistics collector is enabled in your PostgreSQL configuration. 
# NOTE: This configuration needs to be hand-edited in order to work. 
# Look for DATABASE_NAME, STATS_USER, STATS_PASS, POSTGRESQL_HOST and POSTGRESQL_PORT to adjust your configuration file. 
LoadPlugin postgresql 
<Plugin "postgresql"> 

    <Query replication_lag_seconds> 
     Statement "SELECT (CASE WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0 ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp()) END) AS log_delay" 
     <Result> 
      Type "gauge" 
      ValuesFrom "log_delay" 
     </Result> 
    </Query> 

    # Each database needs a separate Database section. 
    # Replace DATABASE_NAME in the Database section with the name of the database. 
    <Database "THE_DATABASE"> 
     # Host and port are only used for TCP/IP connections. 
     # Leaving them out indicates you wish to connect via domain sockets. 
     # When using non-standard PostgreSQL configurations, replace the below with 
     Host "localhost" 
     Port "5432" 
     User "THE_USER" 
     Password "hunter2" 
     Query backends 
     Query transactions 
     Query queries 
     Query table_states 
     Query disk_io 
     Query disk_usage 
     Query replication_lag_seconds # My custom query 
    </Database> 
</Plugin> 

Les journaux Stackdriver-agent confirment que le plug-in est chargé et que le plug-in est capable de se connecter au serveur PostgreSQL.

collectd[30418]: plugin_load: plugin "postgresql" successfully loaded. 
collectd[13849]: Successfully connected to database THE_DATABASE (user THE_USER) at server localhost:5432 (server version: 9.4.12, protocol version: 3, pid: 13862) 

En ce moment, je me attends à voir mon « log_delay » métrique pour apparaître dans surveillance Stackdriver quand on regarde les mesures pour la « instance (GCE) » des ressources . Je peux voir que d'autres mesures de PostgreSQL ont fait à travers, plus spécifiquement:

PostgeSQL Metrics

Je semble peut aussi ne pas trouver un quelconque des autres par défaut Query [...] métriques héritées du default PostgreSQL collectd configuration référencé par Stackdriver PostgreSQL Plugin Documentation:

# [...] 
LoadPlugin postgresql 
<Plugin "postgresql"> 
    # [...] 
    <Database "DATABASE_NAME"> 
     # [...] 
     User "STATS_USER" 
     Password "STATS_PASS" 
     Query backends 
     Query transactions 
     Query queries 
     Query table_states 
     Query disk_io 
     Query disk_usage 
    </Database> 
</Plugin> 

question

  1. Comment puis-je obtenir la métrique replication_lag_seconds de collecd personnalisée dans Stackdriver Monitoring?
  2. Ai-je besoin de configurer Custom Metrics afin d'obtenir les mesures à apparaître dans la surveillance Stackdriver?

Répondre