Example #1
0
def handle_not_found(error):
    pyformance.global_registry().counter("submit.error.404").inc()
    return make_response(
        render_template(
            "error.html",
            error=error),
        404)
Example #2
0
def handle_internal_server_error(error):
    response.status_code = 500
    pyformance.global_registry().counter("submit.error.500").inc()
    return make_response(
        render_template(
            "error.html",
            error=error),
        500)
Example #3
0
def handle_exception(error):
    if app.config['DEBUG']:
        raise

    error_string = str(error)
    status_code = 500
    pyformance.global_registry().counter("present.error.500").inc()

    return make_response(render_template("error.html", error=error_string),
                         status_code)
def handle_exception(error):
    error_string = str(error)
    if isinstance(error, RequestException) and error.response is not None:
        status_code = error.response.status_code
        pyformance.global_registry().counter("present.error.%d" %
                                             error.response.status_code).inc()
        error_string += ": %s" % error.response.json()
    else:
        status_code = 500
        pyformance.global_registry().counter("present.error.500").inc()
    return make_response(render_template("error.html", error=error_string),
                         status_code)
Example #5
0
def handle_requests_error(error):
    status_code = error.response.status_code
    pyformance.global_registry().counter("present.error.%d" %
                                         error.response.status_code).inc()

    if status_code != 500 and status_code in default_exceptions:
        description = default_exceptions[status_code].description
    elif app.config['DEBUG']:
        raise
    else:
        status_code = 500
        description = default_exceptions[500].description

    return make_response(render_template('error.html', error=description),
                         status_code)
Example #6
0
 def __init__(self,
              registry: MetricsRegistry = None,
              reporting_interval: int = 30) -> None:
     self.registry = registry or global_registry()
     self.reporting_interval = reporting_interval
     self._stopped = False
     self._handle: Optional[Task[None]] = None
Example #7
0
 def __init__(self, registry=None):
     import sys
     if registry is None:
         registry = pyformance.global_registry()
     self._registry = registry
     self._schemas = []
     global metrics_dict
     metrics_dict = Manager().dict(
     ) if 'rungunicornserver' in sys.argv else None
     self._metrics_dict = metrics_dict
Example #8
0
 def __init__(self, registry=None):
     if registry is None:
         registry = global_registry()
     self.registry = registry
Example #9
0
 def __init__(self, registry=None):
     if registry is None:
         registry = global_registry()
     self.registry = registry
     self._memory_usage = 0
Example #10
0
import json

app = Flask(__name__)
app.debug = 'DEBUG' in os.environ
socketio = SocketIO(app)
mongo_events.initialize('mongodb://127.0.0.1:27017/')
ld_logger = logging.getLogger('ldclient')
ld_logger.setLevel(logging.DEBUG)

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
ld_logger.addHandler(ch)

metrics_reporter = WebsocketReporter(registry=global_registry(), socketio=socketio, reporting_interval=1)
metrics_reporter.start()
# console_reporter = ConsoleReporter(registry=global_registry(), reporting_interval=5)
# console_reporter.start()

@app.route('/', methods=['GET'])
@time_calls
def dashboard():
  return render_template('dashboard.html')

@app.route('/events', methods=['POST'])
@time_calls
def events():
  content = request.get_json()
  if content is None:
    return '', 400
 def __init__(self, registry=None):
     if registry is None:
         registry = global_registry()
     self.registry = registry
def timer(key):
    return global_registry().timer(key).time()
Example #13
0
 def __init__(self, registry=None):
     if registry is None:
         registry = global_registry()
     self.registry = registry
     self._memory_usage = 0
Example #14
0
def handle_forbidden(error):
    pyformance.global_registry().counter("present.error.403").inc()
    return make_response(render_template("error.html", error=error), 403)
Example #15
0
 def timer(self, name: str, event: Optional[str] = None) -> Timer:
     if event is not None:
         return global_registry().timer(self._name(f"{name}.{event}"))
     else:
         return global_registry().timer(self._name(name))
Example #16
0
def handle_internal_server_error(error):
    pyformance.global_registry().counter("present.error.500").inc()
    return make_response(render_template("error.html", error=error), 500)
Example #17
0
 def __init__(self, registry=None):
   if registry is None:
     registry = pyformance.global_registry()
   self._registry = registry
   self._schemas = []
Example #18
0
 def __init__(self, registry=None):
     if registry is None:
         registry = pyformance.global_registry()
     self._registry = registry
     self._schemas = []
Example #19
0
RESPONSE = 'r'
QUERY = 'q'
ERROR = 'e'

BOOTSTRAP_NODES = (("router.bittorrent.com", 6881),
                   ("dht.transmissionbt.com", 6881), ("router.utorrent.com",
                                                      6881))

BIND_IP = '0.0.0.0'
BIND_PORT = 6881
MAX_NODE_SIZE = 1000
NODES = collections.deque(maxlen=MAX_NODE_SIZE)
TOKEN_LENGTH = 2
INTERVAL = 0.001
REGISTRY = global_registry()


def entropy(length=20):
    """Generate a hexadecimal string with input length

    Args:
        length: character length

    Returns:
    """
    return "".join(chr(randint(0, 255)) for _ in xrange(length))


def random_id(size=20):
    """generate node id