pgmetrics 一个灵活方便的pg 监控cli

pgmetrics 是基于golang 编写的一个灵活的pg性能分析cli,我们可以方便的看到关于pg 以及系统的一些metrics
使用简单,支持human,json,csv 等格式

下载

参考以下地址https://github.com/rapidloop/pgmetrics/releases

使用

  • 命令
 
pgmetrics -U <user> -p <port> -h <host>
  • 命令
pgmetrics collects PostgreSQL information and metrics.
Usage:
  pgmetrics [OPTION]... [DBNAME]
General options:
  -t, --timeout=SECS individual query timeout in seconds (default: 5)
  -i, --input=FILE don't connect to db, instead read and display
                                   this previously saved JSON file
  -V, --version output version information, then exit
  -?, --help[=options] show this help, then exit
      --help=variables list environment variables, then exit
Collection options:
  -S, --no-sizes don't collect tablespace and relation sizes
  -c, --schema=REGEXP collect only from schema(s) matching POSIX regexp
  -C, --exclude-schema=REGEXP do NOT collect from schema(s) matching POSIX regexp
  -a, --table=REGEXP collect only from table(s) matching POSIX regexp
  -A, --exclude-table=REGEXP do NOT collect from table(s) matching POSIX regexp
      --omit=WHAT do NOT collect the items specified as a comma-separated
                                   list of: "tables", "indexes", "sequences",
                                   "functions", "extensions", "triggers",
                                   "statements", "log"
      --sql-length=LIMIT collect only first LIMIT characters of all SQL
                                   queries (default: 500)
      --statements-limit=LIMIT collect only utmost LIMIT number of row from
                                   pg_stat_statements (default: 100)
      --only-listed collect info only about the databases listed as
                                   command-line args (use with Heroku)
      --log-file location of PostgreSQL log file
      --log-span=MINS examine the last MINS minutes of logs (default: 5)
Output options:
  -f, --format=FORMAT output format; "human", "json" or "csv" (default: "human")
  -l, --toolong=SECS for human output, transactions running longer than
                                   this are considered too long (default: 60)
  -o, --output=FILE write output to the specified file
      --no-pager do not invoke the pager for tty output
Connection options:
  -h, --host=HOSTNAME database server host or socket directory
                                   (default: "10.16.225.178")
  -p, --port=PORT database server port (default: 5433)
  -U, --username=USERNAME database user name (default: "postgres")
  -w, --no-password never prompt for password
For more information, visit <https://pgmetrics.io>.
  • 环境变量方式
    通过环境变量的方式,比较适合基于容器(比如k8s的configmap)以下是支持的环境变量
 
Environment variables:
Usage:
  NAME=VALUE [NAME=VALUE] pgmetrics ...
  PAGER name of external pager program
  PGAPPNAME the application_name connection parameter
  PGDATABASE the dbname connection parameter
  PGHOST the host connection parameter
  PGPORT the port connection parameter
  PGUSER the user connection parameter
  PGPASSWORD connection password (not recommended)
  PGPASSFILE path to the pgpass password file
  PGSSLMODE "disable", "require", "verify-ca", "verify-full"
  PGSSLCERT path to client SSL certificate
  PGSSLKEY path to secret key for client SSL certificate
  PGSSLROOTCERT path to SSL root CA
  PGCONNECT_TIMEOUT connection timeout in seconds
Also, the following libpq-related environment variarables are not
required/used by pgmetrics and are IGNORED:
  PGHOSTADDR, PGSERVICE, PGSERVICEFILE, PGREALM, PGREQUIRESSL,
  PGSSLCRL, PGREQUIREPEER, PGKRBSRVNAME, PGGSSLIB, PGSYSCONFDIR,
  PGLOCALEDIR

说明

官方同时提供了一个dashboard(云服务),实际上我们基于json 文件,使用prometheus 的push gateway 以及
grok exporter,或者mtail,也都可以方便的进行数据分析的,同时官方文档也提供了比较详细的参数说明,pg_top,
pg_systat 也是不错的工具

参考资料

https://github.com/rapidloop/pgmetrics/releases
https://pgmetrics.io/docs/

posted on   荣锋亮  阅读(788)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-03-03 Announcing HashiCorp Consul + Kubernetes
2019-03-03 katalog-sync: Reliable Integration of Consul and Kubernetes

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示