部署 Mongodb-Exporter
监控 Mongodb 需要创建 Monitor 用户
## 前提是你有足够的权限创建
db.createUser({
user: "exporter",
pwd: "exporter_password",
roles: [
{ role: "clusterMonitor", db: "admin" },
{ role: "read", db: "local" }
]
});
## 本人没有权限创建只能监控部分指标
db.createUser({
user: "exporter",
pwd: "exporter_password",
roles: [
{ role: "read", db: "test" },
{ role: "read", db: "local" }
]
});
## 如果你有用户只想添加权限可以如下
db.updateUser("exporter", {
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" },
{ role: "backup", db: "admin" },
{ role: "restore", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
{ role: "clusterAdmin", db: "admin" }
]
});
有全部权限采集可以配置为 --collect-all,此处采集指标根据权限配置
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-exporter
namespace: monitoring
labels:
app: mongodb-exporter
spec:
selector:
matchLabels:
app: mongodb-exporter
template:
metadata:
labels:
app: mongodb-exporter
spec:
containers:
- name: mongodb-exporter
image: bitnami/mongodb-exporter
args:
- "--mongodb.user=exporter"
- "--mongodb.password=123456"
- "--mongodb.uri=mongodb://10.0.1.2:27017/admin"
- "--collector.diagnosticdata" //此处采集指标根据权限配置
- "--collector.dbstats"
- "--collector.dbstatsfreestorage"
- "--collector.indexstats"
- "--collector.collstats"
- "--collector.profile"
- "--collector.shards"
- "--collector.pbm"
ports:
- containerPort: 9216
name: http
---
apiVersion: v1
kind: Service
metadata:
name: mongodb-exporter
namespace: monitoring
labels:
app: mongodb-exporter
spec:
ports:
- name: api
port: 9216
targetPort: 9216
type: ClusterIP
selector:
app: mongodb-exporter
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: mongodb-exporter
app.kubernetes.io/part-of: kube-prometheus
name: mongodb-exporter
namespace: monitoring
spec:
endpoints:
- honorLabels: true
interval: 30s
path: /metrics
port: api
scheme: http
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app: mongodb-exporter