夜莺-Nightingale
采集器-Categraf
夜莺V6
项目介绍
架构介绍
快速开始
黄埔营
安装部署
升级
采集器
使用手册
API
数据库表结构
alert_aggr_view
alert_cur_event
alert_his_event
alert_mute
alert_rule
alert_subscribe
alerting_engines
board
board_payload
builtin_cate
busi_group
busi_group_member
chart_share
configs
datasource
metric_view
notify_tpl
recording_rule
role
role_operation
sso_config
target
task_record
task_tpl
task_tpl_host
user_group
user_group_member
users
FAQ
夜莺V5
夜莺专业版
企业版-Flashcat
智能告警插件
开源生态
Telegraf
Prometheus
版权声明
第1章:天降奇兵
第2章:探索PromQL
开篇
理解时间序列
Metrics类型
初识PromQL
PromQL操作符
PromQL聚合操作
PromQL内置函数
在HTTP API中使用PromQL
最佳实践:4个黄金指标和USE方法
小结
第3章:Prometheus告警处理
开篇
Prometheus告警简介
自定义Prometheus告警规则
部署Alertmanager
Alertmanager配置概述
基于标签的告警处理路由
使用Receiver接收告警信息
告警模板详解
屏蔽告警通知
使用Recoding Rules优化性能
小结
第4章:Exporter详解
第5章:数据与可视化
第6章:集群与高可用
第7章:Prometheus服务发现
第8章:监控Kubernetes
开篇
初识Kubernetes
在Kubernetes下部署Prometheus
Kubernetes下的服务发现
使用Prometheus监控Kubernetes集群
基于Prometheus的弹性伸缩
小结
第9章:Prometheus Operator
参考资料
postgresql插件
postgresql采集插件
postgresql 监控采集插件,核心原理就是连到 postgres 实例,执行一些查询,解析输出内容,整理为监控数据上报。
创建只读用户
> create user categraf with password 'categraf';
> alter user categraf set default_transaction_read_only=on;
> grant usage on schema public to categraf;
> grant select on all tables in schema public to categraf ;
配置
配置文件
路径 conf/input.postgresql/postgresql.toml
配置项说明
[[instances]]
# 配置dsn
# 额外要附件的标签
labels = { region="xxxx", zone="xxx" }
## dsn, postgresql 的连接信息
address = "host=1.2.3.4 port=5432 user=postgres password=123456 sslmode=disable"
## outputaddress 相当于是addres的别名
outputaddress = "db01"
## 一条连接保持活跃的最大时长, 0s表示永远
## 当查询执行时,到达最大时长的连接不会被立即强制断开
max_lifetime = "0s"
## 忽略哪些db的采集
ignored_databases = ["postgres", "template0", "template1"]
## 显式指定采集哪些db
databases = ["app_production", "testing"]
## Whether to use prepared statements when connecting to the database.
## This should be set to false when connecting through a PgBouncer instance
## with pool_mode set to transaction.
## 是否使用prepared statements 连接数据库
prepared_statements = true
[[instances.metrics]]
mesurement = "sessions"
#label_fields = [ "status", "type" ]
metric_fields = [ "active" ]
timeout = "3s"
request = '''
select count(*) as active from pg_stat_activity;
'''
配置项基本都在注释中了, 解释一下最后的metrics生成规则。
命令与输出
# select count(*) as active from pg_stat_activity;
active
--------
6
(1 row)
select count(*) as active from pg_stat_activity;
这条语句会查询当前活跃的session数量 这条语句会查询当前活跃的session数量mesurement = "sessions"
定义指标前缀为sessionsmetrics_fields = [ "active" ]
定义列名active作为指标名,附加在mesurement
后面label_fields = [ "status", "type" ]
定义列status和列type作为标签, 这个例子中注释了,所以不附加到指标上 最终生成的指标为postgresql_sessions_active{server="db01",region="xxx",zone="xxx"} 6