跳转至

采集器「腾讯云-PostgreSQL 慢查询日志」配置手册

阅读本文前,请先阅读:

使用本采集器前,必须安装「观测云集成 Core 核心包」及其配套的第三方依赖包

本脚本的代码运行依赖 PostgreSQL 实例对象采集,如果未配置 PostgreSQL 的自定义对象采集,慢日志脚本无法采集到慢日志数据

1. 配置结构

本采集器配置结构如下:

字段 类型 是否必须 说明
regions list 必须 所需采集的地域列表
regions[#] str 必须 地域 ID。如:'ap-nanjing'
总表见附录

2. 配置示例

指定地域

采集南京地域的 PostgreSQL 慢查询日志数据

Python
1
2
3
collector_configs = {
    'regions': ['ap-nanjing'],
}

3. 数据上报格式

数据正常同步后,可以在观测云的「日志」中查看数据。

上报的数据示例如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
  "measurement": "tencentcloud_postgre_slowlog",
  "tags": {
      "AppId"            : "137185",
      "ClientAddr"       : "",
      "DBCharset"        : "UTF8",
      "DBEngine"         : "postgresql",
      "DBEngineConfig"   : "",
      "DBInstanceClass"  : "cdb.pg.ts1.2g",
      "DBInstanceId"     : "postgres-3coh1xgm",
      "DBInstanceName"   : "Unnamed",
      "DBInstanceStatus" : "running",
      "DBInstanceType"   : "primary",
      "DBInstanceVersion": "standard",
      "DBVersion"        : "10.17",
      "DatabaseName"     : "postgres",
      "PayType"          : "postpaid",
      "ProjectId"        : "0",
      "Region"           : "ap-shanghai",
      "RegionId"         : "ap-shanghai",
      "SubnetId"         : "subnet-bp2jqhcj",
      "Type"             : "TS85",
      "Uid"              : "4147",
      "UserName"         : "postgres",
      "VpcId"            : "vpc-kcpy",
      "Zone"             : "ap-shanghai-2",
      "name"             : "postgres-3coh1xgm"
  },
  "fields": {
      "NormalQuery": "select $1 from information_schema.tables where table_schema = $2 and table_name = $3",
      "AvgCostTime": "101.013005",
      "CostTime"   : "101.013025",
      "FirstTime"  : "2021-07-27 03:12:01",
      "LastTime"   : "2021-07-27 03:12:01",
      "MaxCostTime": "101.828125",
      "MinCostTime": "101.828125",
      "message"    : "{慢查询 JSON 数据}"
  }
}

tags、fields 中的字段可能会随后续更新有所变动

tags 值由自定义对象补充

fields.message 为 JSON 序列化后字符串

X. 附录

TencentCloud-PostgreSQL「地域」

请参考 Tencent 官方文档:

TencentCloud-PostgreSQL「慢日志信息说明文档」

请参考 Tencent 官方文档: