需求:promethus对mongodb进行监控,
- 准备步骤:安装一个简单mongodb服务
- 下载MongoDB的插件
- promethus 配置文件修改关联。
一、快速简易安装一个mongodb服务
- 1、安装部署
cat >/etc/yum.repos.d/mongodb-org-4.0.repo <<EOF
[mongodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
EOF
yum update
yum -y install mongodb-org
- 2、启动
systemctl start mongod.service
- 3、配置权限 添加amdin用户
use admin
db.createUser({"user":"admin","pwd":"admin123456","roles":["root"]})
修改配置文件,开启权限认证vim /etc/mongod.conf
security:
authorization: enabled
重启动
systemctl restart mongod
二、下载mongodb_exporter,收集数据
https://github.com/percona/mongodb_exporter/releases 引用此功能更全一点
https://github.com/dcu/mongodb_exporter(更新比较慢)
- 安装mongodb_exporter
wget https://github.com/percona/mongodb_exporter/releases/download/v0.10.0/mongodb_exporter-0.10.0.linux-amd64.tar.gz
mkdir -p /usr/local/exporter/mongodb_exporter
mv mongodb_exporter-0.10.0.linux-amd64.tar.gz /usr/local/exporter/mongodb_exporter/
cd /usr/local/exporter/mongodb_exporter/
tar zxvf mongodb_exporter-0.10.0.linux-amd64.tar.gz
- 启动服务
nohup ./mongodb_exporter --mongodb.uri "mongodb://admin:admin123456@127.0.0.1:27017" &
集群的话192.168.50.7:27017,192.168.50.8:27017,用逗号分隔开就可以
[root@Prometheus mongodb_exporter]# tail -f nohup.out
time="2020-02-23T17:53:33+08:00" level=info msg="Starting mongodb_exporter (version=0.10.0, branch=v0.10.0, revision=bf683745093a9210ebacbeb235bb792e21d17389)" source="mongodb_exporter.go:94"
time="2020-02-23T17:53:33+08:00" level=info msg="Build context (go=go1.12.9, user=travis@build.travis-ci.com, date=20190918-16:07:48)" source="mongodb_exporter.go:95"
time="2020-02-23T17:53:33+08:00" level=info msg="Starting HTTP server for http://:9216/metrics ..." source="server.go:140"
- 访问web 界面
三、修改promethus主配置文件,采集mongodb的数据指标
vim /usr/local/promethus/promethus.yml
- job_name: mongo_exporter
static_configs:
- targets: ['114.67.116.119:9216']
labels:
instance: mongo
- 重启动promethus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
或者
kill -hup PID
四、配置granfana展示
导入模板2583,https://grafana.com/dashboards/2583
注意:模板获取到指标变量名,要改为IP:PORT/metrics