def test_compute(): dt = datetime.now() dt1 = DateTools.update_time(dt) assert dt.minute == dt1.minute dt2 = DateTools.update_time(dt, minutes=2) if dt.minute < 57: assert dt.minute == dt2.minute - 2 else: assert dt.minute == dt2.minute + 60 - 2 dt3 = DateTools.update_time(dt, minutes=2, add=False) if dt.minute > 2: assert dt.minute == dt3.minute + 2 else: assert dt.minute == dt3.minute + 2 - 60
def metric(): metrics = [] su = SqlUtil() # 获取监控表 dt_now = datetime.now() dt = DateTools.update_time(dt_now, minutes=conf.monitor_frequency, add=False) monitors, err = su.get_monitor_data_gt_time(Monitor, time=dt) if err: print "%s Error: %s" % (DateTools.date_format(dt), err) else: for monitor in monitors: metrics.append( 'private_monitor_env{cluster="%s",type="%s", time="%s", detail="%s"} %d' % (monitor.cluster, monitor.type, monitor.time, monitor.detail, monitor.status)) # 获取服务主动监控表 clusters, err = su.get_cluster() if err: print "%s Error: %s" % (DateTools.date_format(dt), err) else: for cluster in clusters: metrics.append( 'private_monitor_env{cluster="%s",type="connect", time="%s", detail="%s"} %d' % (cluster.name, cluster.last_update, cluster.detail, cluster.status)) return metrics
def test_delete_monitor_data(): su = SqlUtil() ex_time = datetime.now() ex_time_s = DateTools.update_time(ex_time, minutes=1, add=False) res, err = su.delete_expire_monitor_data(ex_time_s) if err: print err print res
def test_get_gt_date(): dt = datetime.now() dt1 = DateTools.update_time(dt, days=2, add=False) su = SqlUtil() r1, _ = su.get_monitor_data_gt_time(Monitor, time=dt) r2, _ = su.get_monitor_data_gt_time(Monitor, time=dt1) assert not r1 assert r2 print r2
def data_expire_delete(): data_keep = conf.data_keep expire_time = DateTools.update_time(datetime.now(), days=data_keep, add=False) CronDataExpire.su.delete_expire_monitor_data(expire_time)