from flask import Flask #### https://docs.python-arango.com/en/main/ from arango import ArangoClient app = Flask(__name__) def get_top_dicks(): arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru') pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527') dicks_collection = pipisa_db.collection('dicks') dicks = dicks_collection.all( ) dicks = [[ d['user_fullname'], d['dick_size'], d['user_id'], d['chat_id'], d['attempts'], ] for d in dicks] return dicks @app.route('/metrics') def metrics(): metrics = "" docks = get_top_dicks() # текущий размер пипис for dick in docks: metrics += 'pipisio{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[1]) # текущее число попыток for dick in docks: metrics += 'pipisio_attempto{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[4]) # расстояние до следующего впереди for k in range(len(docks)): ### не самый красивый код для не самой красивой ситуации if k == 0: metrics += 'pipisio_topdick_distanso{user="%s", user_id="%s", chat_id="%s"} %s\n' % (docks[k][0], docks[k][2], docks[k][3], 0) else: i = k - 1 upper_dick_size = docks[i][1] while i > 0 and upper_dick_size == docks[k][1]: i -= 1 upper_dick_size = docks[i][1] metrics += 'pipisio_topdick_distanso{user="%s", user_id="%s", chat_id="%s"} %s\n' % (docks[k][0], docks[k][2], docks[k][3], (upper_dick_size - docks[k][1])) return metrics if __name__ == '__main__': app.run(host='0.0.0.0', port=9992)