本文整理汇总了Python中opserver_util.OpServerUtils.utc_timestamp_usec方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.utc_timestamp_usec方法的具体用法?Python OpServerUtils.utc_timestamp_usec怎么用?Python OpServerUtils.utc_timestamp_usec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.utc_timestamp_usec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_uve
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import utc_timestamp_usec [as 别名]
#.........这里部分代码省略.........
continue
if typ not in statdict:
statdict[typ] = {}
statdict[typ][attr] = []
statsattr = json.loads(value)
for elem in statsattr:
#import pdb; pdb.set_trace()
edict = {}
if elem["rtype"] == "list":
elist = redish.lrange(elem["href"], 0, -1)
for eelem in elist:
jj = json.loads(eelem).items()
edict[jj[0][0]] = jj[0][1]
elif elem["rtype"] == "zset":
elist = redish.zrange(
elem["href"], 0, -1, withscores=True)
for eelem in elist:
tdict = json.loads(eelem[0])
tval = long(tdict["ts"])
dt = datetime.datetime.utcfromtimestamp(
float(tval) / 1000000)
tms = (tval % 1000000) / 1000
tstr = dt.strftime('%Y %b %d %H:%M:%S')
edict[tstr + "." + str(tms)] = eelem[1]
elif elem["rtype"] == "hash":
elist = redish.hgetall(elem["href"])
edict = elist
elif elem["rtype"] == "query":
if sfilter is None and mfilter is None and not multi:
qdict = {}
qdict["table"] = elem["aggtype"]
qdict["select_fields"] = elem["select"]
qdict["where"] =[[{"name":"name",
"value":key.split(":",1)[1],
"op":1}]]
qmap[elem["aggtype"]] = {"query":qdict,
"type":typ, "attr":attr}
# For the stats query case, defer processing
continue
statdict[typ][attr].append(
{elem["aggtype"]: edict})
continue
# print "Attr %s Value %s" % (attr, snhdict)
if attr not in state[key][typ]:
state[key][typ][attr] = {}
if dsource in state[key][typ][attr]:
print "Found Dup %s:%s:%s:%s:%s = %s" % \
(key, typ, attr, source, mdule, state[
key][typ][attr][dsource])
state[key][typ][attr][dsource] = snhdict[attr]
if len(qmap):
url = OpServerUtils.opserver_query_url(
self._local_redis_uve[0],
str(8081))
for t,q in qmap.iteritems():
try:
q["query"]["end_time"] = OpServerUtils.utc_timestamp_usec()
q["query"]["start_time"] = qdict["end_time"] - (3600 * 1000000)
json_str = json.dumps(q["query"])
resp = OpServerUtils.post_url_http(url, json_str, True)
if resp is not None:
edict = json.loads(resp)
edict = edict['value']
statdict[q["type"]][q["attr"]].append(
{t: edict})
except Exception as e:
print "Stats Query Exception:" + str(e)
if sfilter is None and mfilter is None:
for ptyp in redish.smembers("PTYPES:" + key):
afilter = None
if tfilter is not None:
if ptyp not in tfilter:
continue
afilter = tfilter[ptyp]
existing = redish.hgetall("PREVIOUS:" + key + ":" + ptyp)
nstate = UVEServer.convert_previous(
existing, state, key, ptyp, afilter)
state = copy.deepcopy(nstate)
pa = ParallelAggregator(state)
rsp = pa.aggregate(key, flat)
except redis.exceptions.ConnectionError:
self._logger.error("Failed to connect to redis-uve: %s:%d" \
% (redis_uve[0], redis_uve[1]))
except Exception as e:
self._logger.error("Exception: %s" % e)
return {}
else:
self._logger.debug("Computed %s" % key)
for k, v in statdict.iteritems():
if k in rsp:
mp = dict(v.items() + rsp[k].items())
statdict[k] = mp
return dict(rsp.items() + statdict.items())