Exemplo n.º 1
0
def start_app(app=None):
    '''
    Starts the given application. If the application isn't present a new one is created.

    Args:
      app: Application that will be started.
    '''
    if not app:
        app = create_app()

    host = os.getenv('FLASK_HOST')
    port = os.getenv('FLASK_PORT')
    prometheus_port = int(os.getenv('PROMETHEUS_PORT'))
    monitor(app, port=prometheus_port)
    app.run(host=host, port=port, threaded=True)
Exemplo n.º 2
0
import logging
import datetime
import time
import socket

from flask import Flask, request
from flask_prometheus import monitor

app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.DEBUG)

hostname = socket.gethostname()
if "MESSAGE" in os.environ:
    message = os.getenv("MESSAGE")
else:
    message = "Hello, Avinash"


@app.route('/')
def index():
    timestamp = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    app.logger.debug("Finished at: " + timestamp)
    return timestamp + " " + message + "\n"


if __name__ == '__main__':
    misbehave = False
    monitor(app, port=8000)
    app.run(host='0.0.0.0', port=8080)
Exemplo n.º 3
0

@app.route('/', methods=["GET", "POST"])
def hi():
    if request.method == "GET":
        return "OK", 200, None

    return "Bad Request", 400, None


counter = prom.Counter('python_my_counter', 'This is my counter')
gauge = prom.Gauge('python_my_gauge', 'This is my gauge')
histogram = prom.Histogram('python_my_histogram', 'This is my histogram')
summary = prom.Summary('python_my_summary', 'This is my summary')


def thr():
    while True:
        counter.inc(random.random())
        gauge.set(random.random() * 15 - 5)
        histogram.observe(random.random() * 10)
        summary.observe(random.random() * 10)
        process_request(random.random() * 5)

        time.sleep(1)


Thread(target=thr).start()

monitor(app, port=8001)
app.run(host="0.0.0.0", port=8000)
Exemplo n.º 4
0
#!flask/bin/python
from flask import Flask
from flask_prometheus import monitor

app = Flask(__name__)


@app.route('/')
def index():
    return "Chris"


if __name__ == '__main__':
    monitor(app, port=8002)
    app.run(host='0.0.0.0', port=5002)
from flask import Flask
from flask_prometheus import monitor
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)

class Loan(Resource):
    def get(self):
        return {
            'loan_amount_due': 5000
        }

api.add_resource(Loan, '/')

monitor(app, port=9000)
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000)
Exemplo n.º 6
0

def queue_reading():
    # Queue connection
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=os.environ["RABBITMQ_CONNECTION"], port='5672'))
    channel = connection.channel()

    channel.queue_declare(queue='prom_queue', durable=True)

    def callback(ch, method, properties, body):
        print(" [x] Received %r" % body)
        #print(type(ast.literal_eval(body.decode('utf-8'))))
        print("bodyconverted ---- %s",body)
        bodyConverted = ast.literal_eval(body.decode('utf-8'))
        result = list(bodyConverted.keys())[0]
        print("result ---- %s",result)
        metricAnalysis(result)

    channel.basic_consume(queue='prom_queue', on_message_callback=callback, auto_ack=True)

    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()


Thread(target=queue_reading).start()

monitor(app, port=8080)
app.run(host="0.0.0.0", port=80)


Exemplo n.º 7
0
from flask import Flask, request, send_file
from flask_prometheus import monitor

import socket
import time

app = Flask(__name__)
monitor(app, port=6001)


@app.route("/")
def index():
    return "Hello world from k8s! Edition 1.8.2!!"


@app.route("/host")
def ip():
    return socket.gethostname()


@app.route("/headers")
def hello():
    return "<xmp>Headers:\n{}Remote Address:\n{}</xmp>".format(
        request.headers, request.remote_addr)


@app.route("/cpuload")
def cpuload():
    till = time.time() + 20  # 20 seconds load
    while (time.time() < till):
        pr = 213123
Exemplo n.º 8
0
from flask import Flask
from flask_prometheus import monitor
import json

app = Flask(__name__)


@app.route('/test', methods=['GET'])
def test():

    response = {"words": "new testing"}
    r = json.dumps(response)
    return r


if __name__ == '__main__':
    monitor(app, port=8000)  # monitor using with prometheus
    app.run(host='0.0.0.0', port=5000)
Exemplo n.º 9
0
        process.start()

    if processing:
        handler.start()

    return None


@app.route('/start', methods=['POST'])
def start():
    body = json.loads(request.data)
    crawl = body.get('crawl', True)
    processing = body.get('processing', False)
    items = body.get('items', [JamEnDoSpider, ZkSpider])
    sub_process = Process(target=process_run, args=(crawl, processing, items))
    sub_process.start()
    return 'OK'


@app.route('/metrics')
def metrics():
    registry = CollectorRegistry()
    multiprocess.MultiProcessCollector(registry)
    data = generate_latest(registry)
    return Response(data, mimetype=CONTENT_TYPE_LATEST)


if __name__ == '__main__':
    monitor(app, port=8081)
    app.run(host='0.0.0.0', port=8080)
Exemplo n.º 10
0
from flask import Flask, request, jsonify, send_file, redirect, Response
from flask_restful import Resource, Api
import requests
from flask_prometheus import monitor
import graph
import handlers
import os

# flask setup
app = Flask(__name__)
app.config.from_pyfile('../config.cfg')
monitor(app, port=app.config["METRICS_PORT"])
SHORTEST_PATH_TIMEOUT = int(app.config["SHORTEST_PATH_TIMEOUT"])
MAX_INT = 999999999.0
DEFAULT_LIMIT = 1000
# graph setup
file = os.environ['GRAPH_SAVE_PATH']
g = graph.Graph(file)

#########
## api ##
#########

# core functions
app.add_url_rule('/edges', "add edges", handlers.postEdges, methods=["POST"])
app.add_url_rule("/neighbors", "get neighbors", handlers.getNeighbors)
app.add_url_rule("/shortestPath", "get shortest path", handlers.shortestPath)
# structural porperties]
app.add_url_rule("/top", "computes top centrality properties for graph",
                 handlers.top)
app.add_url_rule("/centrality",