初始化提交
This commit is contained in:
196
prometheus/安装exporter
Normal file
196
prometheus/安装exporter
Normal file
@@ -0,0 +1,196 @@
|
||||
tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz
|
||||
|
||||
vim /etc/systemd/system/node_exporter.service
|
||||
|
||||
[Unit]
|
||||
Description=node_exporter Monitoring System
|
||||
Documentation=node_exporter Monitoring System
|
||||
[Service]
|
||||
ExecStart=/opt/exporter/node_exporter/node_exporter --web.listen-address=:9100
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
systemctl daemon-reexec
|
||||
systemctl daemon-reload
|
||||
|
||||
|
||||
systemctl start node_exporter
|
||||
systemctl status node_exporter
|
||||
|
||||
systemctl enable node_exporter
|
||||
|
||||
ss -ntl | grep 9100
|
||||
|
||||
curl http://localhost:9100/metrics
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 下载 node_exporter
|
||||
cd /opt/
|
||||
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.0/node_exporter-1.8.0.linux-amd64.tar.gz
|
||||
tar -xzf node_exporter-1.8.0.linux-amd64.tar.gz
|
||||
mv node_exporter-1.8.2.linux-amd64 node_exporter
|
||||
|
||||
|
||||
# systemd 管理----------
|
||||
sudo tee /etc/systemd/system/node_exporter.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Prometheus Node Exporter
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
ExecStart=/opt/exporter/node_exporter/node_exporter
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
# systemd 管理----------
|
||||
sudo systemctl daemon-reexec
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start node_exporter
|
||||
sudo systemctl status node_exporter
|
||||
sudo systemctl enable node_exporter
|
||||
|
||||
|
||||
# 启动服务
|
||||
nohup /opt/node_exporter/node_exporter > /opt/node_exporter/node_exporter.log 2>&1 &
|
||||
|
||||
默认监听 9100,确认防火墙放行或仅 Prometheus 网络能访问。
|
||||
|
||||
调试技巧
|
||||
cat /proc/1784152/cmdline | tr '\0' '\n'
|
||||
|
||||
安装 process_exporter(二进制)
|
||||
cd /opt/
|
||||
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.7.10/process-exporter-0.7.10.linux-amd64.tar.gz
|
||||
tar -xzf process-exporter-0.7.10.linux-amd64.tar.gz
|
||||
mv process-exporter-0.8.5.linux-amd64 process-exporter
|
||||
|
||||
|
||||
sudo tee /etc/systemd/system/process_exporter.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Prometheus Process Exporter
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/exporter/process-exporter/process-exporter --config.path=/opt/exporter/process-exporter/process-exporter.yml
|
||||
Restart=always
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start process_exporter
|
||||
sudo systemctl status process_exporter
|
||||
sudo systemctl enable process_exporter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
安装 mongodb_exporter
|
||||
cd /opt
|
||||
wget https://github.com/percona/mongodb_exporter/releases/download/v0.40.0/mongodb_exporter-0.40.0.linux-amd64.tar.gz
|
||||
tar -xzf mongodb_exporter-0.40.0.linux-amd64.tar.gz
|
||||
mv mongodb_exporter-0.40.0.linux-amd64 /opt/mongodb_exporter
|
||||
|
||||
|
||||
use admin
|
||||
db.createUser({
|
||||
user: "prometheus",
|
||||
pwd: "StrongPassword",
|
||||
roles: [ { role: "clusterMonitor", db: "admin" } ]
|
||||
})
|
||||
|
||||
|
||||
[Unit]
|
||||
Description=Prometheus MongoDB Exporter
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/exporter/mongodb_exporter/mongodb_exporter \
|
||||
--mongodb.uri=mongodb://prometheus:StrongPassword@localhost:27017/admin
|
||||
Restart=on-failure
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
|
||||
|
||||
sudo tee /etc/systemd/system/mongodb_exporter.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Prometheus MongoDB Exporter
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/exporter/mongodb_exporter/mongodb_exporter \
|
||||
--mongodb.uri=mongodb://admin:Ud4G8sty6BK@localhost:27017/admin \
|
||||
Restart=on-failure
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
|
||||
# 请将 mongodb://myuser:mypassword@localhost:27017/admin 替换为你的实际账号密码和数据库地址。
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart mongodb_exporter
|
||||
sudo systemctl start mongodb_exporter
|
||||
sudo systemctl status mongodb_exporter
|
||||
sudo systemctl enable mongodb_exporter
|
||||
|
||||
|
||||
[Unit]
|
||||
Description=Prometheus MongoDB Exporter
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/exporter/mongodb_exporter/mongodb_exporter --mongodb.uri=mongodb://admin:Ud4G8sty6BK@localhost:27017/admin --compatible-mode
|
||||
Restart=on-failure
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
|
||||
|
||||
# 启动
|
||||
/opt/mongodb_exporter/mongodb_exporter \
|
||||
--mongodb.uri="mongodb://<user>:<password>@localhost:27017/admin" &
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
use admin
|
||||
|
||||
// 获取总连接数信息
|
||||
var connStatus = db.serverStatus().connections;
|
||||
print("总连接数 current:", connStatus.current, "可用 available:", connStatus.available);
|
||||
|
||||
// 统计每个客户端 IP 当前连接数
|
||||
|
||||
db.adminCommand({
|
||||
aggregate: 1,
|
||||
pipeline: [
|
||||
{ $currentOp: { allUsers: true, localOps: true } },
|
||||
{ $match: { client: { $exists: true } } },
|
||||
{ $project: { ip: { $arrayElemAt: [ { $split: ["$client", ":"] }, 0 ] } } },
|
||||
{ $group: { _id: "$ip", count: { $sum: 1 } } },
|
||||
{ $sort: { count: -1 } }
|
||||
],
|
||||
cursor: {}
|
||||
}).cursor.firstBatch.forEach(doc => printjson(doc));
|
||||
Reference in New Issue
Block a user