我是靠谱客的博主 悦耳长颈鹿,最近开发中收集的这篇文章主要介绍Open-Falcon 使用 python 监控发布中未分发的命令数,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

性能计数器监控参考 :SqlServer 监控发布中未分发的命令数

但 open-falcon 不能监控 windows 性能计数器,因此只能自定义监控推送监控信息。open-falcon 使用 python 可以推送数据,因此需安装python(脚本使用python2.7)。

自定义push数据到open-falcon 参考:自定义push数据到open-falcon

 

 

#coding=gbk
#python2.7.13
import requests
import time
import json
import pymssql
# 推送默认参数
# https://book.open-falcon.org/zh/usage/data-push.html
endpoint = "KK-PC"
metric = "repl."
timestamp = int(time.time())
step = 300
value = 0
counterType = "GAUGE"
tags = "db="
# 存储过程参数声明(保存到json中),用于执行sp_replmonitorsubscriptionpendingcmds
"""
EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds
@publisher = N'publisher'
,@publisher_db = N'publisher_db'
,@publication = N'publication_name'
,@subscriber = N'subscriber'
,@subscriber_db = N'subscriber_db'
,@subscription_type =0
"""
publicationlist = [
{
"publisher": "KK-PC",
"publisherdb": "DB01",
"publication": "repl_test_DB01",
"subscriber": "AA-PC",
"subscriberdb": "DB01",
},
{
"publisher": "KK-PC",
"publisherdb": "DB02",
"publication": "repl_test_DB02",
"subscriber": "AA-PC",
"subscriberdb": "DB02",
},
{
"publisher": "KK-PC",
"publisherdb": "DB03",
"publication": "repl_test_DB03",
"subscriber": "AA-PC",
"subscriberdb": "DB03",
},
{
"publisher": "KK-PC",
"publisherdb": "DB04",
"publication": "repl_test_DB04",
"subscriber": "AA-PC",
"subscriberdb": "DB04",
},
]
def main():
#连接数据库执行存储过程
#dbdate 保存存储过程结果;pbdate 保存名称
dbdate = []
pbdate = []
conn=pymssql.connect(host='.',database='distribution')
cur=conn.cursor()
for i in publicationlist:
sql = """
EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds
@publisher = N'"""+i["publisher"]+"""'
,@publisher_db = N'"""+i["publisherdb"]+"""'
,@publication = N'"""+i["publication"]+"""'
,@subscriber = N'"""+i["subscriber"]+"""'
,@subscriber_db = N'"""+i["subscriberdb"]+"""'
,@subscription_type =0"""
cur.execute(sql)
dbdate.append(cur.fetchall())
pbdate.append(i["publisher"]+"."+i["publisherdb"])
cur.close()
conn.close()
#配置推送的json格式,都添加到 payload 中
payload = []
data = {"endpoint":endpoint,"metric":metric,"timestamp":timestamp,"step":step,"value":value,"counterType":counterType,"tags":tags}
for item,repl in zip(dbdate,pbdate):
data = data.copy()
data["endpoint"] = endpoint
data["metric"] = metric + "pendingcmdcount"
data["timestamp"] = timestamp
data["step"] = step
data["value"] = item[0][0]
data["counterType"] = counterType
data["tags"] = tags + repl
payload.append(data)
data = data.copy()
data["endpoint"] = endpoint
data["metric"] = metric + "estimatedprocesstime"
data["timestamp"] = timestamp
data["step"] = step
data["value"] = item[0][1]
data["counterType"] = counterType
data["tags"] = tags + repl
payload.append(data)
r = requests.post("http://127.0.0.1:1988/v1/push", data=json.dumps(payload))
print r.text
if __name__ == "__main__":
main()


创建定时任务,每个5分钟执行一次。

 

 

 

最后

以上就是悦耳长颈鹿为你收集整理的Open-Falcon 使用 python 监控发布中未分发的命令数的全部内容,希望文章能够帮你解决Open-Falcon 使用 python 监控发布中未分发的命令数所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部