将自定义收集的PostgreSQL指标导出到GCP Stackdriver Monitoring

时间:2017-05-24 06:22:58

标签: stackdriver collectd google-cloud-stackdriver

背景

我试图通过添加自定义<Query>来导出PostgreSQL复制延迟 我的PostgreSQL配置语句(来自Stackdriver PostgreSQL Plugin的原始配置)in stackdriver-agents收集配置 。目录

/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-agent日志确认插件已加载且插件已加载 能够连接到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)

此时,我希望看到我的&#34; log_delay&#34;出现的指标 查看&#34;实例(GCE)&#34;的指标时的堆栈驱动程序监控 资源。我可以看到其他PostgreSQL指标已经完成,更多 具体是:

PostgeSQL Metrics

我似乎也无法找到任何其他默认Query [...]指标 继承自default PostgreSQL collectd configurationStackdriver 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中显示的指标?

1 个答案:

答案 0 :(得分:1)

Stackdriver监视代理程序为每个set of curated metrics发送supported third-party application。该集合无法由用户扩展 - 任何不是精选指标的内容都将被API忽略,并且必须通过custom metrics机制发送。

相关问题