2017-05-24 35 views
1

背景

我試圖通過 爲Stackdriver代理添加自定義<Query> 聲明,我的PostgreSQL的配置(從Stackdriver PostgreSQL Plugin原配置)出口PostgreSQL的複製延遲collectd配置 目錄。導出自collectd PostgreSQL的指標來GCP爲Stackdriver監測

/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> 

的爲Stackdriver代理日誌確認插件加載和插件 能夠連接到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) 

到了這個時候,我希望看到我的「log_delay」指標看指標「實例(GCE)」 資源時,在 爲Stackdriver監測顯示出來。我可以看到其他的PostgreSQL指標取得了事情的經過,更 具體爲:

PostgeSQL Metrics

也似乎我無法找到任何其他默認的Query [...]指標 從default PostgreSQL collectd configuration 通過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> 

問題

  1. 如何讓我的collecd自定義replication_lag_seconds指標顯示在Stackdriver Monitoring中?
  2. 我是否需要配置Custom Metrics才能獲得 指標顯示在Stackdriver Monitoring中?

回答

相關問題