def add_bytes(time, address, nbytes, seconds): if 0 == nbytes: return # no point saving an empty entry bandwidth = float(nbytes)/seconds message = 'internet.bandwidth.{} {} {}'.format(address, int(bandwidth), int(timestamp(time))) send(message)
def log_write(x): mysql_log = open(conf.MYSQL_LOG_FILE, "a+") mysql_log.write("[%s] %s\n" % (misc.timestamp(), x)) mysql_log.close()
def cpu_time_stdoutln(line): if cpu_time_output_enabled: stdout("[%s] CPU_TIME %s\n" % (misc.timestamp(), line))
def warning_stdoutln(line): stdout("[%s] Warning: %s\n" % (misc.timestamp(), line))
def debug_stdoutln(line): if debug_output_enabled: stdout("[%s] %s\n" % (misc.timestamp(), line))
def stdoutln(line): stdout("[%s] %s\n" % (misc.timestamp(), line))
def add_usage(time, user): message = 'internet.usage.{} 1 {}'.format(user, int(timestamp(time))) send(message)
def add_counter(time, user, counter): message = 'internet.counter.{} {} {}'.format(user, counter, int(timestamp(time))) send(message)
def wait_for_next(period): ts = timestamp(datetime.datetime.utcnow()) time.sleep(period - (ts % period))