2

背景

我正在尝试通过在 stackdriver-agents collectd 配置目录中<Query> 向我的 PostgreSQL 配置(来自Stackdriver PostgreSQL Plugin的原始配置)添加自定义语句来导出 PostgreSQL 复制延迟。

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

到这个时候,在查看“Instance (GCE)”资源的指标时,我希望看到我的“log_delay”指标显示在 Stackdriver 监控中。我可以看到其他 PostgreSQL 指标已经通过,更具体地说:

PostgeSQL 指标

我似乎也找不到从Stackdriver PostgreSQL Plugin Documentation 引用的默认 PostgreSQL collectd 配置Query [...]继承的任何其他默认指标:

# [...]
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. 如何让我收集的自定义 replication_lag_seconds 指标显示在 Stackdriver Monitoring 中?
  2. 我是否需要配置自定义指标才能让指标显示在 Stackdriver Monitoring 中?
4

1 回答 1

1

Stackdriver 监控代理会为每个受支持的第三方应用发送一组精选指标。用户无法扩展该集合——任何不是精选指标的内容都将被 API 忽略,并且必须通过自定义指标机制发送。

于 2017-05-25T14:32:57.583 回答