示例#1
0
def send_api_response_time(prefix, start_time, end_time, url_rule, request_method, request_url):
    try:
        statsd_conf = Conf.get("statsd")
        if not statsd_conf["enabled"]:
            logging.info("Statsd disabled, not sending stats")
            return

        if not url_rule:
            logging.info("URL rule not found for url: [%s %s]" % (request_method, request_url))
            return

        components = []
        for c in url_rule.rule.split("/"):
            if not c: continue
            if c.startswith("<int:") and c.endswith(">"):
                components.append(c[5:-1])
            elif c.startswith("<path:") and c.endswith(">"):
                components.append(c[6:-1])
            elif c.startswith("<") and c.endswith(">"):
                components.append(c[1:-1])
            else:
                components.append(c)
        if not components or len(components) <= 0: components = ["home"]

        key = prefix + "." + ".".join(components) + "." + request_method
        delta = int((end_time - start_time).total_seconds() * 1000)

        logging.debug(
                "Sending stats to %s:%s [%s: %s]" % (statsd_conf["host"], statsd_conf["port"], key, delta))

        statsd_client = StatsdClient(statsd_conf["host"], statsd_conf["port"])
        statsd_client.timing(key, delta)
    except Exception as e:
        logging.error("Error in sending stats: %s" % e)
示例#2
0
 def get_engine(self):
     db_conf = Conf.get("event_database")
     db_baseurl = "mysql://%s/%s?charset=%s&user=%s&passwd=%s" % (
         db_conf["host"], db_conf["name"], db_conf["charset"], db_conf["user"], db_conf["password"])
     logging.info("DB Baseurl: %s, Init pool size: %s, Max pool size: %s, Pool recycle delay: %s" % (
         db_baseurl, db_conf["init_pool_size"], db_conf["max_pool_size"], db_conf["pool_recycle_delay"]))
     return create_engine(db_baseurl, echo=db_conf["sql_logging"], poolclass=QueuePool,
                          pool_size=db_conf["init_pool_size"],
                          max_overflow=int(db_conf["max_pool_size"]) - int(db_conf["init_pool_size"]),
                          pool_recycle=db_conf["pool_recycle_delay"])
示例#3
0
def sample_get(id):
    # Sample reding from config
    app_host = Conf.get("app_host")
    return json_response({"id": id, "app_host": app_host})
示例#4
0
 def get_api_timeout(timeout=None):
     if timeout:
         return int(timeout)
     else:
         int(Conf.get("api_timeout"))
 def get_api_timeout(timeout=None):
     if timeout:
         return int(timeout)
     else:
         int(Conf.get("api_timeout"))