安装pmm客户端

下载安装客户端DownLoad

$ rpm -ivh pmm2-client-2.10.1-6.el7.x86_64.rpm

客户端连接到server

$ pmm-admin config --server-insecure-tls --server-url=https://admin:Abcd123@10.0.139.163:443

查看客户端

$ pmm-admin list
Service type Service name Address and port Service ID

Agent type Status Agent ID Service ID
pmm_agent Connected /agent_id/4e8b2fc2-63f7-4b16-a916-5aa2ec05f641
node_exporter Running /agent_id/09382ac0-756a-4397-8d6b-ef944b339e34

添加MySQL监控

创建pmm用户

mysql> Grant SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD on *.* to 'pmm'@'localhost' identified by 'Abcd123#' with grant option;
mysql> flush privileges;

注册MySQL监控

$ pmm-admin add mysql --username=pmm --password=Abcd123# --query-source=perfschema test-mysql 127.0.0.1:3306

MySQL提供了两个查询指标来源:slowlog和perfschema

查看客户端服务

$ pmm-admin list
Service type Service name Address and port Service ID
MySQL t-luhx02-v-szzb-mysql 127.0.0.1:33006 /service_id/1dc85561-e23e-46a1-8f24-056ffa51137e

Agent type Status Agent ID Service ID
pmm_agent Connected /agent_id/4e8b2fc2-63f7-4b16-a916-5aa2ec05f641
node_exporter Running /agent_id/09382ac0-756a-4397-8d6b-ef944b339e34
mysqld_exporter Running /agent_id/efc4b59f-4136-4526-9b6e-b253c88b1116 /service_id/1dc85561-e23e-46a1-8f24-056ffa51137e
mysql_perfschema_agent Running /agent_id/ede09a9a-d68c-4b98-b461-0e5bd70608b9 /service_id/1dc85561-e23e-46a1-8f24-056ffa51137e

查看MySQL监控面板
pmm-mysql

最佳实践:

  • 如果是使用percona mysql,query source可以使用slowlog,并设置log_slow_rate_limit和slow_query_log_always_write_time,其它情况下建议使用Performance
  • query source采用performance时,应确定所需的setup_consumers已经开启,否则dashboard中无法看到对应视图
  • 当MySQL有多个schema和table时,添加监控时设置–disable-tablestats和–disable-tablestats-limit有助于提高pmm的性能
  • 可以选择开启innodb_monitor_enable=all

添加MongoDB监控

查询分析器要求MongoDB版本在3.2或更高,并且需要创建监控用户

db.createRole({
role: "explainRole",
privileges: [{
resource: {
db: "",
collection: ""
},
actions: [
"listIndexes",
"listCollections",
"dbStats",
"dbHash",
"collStats",
"find"
]
}],
roles:[]
})

db.getSiblingDB("admin").createUser({
user: "pmm",
pwd: "Abcd123",
roles: [
{ role: "explainRole", db: "admin" },
{ role: "clusterMonitor", db: "admin" },
{ role: "read", db: "local" }
]
})

另外,查询分析器还要求MongoDB启用性能分析,可以在参数文件中开启

operationProfiling:
slowOpThresholdMs: 200
mode: slowOp

注册MongoDB监控

$ pmm-admin add mongodb --help
usage: pmm-admin add mongodb [<flags>] [<name>] [<address>]

Add MongoDB to monitoring

Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man)
--version Show application version
--server-url=SERVER-URL PMM Server URL in `https://username:password@pmm-server-host/` format
--server-insecure-tls Skip PMM Server TLS certificate validation
--debug Enable debug logging
--trace Enable trace logging (implies debug)
--json Enable JSON output
--node-id=NODE-ID Node ID (default is autodetected)
--pmm-agent-id=PMM-AGENT-ID
The pmm-agent identifier which runs this instance (default is autodetected)
--username=USERNAME MongoDB username
--password=PASSWORD MongoDB password
--query-source=profiler Source of queries, one of: profiler, none (default: profiler)
--environment=ENVIRONMENT Environment name
--cluster=CLUSTER Cluster name
--replication-set=REPLICATION-SET
Replication set name
--custom-labels=CUSTOM-LABELS
Custom user-assigned labels
--skip-connection-check Skip connection check
--tls Use TLS to connect to the database
--tls-skip-verify Skip TLS certificates validation
--service-name=NAME Service name (overrides positional argument)
--host=HOST Service hostname or IP address (overrides positional argument)
--port=PORT Service port number (overrides positional argument)
--socket=SOCKET Path to socket

Positional arguments:
[<name>] Service name (autodetected default: t-luhx02-v-szzb-mongodb)
[<address>] MongoDB address and port (default: 127.0.0.1:27017)

添加单节点

$ pmm-admin add mongodb  --service-name="test-mongodb" --username=pmm --password=Abcd123  --host=10.0.139.162 --port=20000

添加副本集

$ pmm-admin add mongodb --cluster test --replication-set="shard1" --service-name="shard1-162" --username=pmm --password=Abcd123  --host=10.0.139.162 --port=20000

添加mongos

$ pmm-admin add mongodb --cluster test --service-name="mongos-162" --username=pmm --password=Abcd123  --host=10.0.139.162 --port=24000