1.注册节点到pmm
pmm-admin config --server-insecure-tls --server-url=https://admin:admin@X.X.X.X:443 --node-address=被监控节点ip --node-type=generic --node-name=被监控节点的名称
2.创建数据库用户
db.getSiblingDB("admin").createRole({ role: "explainRole", privileges: [{ resource: { db: "", collection: "" }, actions: [ "listIndexes", "listCollections", "dbStats", "dbHash", "collStats", "find" ] }], roles:[] }) db.getSiblingDB("admin").createUser({ user: "pmm_mongodb", pwd: "password", roles: [ { role: "explainRole", db: "admin" }, { role: "clusterMonitor", db: "admin" }, { role: "read", db: "local" } ] })
如果想使用PMM Query Analytics,需要开启profiling feature,默认是不开启,因为会影响性能。
3.开启profiling功能
这一步是可选项。
·在实例级别启动profiler
mongod <other options> --profile 2 --slowms 200 --rateLimit 100
或者配置在配置文件中
operationProfiling: mode: all slowOpThresholdMs: 200 # (Below variable is available only with Percona Server for MongoDB.) rateLimit: 100
·在DB级别开启profiler
use dbname db.setProfilingLevel(2)
4.添加mongodb实例
pmm-admin add mongodb --username=pmm_mongodb --password=password --query-source=profiler --cluster=mycluster --service-name=myc_mongoc2 --host=127.0.0.1 --port=27017
5.查看
$ sudo pmm-admin list Service type Service name Address and port Service ID MongoDB myc_mongoc2 127.0.0.1:37061 /service_id/02e261a1-e8e0-4eb4-8043-8616424500de Agent type Status Metrics Mode Agent ID Service ID pmm_agent Connected /agent_id/281b4046-4f4b-4897-bd2e-b771d3e97922 node_exporter Running push /agent_id/5e9b17a8-ecb9-47c3-8477-ce322047c4d9 mongodb_exporter Running push /agent_id/0067dd85-9a0a-47dd-976e-ae779deb982b /service_id/5c92f132-3005-45ab-84df-7541c286c34a mongodb_profiler_agent Running /agent_id/18d3d87a-9bb9-48c1-8e3e-d8bae3f043bb /service_id/02e261a1-e8e0-4eb4-8043-8616424500de
#########################################
考虑到密码的问题,可以做一下密码隐藏
cat <<EOF >/home/.pmm-admin-config.conf --server-insecure-tls --server-url=https://admin:admin@X.X.X.X:443 --node-address=被监控节点ip --node-type=generic --node-name=被监控节点的名称 EOF cat <<EOF >/home/.pmm-admin-mysql.conf --username=pmm_mongodb --password=password --query-source=profiler --cluster=mycluster --service-name=xxxx --host=127.0.0.1 --port=27017 EOF
pmm-admin config @/home/.pmm-admin-config.conf pmm-admin add mongodb @/home/.pmm-admin-mongodb.conf