def duration(self, note=''): now = time.time() elapsed_time = now - self._start log.info("[ Timer<%s> %s] from %s to %s , elapsed time %.3fs", id(self), note, format_time(self._start), format_time(now), elapsed_time) return elapsed_time
def do_write_metrics(): if store == 'ES': write() elif store == 'DB': data = list_realtime_metrics() log.info('inserting') insert_many_to_record(data) log.info('inserted')
def list_realtime_metrics(fmt=None): data = [] tms = int(time.time()) log.info('Reading process info... %s', tms) for p in psutil.process_iter(): data.append((tms, p.pid, p.name(), get_mem_size(p), float(format(p.cpu_percent(), '.2f')))) if fmt is None: return data elif fmt == 'json': return convert_json_from_lists(keys, data)
def write(): timer = Timer() process_info_list = list_realtime_metrics(fmt='json') timer.start() actions = [{ "_index": 'record', "_id": uuid.uuid1().hex.upper(), "_source": action } for action in process_info_list] res = helpers.bulk(es, actions) timer.duration('bulk') log.info(res)
def orange(): user_socket = request.environ.get('wsgi.websocket') log.info('request %s', request) log.info('user_socket %s', user_socket) if user_socket: user_socket_list.append(user_socket) log.info('user_socket_list depth %s', len(user_socket_list)) while True: try: msg = user_socket.receive() log.info('received: %s', msg) for sock in user_socket_list: try: sock.send('received: %s' + msg) except: continue except Exception as e: log.error(e) if user_socket and user_socket in user_socket_list: user_socket_list.remove(user_socket) return ''
def select_all_monprocess(): return PySqlTemplate.statement('select * from monprocess').list_json() def select_from_record(start, end): conn = sqlite3.connect(db) cur = conn.cursor() cur.execute( "select * from record where timestamp between ? and ? order by timestamp", (start, end)) return cur.fetchall() def select_from_record_filter(start, end, processfilter): conn = sqlite3.connect(db) cur = conn.cursor() cur.execute( "select * from record where pname=? and timestamp between ? and ? order by timestamp", (processfilter, start, end)) return cur.fetchall() def close_resource(cur, conn): cur.close() conn.close() if __name__ == "__main__": log.info(select_all_monprocess())
def test_yaml(): conf = util.load_yaml('config/application.yml') log.info(conf)
def insert_monprocess(): parm = request.args.to_dict() log.info(parm) DataProcessor.insert_monprocess(parm) return {'code': 1, 'msg': 'success'}
@app.route('/query_range') def query_range(): parm = request.args.to_dict() processfilter = parm.get('processfilter') wildcard = '' if processfilter is not '': wildcard = re.sub(',', "','", "'" + processfilter + "'") log.warn(wildcard) start = parm.get('start') now = time.time() if start is None: start = now - 300 end = parm.get('end') if end is None: end = now return DataProcessor.query(start, end, wildcard) if __name__ == "__main__": scheduler_thread = threading.Thread(target=start, args=()) scheduler_thread.setDaemon(True) scheduler_thread.start() log.info(u'Scheduler Started.') srv = WSGIServer(('0.0.0.0', 5000), app, handler_class=WebSocketHandler, log=log) log.info(u'Started Server.') srv.serve_forever() shutdown()
""" Start script (enter point of the whole application)""" import sys from PyQt5.QtWidgets import QApplication from app.ui.main_window import MainWindow from app.util.logger import log if __name__ == '__main__': log.info('begin main') # ----Запускаем главное окно---- app = QApplication(sys.argv) qWind = MainWindow() qWind.show() rez = app.exec_() log.info('end main') sys.exit(rez)
def request_update_status(): log.info('Starting job %s', int(time.time())) do_write_metrics() log.info('Finish job %s', int(time.time()))