Ejemplo n.º 1
0
def fetch_last_n_days(n: int) -> Tuple[Questions, Answers]:
    end = dt.datetime.now()
    start = end - dt.timedelta(seconds=n * 24 * 60 * 60)
    api_client = APIClient()
    questions = api_client.questions(start=start, end=end)
    answers = api_client.answers(questions)
    return questions, answers
Ejemplo n.º 2
0
 def __init__(self, env_url):
     session = requests.Session()
     self.api = APIClient(env_url)
     self.api.session = session
     #self.jwt = JWTClient(env_url)
     #self.jwt.session = session
     self.oauth = Oauth(env_url)
     self.oauth.session = session
Ejemplo n.º 3
0
    def __init__(self, account='', login='', password=''):
        self.Account, self.Login, self.Password = account, login, password

        self._client = APIClient()
        self._data = str()

        self._AccessId = str()
        self._SecretKey = str()
Ejemplo n.º 4
0
    def __init__(self, client_id, username='', password='', token='', code=''):
        self._ClientId = client_id
        self._Username = username
        self._Password = password
        self._Token = token
        self._Code = code

        self._client = APIClient()
        self._client.UserAgent = self._UserAgent
        self._data = ''
Ejemplo n.º 5
0
    def sign_in(self):

        self.user = self.userLineEdit.text()
        self.pw = self.passwordLineEdit.text()

        self.conn = APIClient(user=self.user, pw=self.pw)

        if self.rememberMeCheckBox.isChecked():
            self.config.set_login_info(self.user, self.pw)
        else:
            self.config.erase_login_info()

        resp = self.conn.get_my_capabilities()

        if resp.code != 200:
            # Catch the error specified by the API..

            tree = ElementTree.fromstring(resp.read())

            elt_err = tree.find(r"./erreur")
            if elt_err.text:
                msg = elt_err.text
            else:
                # Error returned by the server (all other cases)..
                msg = str(resp)

            # Then display the error in a message box..
            return QMessageBox.warning(self, r"Warning", msg)

        tree = ElementTree.fromstring(resp.read())

        # On connection success, get user's capability informations..

        elt_extract = tree.find(r"./cle_api_rfu/extraction_rfu")
        if elt_extract.text == r"oui":
            self.conn.extract = True

        elt_extract_lim = tree.find(r"./cle_api_rfu/extraction_rfu_limite")
        if elt_extract_lim.text is not None:
            self.conn.extract_lim = int(elt_extract_lim.text)

        elt_update = tree.find(r"./cle_api_rfu/mise_a_jour_rfu")
        if elt_update.text == r"oui":
            self.conn.update = True

        # Then..
        self.accept()

        self.opened.emit()
Ejemplo n.º 6
0
async def run(parameters):
    loop = asyncio.get_event_loop()
    clients = {}
    async with aiohttp.ClientSession(loop=loop) as session:
        for region in parameters["regions"]:
            clients[region] = APIClient(region, session, parameters["key"],
                                        parameters["data_path"])
        # Await until ctrl+c
        while not lissandra.exiting:
            await asyncio.sleep(1)

        # Exiting, shutdown nicely
        for client in clients.values():
            client.exiting = True
        for client in clients.values():
            await client.shutdown.wait()
Ejemplo n.º 7
0
    def __init__(self, container_id, configs={}):
        # initial backend.
        self.backend = BackendFactory(configs["backend"]["name"])(
            configs=configs
        )

        self.interval = configs["collect_interval"]
        self.client = APIClient(configs)
        self.configs = configs

        # initial modules.
        # query the CMonitor configured modules,
        # and sync them into application container.
        self.client.sync_modules(container_id)

        super(ContainerAppMetricsCollector, self).__init__(container_id,
                                                           configs)
Ejemplo n.º 8
0
    def housekeeping(cls, configs={}):
        '''
        another background process, clean up the out-of-date textfile metrics.
        we assumed that there is ONLY 1 layer files under the `data_dir`.
        '''
        data_dir = configs["backend"]["data_dir"]
        prom_textfile_style = configs["backend"]["prom_textfile_style"]
        prom_textfiles = glob.glob(data_dir + prom_textfile_style)
        client = APIClient(configs)

        current_container_ids = [cnter["Id"] for cnter in client.containers()]
        for metric_file in prom_textfiles:
            has_metric = False
            for container_id in current_container_ids:
                if container_id in metric_file:
                    has_metric = True
                    break
                else:
                    continue

            if not has_metric:
                # clean up the out-of-date metric!
                os.remove(metric_file)
                print "Cleaned out-of-date metric file: {}".format(metric_file)
Ejemplo n.º 9
0
def main():
    global LIVE_CONTAINERS

    print "CMonitor starting...\n"

    # Workaround for multithread _strptime bug: https://groups.google.com/forum/#!topic/comp.lang.python/VFIppfWTblw
    datetime.datetime.strptime("2015-04-05T14:20:00", "%Y-%m-%dT%H:%M:%S")

    # register signal
    signal.signal(signal.SIGTERM, sigterm_clean)
    signal.signal(signal.SIGINT, sigterm_clean)

    # load configs.
    # TODO: make it as a startup parameter.
    configs = {}
    config_file = os.getenv('CONFIG', '/config/config.yml')
    with open(config_file, 'r') as fp:
        configs = yaml.load(fp)

    cli = APIClient(configs=configs)

    # startup container metrics collector
    check_interval = configs["check_interval"]
    startup_containers = cli.containers()
    for c in startup_containers:
        print "Starting ContainerAppMetricsCollector for {}\n".format(c["Id"])
        app_t = ContainerAppMetricsCollector(c["Id"], configs)
        app_t.setDaemon(True)
        app_t.start()

        LIVE_CONTAINERS[c["Id"]] = [app_t, ]

    print "CMonitor started...\n"
    while True:
        time.sleep(check_interval)

        # Backend housekeeping.
        # We setup a workaround here right now.
        BackendFactory(configs["backend"]["name"]).housekeeping(configs)

        # recollect all live containers states
        # now, we just mark up unknown as offline state.
        cstates = {}
        now_alive_containers = cli.containers()
        for c in now_alive_containers:
            cstates[c["Id"]] = c["State"]

        offlined_containers = set(LIVE_CONTAINERS.keys()) - set(cstates.keys())
        onlined_containers = set(cstates.keys()) - set(LIVE_CONTAINERS.keys())

        # rebuild live container crashed thread.
        for cid, crashed_t in LIVE_CONTAINERS.iteritems():
            if crashed_t[0] is None or not crashed_t[0].is_alive():
                app_t = ContainerAppMetricsCollector(cid, configs)
                app_t.setDaemon(True)
                app_t.start()

                print "Rebuild crashed app metrics thread for {}\n".format(cid)
                LIVE_CONTAINERS[cid][0] = app_t
            else:
                pass

        # offline some
        for offlineId in offlined_containers:
            try:
                LIVE_CONTAINERS[offlineId][0].stop()
                del LIVE_CONTAINERS[offlineId]
                print "Stopped or deleted old container {}\n".format(offlineId)
            except Exception, e:
                print "ERROR while stopping the container {} collector, may already stopped!!!\n".format(offlineId)
                continue

        # online some
        for onlineId in onlined_containers:
            try:
                app_t = ContainerAppMetricsCollector(onlineId, configs)
                app_t.setDaemon(True)
                app_t.start()

                LIVE_CONTAINERS[onlineId] = [app_t, ]
                print "appending new container {}, now lives {}\n".format(onlineId, LIVE_CONTAINERS.keys())
            except Exception, e:
                print "Container {} append to LIVE_CONTAINERS ERROR, {}\n".format(onlineId, e)
                continue
Ejemplo n.º 10
0
 def __init__(self, key_file=None, cert_file=None):
     self._client = APIClient(key_file, cert_file)
     self._client.UserAgent = self._UserAgent
     self._data = ''