Export custom collectd PostgreSQL metrics to GCP Stackdriver Monitoring

江枫思渺然 提交于 2021-01-27 17:48:44

问题


Background

I'm trying to export PostgreSQL replication delay by adding a custom <Query> statement to my PostgreSQL config (original config from Stackdriver PostgreSQL Plugin) in stackdriver-agents collectd configuration directory.

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

The stackdriver-agent logs confirm that the plugin is loaded and that the plugin is able to connect to the PostgreSQL server.

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)

By this time, I would expect to see my "log_delay" metric to show up in Stackdriver monitoring when looking at metrics for the "Instance (GCE)" resource. I can see that other PostgreSQL metrics have made it through, more specifically:

I also can't seem to find any of the other default Query [...] metrics inherited from the default PostgreSQL collectd configuration referenced by 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. How do I get my collecd custom replication_lag_seconds metric to show up in Stackdriver Monitoring?
  2. Do I need to configure Custom Metrics in order to get the metrics to show up in Stackdriver Monitoring?

回答1:


The Stackdriver monitoring agent sends a set of curated metrics for each supported third-party application. That set cannot be extended by users -- anything that isn't a curated metric will be ignored by the API and must be sent via the custom metrics mechanism.



来源:https://stackoverflow.com/questions/44150437/export-custom-collectd-postgresql-metrics-to-gcp-stackdriver-monitoring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!