线上实战zabbix监控mongodb详细步骤

                                    **Zabbix 监控mongodb做后整理**

系统运维工程师 李超
因为我安全问题我们只能呢个通过mongo客户端去远程监控mongo服务端。
1、 如果你不是在mongo服务器上操作请参考我下边的部分,如果是直接在mongodb服务器上安装的zabbix_agnetd请参考网上其他文章。(直接在mongodb服务端安装zabbix客户端的文档非常多)。
2、 下边首先安装mongo客户端:我的系统是:ubuntu16.04,安装mongo客户端直接apt-get安装即可(这里不多做介绍,但是要注意apt一般都是较低的版本,要4.0版本的可以更新apt这里不做介绍,网上可以搜索到相关内容)。
3、 当mongodb客户端安装完毕以后我们执行下边命令
/bin/echo "db.serverStatus()" |/usr/bin/mongo 192.168.16.111:20001/admin -ulichao -plichao
通过这个命令可以测试知道mongo的系统参数,我们根据这些系统参数进行监控,
执行结果如下:

MongoDB shell version v4.0.0
connecting to: mongodb://192.168.16.111:20001/admin
MongoDB server version: 3.4.9
WARNING: shell and server versions do not match
{
"host" : "iZ2zeem1uivcbfbr01nmnrZ:20000",
"version" : "3.4.9",
"process" : "mongos",
"pid" : NumberLong(10828),
"uptime" : 24441734,
"uptimeMillis" : NumberLong("24441733680"),
"uptimeEstimate" : NumberLong(24441733),
"localTime" : ISODate("2018-08-02T09:34:54.400Z"),
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 1763423,
"rollovers" : 0
},
"connections" : {
"current" : 86,
"available" : 52342,
"totalCreated" : 118672
},
"extra_info" : {
"note" : "fields vary by platform",
"page_faults" : 14
},
"network" : {
"bytesIn" : NumberLong("467536962787"),
"bytesOut" : NumberLong("111369070632"),
"physicalBytesIn" : NumberLong("467536962787"),
"physicalBytesOut" : NumberLong("108213593338"),
"numRequests" : NumberLong("2582169303")
},
"opcounters" : {
"insert" : 619611,
"query" : 406777,
"update" : 122426978,
"delete" : 61,
"getmore" : 308,
"command" : 215576153
},
"sharding" : {
"configsvrConnectionString" : "config/iZ2ze7s6pfi7t4x18mx417Z:22000,iZ2ze7s6pfi7t4x18mx418Z:22000,iZ2ze7s6pfi7t4x18mx419Z:22000",
"lastSeenConfigServerOpTime" : {
"ts" : Timestamp(1533202490, 2),
"t" : NumberLong(3)
}
},
"tcmalloc" : {
"generic" : {
"current_allocated_bytes" : 4007000,
"heap_size" : NumberLong("3108966400")
},
"tcmalloc" : {
"pageheap_free_bytes" : 36864,
"pageheap_unmapped_bytes" : NumberLong("3090604032"),
"max_total_thread_cache_bytes" : NumberLong(1073741824),
"current_total_thread_cache_bytes" : 5583584,
"total_free_bytes" : 14318504,
"central_cache_free_bytes" : 3283112,
"transfer_cache_free_bytes" : 5451808,
"thread_cache_free_bytes" : 5583584,
"aggressive_memory_decommit" : 0,
"formattedString" : "------------------------------------------------\nMALLOC: 4007000 ( 3.8 MiB) Bytes in use by application\nMALLOC: + 36864 ( 0.0 MiB) Bytes in page heap freelist\nMALLOC: + 3283112 ( 3.1 MiB) Bytes in central cache freelist\nMALLOC: + 5451808 ( 5.2 MiB) Bytes in transfer cache freelist\nMALLOC: + 5583584 ( 5.3 MiB) Bytes in thread cache freelists\nMALLOC: + 8577216 ( 8.2 MiB) Bytes in malloc metadata\nMALLOC: ------------\nMALLOC: = 26939584 ( 25.7 MiB) Actual memory used (physical + swap)\nMALLOC: + 3090604032 ( 2947.4 MiB) Bytes released to OS (aka unmapped)\nMALLOC: ------------\nMALLOC: = 3117543616 ( 2973.1 MiB) Virtual address space used\nMALLOC:\nMALLOC: 2014 Spans in use\nMALLOC: 115 Thread heaps in use\nMALLOC: 4096 Tcmalloc page size\n------------------------------------------------\nCall ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).\nBytes released to the OS take up virtual address space but no physical memory.\n"
}
},
"mem" : {
"bits" : 64,
"resident" : 174,
"virtual" : 3426,
"supported" : true
},
"metrics" : {
"cursor" : {
"timedOut" : NumberLong(380),
"open" : {
"multiTarget" : NumberLong(0),
"singleTarget" : NumberLong(0),
"pinned" : NumberLong(0),
"total" : NumberLong(0)
}
},
"commands" : {
"<UNKNOWN>" : NumberLong(1),
"aggregate" : {
"failed" : NumberLong(142),
"total" : NumberLong(8980)
},
"authenticate" : {
"failed" : NumberLong(12),
"total" : NumberLong(12)
},
"buildInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(635407)
},
"collStats" : {
"failed" : NumberLong(65),
"total" : NumberLong(6827)
},
"count" : {
"failed" : NumberLong(388),
"total" : NumberLong(491985789)
},
"create" : {
"failed" : NumberLong(0),
"total" : NumberLong(10)
},
"createIndexes" : {
"failed" : NumberLong(1),
"total" : NumberLong(69)
},
"createUser" : {
"failed" : NumberLong(6),
"total" : NumberLong(10)
},
"currentOp" : {
"failed" : NumberLong(0),
"total" : NumberLong(15)
},
"dbStats" : {
"failed" : NumberLong(7),
"total" : NumberLong(917)
},
"delete" : {
"failed" : NumberLong(0),
"total" : NumberLong(705)
},
"distinct" : {
"failed" : NumberLong(17),
"total" : NumberLong(5105)
},
"drop" : {
"failed" : NumberLong(0),
"total" : NumberLong(67)
},
"dropDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(7)
},
"dropIndexes" : {
"failed" : NumberLong(7),
"total" : NumberLong(23)
},
"enableSharding" : {
"failed" : NumberLong(1),
"total" : NumberLong(2)
},
"explain" : {
"failed" : NumberLong(0),
"total" : NumberLong(13)
},
"find" : {
"failed" : NumberLong(131),
"total" : NumberLong(1764517)
},
"findAndModify" : {
"failed" : NumberLong(1),
"total" : NumberLong(772)
},
"getLastError" : {
"failed" : NumberLong(0),
"total" : NumberLong(1989)
},
"getLog" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"getMore" : {
"failed" : NumberLong(17),
"total" : NumberLong(1791)
},
"getnonce" : {
"failed" : NumberLong(0),
"total" : NumberLong(38)
},
"insert" : {
"failed" : NumberLong(0),
"total" : NumberLong(207939962)
},
"isMaster" : {
"failed" : NumberLong(0),
"total" : NumberLong(35391424)
},
"killCursors" : {
"failed" : NumberLong(0),
"total" : NumberLong(79)
},
"listCollections" : {
"failed" : NumberLong(0),
"total" : NumberLong(862)
},
"listDatabases" : {
"failed" : NumberLong(0),
"total" : NumberLong(263)
},
"listIndexes" : {
"failed" : NumberLong(0),
"total" : NumberLong(8)
},
"logout" : {
"failed" : NumberLong(0),
"total" : NumberLong(8658)
},
"mapReduce" : {
"failed" : NumberLong(24),
"total" : NumberLong(64)
},
"ping" : {
"failed" : NumberLong(0),
"total" : NumberLong(5980)
},
"profile" : {
"failed" : NumberLong(4),
"total" : NumberLong(4)
},
"renameCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"repairDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(1)
},
"replSetGetStatus" : {
"failed" : NumberLong(88870),
"total" : NumberLong(88870)
},
"rolesInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(491)
},
"saslContinue" : {
"failed" : NumberLong(4),
"total" : NumberLong(183362)
},
"saslStart" : {
"failed" : NumberLong(8),
"total" : NumberLong(91691)
},
"serverStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(223111)
},
"shardCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(3)
},
"update" : {
"failed" : NumberLong(0),
"total" : NumberLong(552681439)
},
"usersInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(493)
},
"whatsmyuri" : {
"failed" : NumberLong(0),
"total" : NumberLong(54513)
}
}
},
"ok" : 1
}
Bye

上边是我们执行完命令从mongo服务端获取到mongo服务端的参数,下面对他进行监控。

首先建立脚本check_mongo.sh

#!/bin/bash

#mongodb status
#b.serverStatus().ok
#memory status
#Physical memory: db.serverStatus().mem.resident
#Virtual memory: db.serverStatus().mem.virtual
#opcounters status
#insert: db.serverStatus().opcounters.insert
#query: db.serverStatus().opcounters.query
#update: db.serverStatus().opcounters.update
#delete: db.serverStatus().opcounters.delete
#connections status
#current connections: db.serverStatus().connections.current
MONGODBPATH="/usr/bin/mongo"
HOST="47.94.37.221"
PORT="$1"
MONGODB_PA="$MONGODBPATH ${HOST}:${PORT}/admin -uroot -pkeytech2017"

if [ $# == 3 ];then
result=$(/bin/echo "db.serverStatus().$2.$3" | $MONGODB_PA --quiet)
echo $result
elif [ $# == 2 ];then
result=$(/bin/echo "db.serverStatus().$2" | $MONGODB_PA --quiet)
echo $result
else
echo "Usage:$0 PORT mem resident"
fi

保存退出!
这里我们可以测试一下我们的脚本可用性:
线上实战zabbix监控mongodb详细步骤
线上实战zabbix监控mongodb详细步骤
我们这里的测试是结合上边第一条命令执行后显示的参数来输入的如:
线上实战zabbix监控mongodb详细步骤

这下明白脚本后边跟的参数的意思了吧$1:端口 $2:主参数 $3: 你要提取的参数
然后我们建立我们想要的key
线上实战zabbix监控mongodb详细步骤
别问我这个目录时干什么的,如果不知道,请从头开始了解zabbix。
在这个目录下我监理一个.conf文件
线上实战zabbix监控mongodb详细步骤
这个是我的key文件里边所有内容,但是接上边的内容我们这里只写入

UserParameter=MongoDB.totalCreated,/data/zabbix/scripts/check_mongodb.sh 20001 connections totalCreated
UserParameter=MongoDB.available,/data/zabbix/scripts/check_mongodb.sh 20001 connections available
这两条

剩下的两条后边会用到(最下边会说这两条做什么用)
加完那两条我们保存退出,然后去web上自定义key进行监控

线上实战zabbix监控mongodb详细步骤
线上实战zabbix监控mongodb详细步骤

保存,过一会监控图像就出来了,如图:
线上实战zabbix监控mongodb详细步骤
线上实战zabbix监控mongodb详细步骤

OK!监控完毕
但是,但是……mongo那么多监控项我们现在只监控了两项吧,如果你觉得上边的方法你吼的住你照着上边自己慢慢的吧所有key都谢出来,下面介绍其他方法,

第二种办法就是我上边说的,直接定义key,在key文件里边加上命令如下

UserParameter=MongoDB.Status[*],/bin/echo "db.serverStatus().$1" |/usr/bin/mongo 192.168.16.111:20001/admin -ulichao -plichao | grep "\<$2\>" |awk -F : '{print $$2}' |awk -F , '{print $$1}'
UserParameter=MongoDB.byesOut,/bin/echo "db.serverStatus().network" |/usr/bin/mongo 192.168.16.111:20001/admin -ulichao -plichao | grep "bytesOut" | awk -F : '{print $2}' | awk -F , '{print $1}' | awk -F \" '{print $2}'
UserParameter=MongoDB.bytesIn,/bin/echo "db.serverStatus().network" |/usr/bin/mongo 192.168.16.111:20001/admin -ulichao -plichao | grep "bytesIn" | awk -F : '{print $2}' | awk -F , '{print $1}' | awk -F \" '{print $2}'
添加完毕保存保存退出。
然后直接导入模板监控即可。模板在这:https://pan.baidu.com/s/1PFrhealedPUejz7ACI_WVA
添加到web上我么你可以在图形上看到下图
线上实战zabbix监控mongodb详细步骤
到此mongo监控完毕。

                                                                                               系统运维工程师  李超

转载于:https://blog.51cto.com/13120271/2153773

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 Zabbix 进行 Kafka 监控详细步骤: 1. 在 Zabbix 服务器上安装 Zabbix Java Gateway,该网关将充当 Zabbix 服务器和 Kafka Broker 之间的中间件。在 Ubuntu 上,可以使用以下命令进行安装: ``` sudo apt-get update sudo apt-get install zabbix-java-gateway ``` 2. 安装 Zabbix Java Gateway 后,需要编辑其配置文件 zabbix_java_gateway.conf,以便将其配置为监听 Kafka Broker。在该文件中,需要将“LISTEN_IP”和“LISTEN_PORT”设置为 Kafka Broker 的 IP 地址和端口。例如: ``` LISTEN_IP=192.168.1.100 LISTEN_PORT=10052 ``` 3. 接下来,需要在 Kafka Broker 上安装 JMX 暴露器。该暴露器将允许 Zabbix Java Gateway 访问 Kafka Broker 的 JMX 指标。可以按照以下步骤进行安装: - 编辑 Kafka Broker 的配置文件 server.properties,将以下行添加到该文件末尾: ``` # Enabling JMX exporter kafka.metrics.reporters=com.salesforce.kafka.test.KafkaJmxReporter kafka.jmx.rmi.host=127.0.0.1 kafka.jmx.rmi.port=9999 ``` - 下载 Kafka JMX 暴露器,并将其复制到 Kafka Broker 的 libs 目录中: ``` wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.12.0/jmx_prometheus_javaagent-0.12.0.jar sudo cp jmx_prometheus_javaagent-0.12.0.jar /usr/local/kafka/libs/ ``` - 创建一个配置文件,用于指定要监视的 JMX 指标: ``` # kafka-0-8-2.yml - pattern : kafka.server<type=BrokerTopicMetrics, name=BytesInPerSec, topic=*, brokerId=*><>OneMinuteRate name: kafka_broker_topic_in_bytes_per_sec{topic="$1", broker="$2"} help: "The incoming byte rate of the given topic/partition in bytes/sec." type: GAUGE ``` - 启动 Kafka Broker,并将 JMX 暴露器添加到其 JVM 参数中: ``` /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties -javaagent:/usr/local/kafka/libs/jmx_prometheus_javaagent-0.12.0.jar=9999:/usr/local/kafka/config/kafka-0-8-2.yml ``` 4. 在 Zabbix 服务器上创建一个新的主机,并将其配置为监视 Kafka Broker。在主机配置中,需要指定主机名称、可用性和性能监视器类型以及主机的 IP 地址。 5. 接下来,需要在主机配置中添加一个新的 JMX 监视器。在监视器配置中,需要指定以下参数: - 监视器类型:JMX 监视器 - 监视器名称:任何有意义的名称 - JMX 主机:Kafka Broker 的 IP

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值