PostgreSQL 查询数据

简介

service_pgsql input插件可以采集PostgreSQL 查询数据。

版本

Beta

配置参数

样例

对postgres数据库下的specialalarmtest进行读取。

  • 表结构及数据信息如下

CREATE TABLE IF NOT EXISTS specialalarmtest (
    id BIGSERIAL NOT NULL, 
 time TIMESTAMP NOT NULL, 
 alarmtype varchar(64) NOT NULL, 
 ip varchar(16) NOT NULL, 
 COUNT INT NOT NULL, 
 PRIMARY KEY (id)
);

insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 0);
insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 1);
insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 2);
insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 3);
  • 采集配置

enable: true
inputs:
    - Type: service_pgsql
      Address: 127.0.0.1
      CheckPoint: true
      CheckPointColumn: id
      CheckPointColumnType: int
      CheckPointSavePerPage: true
      CheckPointStart: "0"
      Database: postgres
      IntervalMs: 1000
      Limit: true
      MaxSyncSize: 100
      PageSize: 100
      User: postgres
      Password: xxxxx 
      StateMent: "select * from specialalarmtest where id > $1"
flushers:
  - Type: flusher_stdout
    OnlyStdout: true
  • 输出

{"id":"1","time":"2022-08-25T06:01:07.276901Z","alarmtype":"NO_ALARM","ip":"10.10.***.***","count":"0","__time__":"1661416452"}
{"id":"2","time":"2022-08-25T06:01:07.277624Z","alarmtype":"NO_ALARM","ip":"10.10.***.***","count":"1","__time__":"1661416452"}
{"id":"3","time":"2022-08-25T06:01:07.278072Z","alarmtype":"NO_ALARM","ip":"10.10.***.***","count":"2","__time__":"1661416452"}
{"id":"4","time":"2022-08-25T06:01:07.278494Z","alarmtype":"NO_ALARM","ip":"10.10.***.***","count":"3","__time__":"1661416452"}

Last updated