本文整理汇总了Python中steelscript.netprofiler.core.filters.TimeFilter.profiler_minutes方法的典型用法代码示例。如果您正苦于以下问题:Python TimeFilter.profiler_minutes方法的具体用法?Python TimeFilter.profiler_minutes怎么用?Python TimeFilter.profiler_minutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类steelscript.netprofiler.core.filters.TimeFilter
的用法示例。
在下文中一共展示了TimeFilter.profiler_minutes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_traffic
# 需要导入模块: from steelscript.netprofiler.core.filters import TimeFilter [as 别名]
# 或者: from steelscript.netprofiler.core.filters.TimeFilter import profiler_minutes [as 别名]
def generate_traffic(self, activity, legend_keys, report_type):
""" Generate traffic data during the time the user was logged-in.
"""
cache = {}
combined_activity = []
for event in activity:
# handle dns names in host along with IP address
host = event[0].split('|', 1)[0]
timefilter = TimeFilter(string_to_datetime(event[1]),
string_to_datetime(event[2]))
# if event occurs in less than a minute, add extra minute to report
while len(timefilter.profiler_minutes()) == 1:
timefilter.end += datetime.timedelta(minutes=1)
# normalize times to minute increments
mins = timefilter.profiler_minutes()
tf = TimeFilter(mins[0], mins[-1])
if self.options.usecache and report_type == 'timeseries':
# only consider a hit when whole time period is covered
minutes = tf.profiler_minutes(astimestamp=True)
if host in cache and all(t in cache[host] for t in minutes):
data = [cache[host][t] for t in minutes]
else:
legend, data = self.traffic_report(host, tf, report_type)
# store results in cache by host->times->data
cache.setdefault(host, {}).update((int(x[0]), x) for x in data)
else:
legend, data = self.traffic_report(host, tf, report_type)
if data:
if self.options.aggregate and report_type == 'timeseries':
# generate running averages over data samples received
# first convert empty strings to zeros, then run averages
columns = map(lambda c: [0 if x == '' else x for x in c],
itertools.izip(*data))
aggmap = [x[1] for x in TCOLUMNS]
aggregates = [aggmap[i](x) for i, x in enumerate(columns)]
combined_activity.append(list(event) + aggregates)
elif report_type == 'timeseries' or report_type == 'summary':
# create entry for each element in report
for row in data:
r = ['--' if x == '' else x for x in row]
combined_activity.append(list(event) + r)
else:
raise RuntimeError('unknown report type: %s' % report_type)
else:
# populate result with blanks
combined_activity.append(list(event) + ['--'] * len(legend))
traffic_legend = [c.key for c in legend]
legend = legend_keys + traffic_legend
return legend, combined_activity