数据洞察 视图 视图模板 自建PostgreSQL 监控视图
自建PostgreSQL 监控视图
简介
展示 自建PostgreSQL 的系统监控指标和数据库监控指标
前提条件
- 已安装 PostgreSQL 9.4 及以上版本
- 需安装 DataKit,并开启以下指标采集:
cpu mem net kernel kernel_vmstat disk swap processes postgresql
配置
1.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 cpu
文件夹,打开里面的 cpu.conf
。
[[inputs.cpu]]
# ## Whether to report per-cpu stats or not
percpu = true
## Whether to report total system cpu stats or not
totalcpu = true
# ## If true, collect raw CPU time metrics.
# collect_cpu_time = false
## If true, compute and report the sum of all non-idle CPU states.
report_active = false
2.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 memory
文件夹,打开里面的 memory.conf
。
# Read metrics about memory usage
[[inputs.mem]]
#no configuration
3.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 network
文件夹,打开里面的 network.conf
。
# # Read metrics about network interface usage
[[inputs.net]]
# ## By default, telegraf gathers stats from any up interface (excluding loopback)
# ## Setting interfaces will tell it to gather these explicit interfaces,
# ## regardless of status.
# ##
# # interfaces = ["eth0"]
# ##
# ## On linux systems telegraf also collects protocol stats.
# ## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
# ##
# # ignore_protocol_stats = false
# ##
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到kernel
文件夹,打开里面的kernel.conf
。
# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# no configuration
# # Get kernel statistics from /proc/vmstat
[[inputs.kernel_vmstat]]
# # no configuration
5.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 disk
文件夹,打开里面的 disk.conf
。
# Read metrics about disk usage by mount point
[[inputs.disk]]
## By default stats will be gathered for all mount points.
## Set mount_points will restrict the stats to only the specified mount points.
# mount_points = ["/"]
## Ignore mount points by filesystem type.
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
6.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 swap
文件夹,打开里面的 swap.conf
。
# Read metrics about swap memory usage
[[inputs.swap]]
# no configuration
7.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 processes
文件夹,打开里面的 processes.conf
[[inputs.procstat]]
pid_file = "/alidata/mysql/data/MySQL-01.pid"
8.打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d
文件夹),找到 postgresql
文件夹,打开里面的 postgresql.conf
[[inputs.postgresql]]
address = "host=xxx user=xxx port=xxx password=xxx sslmode=disable dbname=xxx"
interval = "300s"
[inputs.postgresql.tags]
instance_name='xxx'
project='xxx'
配置好后,重启 DataKit 即可生效。
下面的shell 脚本可以将上述的所有配置文件自动开启,属于覆盖原油配置的方式,如果您需要快速打开配置可以使用。
# auto_configure_datakit_for_mysql
cd /usr/local/cloudcare/forethought/datakit/conf.d
cat > cpu/cpu.conf << ENDF1
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
ENDF1
cat > memory/memory.conf << ENDF2
[[inputs.mem]]
ENDF2
cat > network/network.conf << ENDF3
[[inputs.net]]
ENDF3
cat > kernel/kernel.conf << ENDF4
[[inputs.kernel]]
[[inputs.kernel_vmstat]]
ENDF4
cat > disk/disk.conf << ENDF5
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs"]
ENDF5
cat > swap/swap.conf << ENDF6
[[inputs.swap]]
ENDF6
mysql_pid=`ps -ef| grep mysql[d] | sed 's/.*pid-file=\(.*\)\.pid.*/\1.pid/' | tail -n 1`
cat > processes/processes.conf << ENDF7
[[inputs.procstat]]
pid_file = "$mysql_pid"
ENDF7
cat > postgresql.conf << ENDF8
[[inputs.postgresql]]
address = "host=xxx user=xxx port=xxx password=xxx sslmode=disable dbname=xxx"
interval = "300s"
[inputs.postgresql.tags]
instance_name='xxx'
project='xxx'
ENDF8
概览
指标
小类 | field | type | 单位 | Alias |
---|---|---|---|---|
缓冲耗时 | blk_read_time | float | 毫秒 | 数据库中花费在读取文件的时间,这个值很高说明内存较小,需要频繁从磁盘读入数据文件 |
缓冲耗时 | blk_write_time | float | 毫秒 | 数据库中花费在写数据文件的时间,pg中脏页一般写入page cache,如果这个值较高,则说明cache较小,操作系统的cache需要更积极的写入 |
缓冲 | blks_hit | int | 从shared buffer命中块数 | |
缓冲 | blks_read | int | 总磁盘物理读的块数,这里的read可能是从 cache中读取,如果很高需要结合blk_read_time看是否真的存在从磁盘读取的情况 | |
缓冲区 | buffers_alloc | int | 已分配的缓冲区数量 | |
缓冲区 | buffers_backend | int | 表示后端必须自身,而不是后台写入进程或检查点写的缓冲区数量 | |
缓冲区 | buffers_backend_fsync | int | 后端必须执行自身的fsync调用的次数 | |
缓冲区 | buffers_checkpoint | int | 检查点写入磁盘的缓冲区总数 | |
缓冲区 | buffers_clean | int | 后台进程写入磁盘的缓冲区数 | |
检查点 | checkpoint_sync_time | float | 毫秒 | 检查点进程同步磁盘花费的总时间 |
检查点 | checkpoint_write_time | float | 毫秒 | 检查点进程写入磁盘花费的总时间 |
检查点 | checkpoints_req | int | 请求的检查点数 | |
检查点 | checkpoints_timed | int | 已发生的计划检查点数 | |
基础信息 | datid | int | 数据库的oid | |
基础信息 | datname | string | 数据库名 | |
基础信息 | numbackends | int | 访问当前数据库的连接数量 | |
基础信息 | maxwritten_clean | int | 后台写入进程在每次运行时达到刷新的最大页数的次数 | |
查询情况 | conflicts | int | 与恢复冲突取消的查询次数,只会在备机上发生 | |
死锁 | deadlocks | int | 死锁发生的次数 | |
临时文件 | temp_bytes | int | 临时文件的大小 | |
临时文件 | temp_files | int | 产生临时文件的数量,如果这个值很高,需要调大work_mem | |
SQL执行次数 | tup_deleted | int | 删除的行数 | |
SQL执行次数 | tup_inserted | int | 插入的行数 | |
SQL执行次数 | tup_updated | int | 更新的行数 | |
SQL执行质量 | tup_fetched | int | 指通过索引返回的行数 | |
SQL执行质量 | tup_returned | int | 对于表来说,是全表扫描的行数;对于索引是通过索引返回的索引行数,如果这个值明显大于tup_fetched,说明当前数据库存在大量的全表扫描。查看执行计划,这个是databas全局级别的 | |
事务 | xact_commit | int | 该数据库事务提交总量:和下面的rollback和作为TPS统计 | |
事务 | xact_rollback | int | 该数据库事务rollback总量,如果特别多,需要看业务是否有问题了 |