本文整理汇总了Python中rrdtool.fetch方法的典型用法代码示例。如果您正苦于以下问题:Python rrdtool.fetch方法的具体用法?Python rrdtool.fetch怎么用?Python rrdtool.fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rrdtool
的用法示例。
在下文中一共展示了rrdtool.fetch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def check(self, instance):
if rrdtool is None:
raise Exception("Unable to import python rrdtool module")
connection = self._get_connection()
self.log.debug("Connected to MySQL to fetch Cacti metadata")
# Get whitelist patterns, if available
patterns = self._get_whitelist_patterns(self.config.whitelist)
# Fetch the RRD metadata from MySQL
rrd_meta = self._fetch_rrd_meta(
connection, self.config.rrd_path, patterns, self.config.field_names, self.config.tags
)
# Load the metrics from each RRD, tracking the count as we go
metric_count = 0
for hostname, device_name, rrd_path in rrd_meta:
m_count = self._read_rrd(rrd_path, hostname, device_name, self.config.tags)
metric_count += m_count
self.gauge('cacti.metrics.count', metric_count, tags=self.config.tags)
示例2: dump_histogram_data
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def dump_histogram_data(self, period, step_in=None):
if step_in is not None:
step = int(step_in)
else:
step = int(RrdPeriod.PERIOD_1_HOUR_SEC)
rrd_end_ts = int(int(calendar.timegm(time.gmtime()) * step) / step)
rrd_start_ts = int(rrd_end_ts - int(period))
rrd_result = rrdtool.fetch(self.rrd_location, 'AVERAGE', '-r', str(step), '-s', str(rrd_start_ts), '-e',
str(rrd_end_ts))
rrd_start_ts_out, _, step = rrd_result[0]
rrd_current_ts = rrd_start_ts_out
periodic_cpu_usage = collections.defaultdict(lambda: 0.0)
periodic_mem_usage = collections.defaultdict(lambda: 0.0)
for _, cdp in enumerate(rrd_result[2]):
rrd_current_ts += step
if len(cdp) == 2:
try:
rrd_cdp_gmtime = time.gmtime(rrd_current_ts)
date_group = self.get_date_group(rrd_cdp_gmtime, period)
current_cpu_usage = round(100 * float(cdp[0]), KOA_CONFIG.db_round_decimals) / 100
current_mem_usage = round(100 * float(cdp[1]), KOA_CONFIG.db_round_decimals) / 100
periodic_cpu_usage[date_group] += current_cpu_usage
periodic_mem_usage[date_group] += current_mem_usage
except:
pass
return periodic_cpu_usage, periodic_mem_usage
示例3: read
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def read(self, ts_from, ts_to, filter = None):
ret = rrdtool.fetch(self.filename, 'MAX', '-s', str(ts_from), '-e', str(ts_to))
return ret
示例4: _get_rrd_fetch
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def _get_rrd_fetch(rrd_path, c, start):
return rrdtool.fetch(rrd_path, c, '--start', str(start))
示例5: _fetch_metric
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def _fetch_metric(cc, metric, type_=None,
cf='MAX', dt=86400, r=1800):
dirname = os.path.join(RRD_PATH, metric)
if type_ is None:
rrdname = os.listdir(dirname)[0]
type_ = rrdname.replace('.rrd', '')
else:
rrdname = type_+'.rrd'
if rrdname not in os.listdir(dirname):
raise RuntimeError('Unknown metric type')
cc.flush(identifier='minemeld/%s/%s' % (metric, type_))
(start, end, step), metrics, data = rrdtool.fetch(
str(os.path.join(dirname, rrdname)),
cf,
'--start', '-%d' % dt,
'--resolution', '%d' % r
)
result = []
if type_ != 'minemeld_delta':
curts = start
for v in data:
result.append([curts, v[0]])
curts += step
else:
curts = start+step
ov = data[0][0]
for v in data[1:]:
cv = v[0]
if cv is not None and ov is not None:
if cv >= ov:
cv = cv - ov
result.append([curts, cv])
ov = v[0]
curts += step
return result
示例6: dump_trend_data
# 需要导入模块: import rrdtool [as 别名]
# 或者: from rrdtool import fetch [as 别名]
def dump_trend_data(self, period, step_in=None):
now_epoch_utc = calendar.timegm(time.gmtime())
if step_in is not None:
step = int(step_in)
else:
step = int(RrdPeriod.PERIOD_1_HOUR_SEC)
rrd_end_ts_in = int(int(calendar.timegm(time.gmtime()) * step) / step)
rrd_start_ts_in = int(rrd_end_ts_in - int(period))
rrd_result = rrdtool.fetch(self.rrd_location, 'AVERAGE', '-r', str(step), '-s', str(rrd_start_ts_in), '-e',
str(rrd_end_ts_in))
rrd_start_ts_out, _, step = rrd_result[0]
rrd_current_ts = rrd_start_ts_out
res_usage = collections.defaultdict(list)
sum_res_usage = collections.defaultdict(lambda: 0.0)
for _, cdp in enumerate(rrd_result[2]):
rrd_current_ts += step
if len(cdp) == 2:
try:
rrd_cdp_gmtime = time.gmtime(rrd_current_ts)
current_cpu_usage = round(100 * float(cdp[0]), KOA_CONFIG.db_round_decimals) / 100
current_mem_usage = round(100 * float(cdp[1]), KOA_CONFIG.db_round_decimals) / 100
datetime_utc_json = time.strftime('%Y-%m-%dT%H:%M:%SZ', rrd_cdp_gmtime)
res_usage[ResUsageType.CPU].append(
'{"name":"%s","dateUTC":"%s","usage":%f}' % (self.dbname, datetime_utc_json, current_cpu_usage))
res_usage[ResUsageType.MEMORY].append(
'{"name":"%s","dateUTC":"%s","usage":%f}' % (self.dbname, datetime_utc_json, current_mem_usage))
sum_res_usage[ResUsageType.CPU] += current_cpu_usage
sum_res_usage[ResUsageType.MEMORY] += current_mem_usage
if calendar.timegm(rrd_cdp_gmtime) == int(
int(now_epoch_utc / RrdPeriod.PERIOD_1_HOUR_SEC) * RrdPeriod.PERIOD_1_HOUR_SEC):
PROMETHEUS_HOURLY_USAGE_EXPORTER.labels(self.dbname, ResUsageType.CPU.name).set(
current_cpu_usage)
PROMETHEUS_HOURLY_USAGE_EXPORTER.labels(self.dbname, ResUsageType.MEMORY.name).set(
current_mem_usage)
except:
pass
if sum_res_usage[ResUsageType.CPU] > 0.0 and sum_res_usage[ResUsageType.MEMORY] > 0.0:
return (','.join(res_usage[ResUsageType.CPU]), ','.join(res_usage[ResUsageType.MEMORY]))
else:
if step_in is None:
return self.dump_trend_data(period, step_in=RrdPeriod.PERIOD_5_MINS_SEC)
return '', ''