本文整理汇总了Python中pymongo.connection.Connection.sendall方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.sendall方法的具体用法?Python Connection.sendall怎么用?Python Connection.sendall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.connection.Connection
的用法示例。
在下文中一共展示了Connection.sendall方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Trending_broker
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import sendall [as 别名]
#.........这里部分代码省略.........
# Maybe this service is just unknown and without policies, if so, bail out
policies = self.svc_dict.get((data["host_name"], data["service_description"]), [])
if not policies:
return
# Ok there are some real policies
print "OK POLICIES FOR", (data["host_name"], data["service_description"]), policies
perf_data = data["perf_data"]
couples = self.get_metric_and_value(perf_data)
# If no values, we can exit now
if len(couples) == 0:
return
hname = data["host_name"] # self.illegal_char.sub('_', data['host_name'])
# if data['host_name'] in self.host_dict:
# customs_datas = self.host_dict[data['host_name']]
# if '_GRAPHITE_PRE' in customs_datas:
# hname = ".".join((customs_datas['_GRAPHITE_PRE'], hname))
sdesc = data["service_description"] # self.illegal_char.sub('_', data['service_description'])
# if (data['host_name'], data['service_description']) in self.svc_dict:
# customs_datas = self.svc_dict[(data['host_name'], data['service_description'])]
# if '_GRAPHITE_POST' in customs_datas:
# desc = ".".join((desc, customs_datas['_GRAPHITE_POST']))
check_time = int(data["last_chk"])
logger.debug(
"[Trending broker] Hostname: %s, Desc: %s, check time: %d, perfdata: %s, policies: %s"
% (hname, sdesc, check_time, str(perf_data), policies)
)
# Ok now the real stuff is here
for p in policies:
for (metric, value) in couples:
try:
value = float(value)
except ValueError:
return
if value is not None:
print "DUMPING", (metric, value), "for", p
sec_from_morning = get_sec_from_morning(check_time)
wday = get_wday(check_time)
chunk_nb = sec_from_morning / self.chunk_interval
# Now update mongodb
print "UPDATING DB", wday, chunk_nb, value, hname, sdesc, metric, type(value)
self.trender.update_avg(
self.col, check_time, wday, chunk_nb, value, hname, sdesc, metric, self.chunk_interval
)
# A host check result brok has just arrived, we UPDATE data info with this
def manage_host_check_result_brok(self, b):
return
data = b.data
perf_data = data["perf_data"]
couples = self.get_metric_and_value(perf_data)
# If no values, we can exit now
if len(couples) == 0:
return
hname = self.illegal_char.sub("_", data["host_name"])
if data["host_name"] in self.host_dict:
customs_datas = self.host_dict[data["host_name"]]
if "_GRAPHITE_PRE" in customs_datas:
hname = ".".join((customs_datas["_GRAPHITE_PRE"], hname))
check_time = int(data["last_chk"])
logger.debug(
"[Graphite broker] Hostname %s, check time: %d, perfdata: %s" % (hname, check_time, str(perf_data))
)
if self.graphite_data_source:
path = ".".join((hname, self.graphite_data_source))
else:
path = hname
if self.use_pickle:
# Buffer the performance data lines
for (metric, value) in couples:
if value:
self.buffer.append(("%s.__HOST__.%s" % (path, metric), ("%d" % check_time, "%s" % value)))
else:
lines = []
# Send a bulk of all metrics at once
for (metric, value) in couples:
if value:
lines.append("%s.__HOST__.%s %s %d" % (path, metric, value, check_time))
packet = "\n".join(lines) + "\n" # Be sure we put \n every where
logger.debug("[Graphite broker] Launching: %s" % packet)
self.con.sendall(packet)
示例2: Trending_broker
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import sendall [as 别名]
#.........这里部分代码省略.........
data = b.data
# Maybe this service is just unknown and without policies, if so, bail out
policies = self.svc_dict.get((data['host_name'], data['service_description']), [])
if not policies:
return
# Ok there are some real policies
print "OK POLICIES FOR", (data['host_name'], data['service_description']), policies
perf_data = data['perf_data']
couples = self.get_metric_and_value(perf_data)
# If no values, we can exit now
if len(couples) == 0:
return
hname = data['host_name']#self.illegal_char.sub('_', data['host_name'])
#if data['host_name'] in self.host_dict:
# customs_datas = self.host_dict[data['host_name']]
# if '_GRAPHITE_PRE' in customs_datas:
# hname = ".".join((customs_datas['_GRAPHITE_PRE'], hname))
sdesc = data['service_description']#self.illegal_char.sub('_', data['service_description'])
#if (data['host_name'], data['service_description']) in self.svc_dict:
# customs_datas = self.svc_dict[(data['host_name'], data['service_description'])]
# if '_GRAPHITE_POST' in customs_datas:
# desc = ".".join((desc, customs_datas['_GRAPHITE_POST']))
check_time = int(data['last_chk'])
logger.debug("[Trending broker] Hostname: %s, Desc: %s, check time: %d, perfdata: %s, policies: %s" % (hname, sdesc, check_time, str(perf_data), policies))
# Ok now the real stuff is here
for p in policies:
for (metric, value) in couples:
try:
value = float(value)
except ValueError:
return
if value is not None:
print "DUMPING", (metric, value), "for", p
sec_from_morning = get_sec_from_morning(check_time)
wday = get_wday(check_time)
chunk_nb = sec_from_morning / self.chunk_interval
# Now update mongodb
print "UPDATING DB", wday, chunk_nb, value, hname, sdesc, metric, type(value)
self.update_avg(wday, chunk_nb, value, hname, sdesc, metric)
# A host check result brok has just arrived, we UPDATE data info with this
def manage_host_check_result_brok(self, b):
return
data = b.data
perf_data = data['perf_data']
couples = self.get_metric_and_value(perf_data)
# If no values, we can exit now
if len(couples) == 0:
return
hname = self.illegal_char.sub('_', data['host_name'])
if data['host_name'] in self.host_dict:
customs_datas = self.host_dict[data['host_name']]
if '_GRAPHITE_PRE' in customs_datas:
hname = ".".join((customs_datas['_GRAPHITE_PRE'], hname))
check_time = int(data['last_chk'])
logger.debug("[Graphite broker] Hostname %s, check time: %d, perfdata: %s" % (hname, check_time, str(perf_data)))
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source))
else:
path = hname
if self.use_pickle:
# Buffer the performance data lines
for (metric, value) in couples:
if value:
self.buffer.append(("%s.__HOST__.%s" % (path, metric),
("%d" % check_time,
"%s" % value)))
else:
lines = []
# Send a bulk of all metrics at once
for (metric, value) in couples:
if value:
lines.append("%s.__HOST__.%s %s %d" % (path, metric,
value, check_time))
packet = '\n'.join(lines) + '\n' # Be sure we put \n every where
logger.debug("[Graphite broker] Launching: %s" % packet)
self.con.sendall(packet)