Example #1
0
def main():
    tt = True
    sleep_time = 0
    all_time = 0
    while True:
        try:
            con1 = ssdb.SSDB(host="118.123.9.75", port=57888)
            con2 = ssdb.SSDB(host="118.123.9.75", port=57878)
            list1 = con1.qlist(u"", u"", 999)
            list2 = con2.qlist(u"", u"", 999)
            if len(sys.argv) > 1:
                queue_names = sys.argv[1:]
                if tt:
                    sleep_time = filter(
                        lambda x: re.search("\d{%d}" % len(x), x), queue_names)
                    if sleep_time:
                        sleep_time = int(sleep_time[0])
                tt = False
                for queue_name in filter(
                        lambda x: re.search("\D{%d}" % len(x), x),
                        queue_names):
                    if queue_name in list1:
                        print u"《%s》列当前长度为:%d" % (queue_name,
                                                  con1.qsize(queue_name))
                    elif queue_name in list2:
                        print u"《%s》队列当前长度为:%d" % (queue_name,
                                                   con2.qsize(queue_name))
                    else:
                        print u"《%s》队列当前长度为:0" % queue_name
                        print u"《%s》在当前SSDB队列里没有数据,或者队列名输入错误,请检查" % queue_name
            else:
                print u"SSDB1的当前活动队列名为:"
                print "\t" + "\n\t".join(list1)
                print u"SSDB2的当前活动队列名为:"
                print "\t" + "\n\t".join(list2)
                print u"如果需要查看某个队列的长度:"
                print u"\teg: python ssdb_current_statistics.py queue_names 可以输入多个"
                print u"\teg: python ssdb_current_statistics.py beijing shanghai_2 sichuan"
                print u"可以在后面加上时间间隔,表示每隔几秒执行一次,时间可以放在任何位置"
                print u"\teg: python ssdb_current_statistics.py beijing shanghai_2 sichuan 5"
                print u"\teg: python ssdb_current_statistics.py beijing 5"
            if sleep_time:
                print u"wait time:%d" % sleep_time
                time.sleep(sleep_time)
            all_time += 1
            if all_time >= 20 or not sleep_time:
                break
        except Exception as e:
            print e
    def __init__(self, settings, stats=None):
        missing_params = []
        for param in [
                'HTTPCACHE_EXPIRATION_SECS', 'HTTPCACHE_SSDB_HOST',
                'HTTPCACHE_SSDB_PORT'
        ]:
            if not settings.get(param):
                missing_params.append(param)
        if missing_params:
            raise NotConfigured(
                "Can't initialize storage, missing params: %s" %
                ",".join(missing_params))

        self.expiration_secs = settings.getint('HTTPCACHE_EXPIRATION_SECS')

        self.ssdb_host = settings['HTTPCACHE_SSDB_HOST']
        self.ssdb_port = settings['HTTPCACHE_SSDB_PORT']

        try:
            self.ssdb = ssdb.SSDB(host=self.ssdb_host, port=self.ssdb_port)
            self.ssdb.get('asd')
        except ssdb.ConnectionError as e:
            raise NotConfigured(
                "Can't establish connection to SSDB server using host %s and port %s. Error: %s"
                % (self.ssdb_host, self.ssdb_port, str(e)))
Example #3
0
 def run(self):
     try:
         self.ssdb = ssdb.SSDB(host = self.ssdb_conf['host'], port = self.ssdb_conf['port'], password = self.ssdb_conf['password'])
         falcon_metrics = []
         # Statistics
         self.timestamp = int(time.time())
         ssdb_info = self.ssdb.info()
         # Original metrics
         for keyword in self.gauge_keywords:
             falcon_metric = self.new_metric("ssdb." + keyword, int(ssdb_info[keyword]))
             falcon_metrics.append(falcon_metric)
         for keyword in self.counter_keywords:
             falcon_metric = self.new_metric("ssdb." + keyword, int(ssdb_info[keyword]), type='COUNTER')
             falcon_metrics.append(falcon_metric)
         for level_stat in ssdb_info['leveldb']['stats']:
             for keyword in self.level_db_keywords:
                 falcon_metric = self.new_metric("ssdb.level_%d_%s" % (level_stat['Level'], keyword), level_stat[keyword])
                 falcon_metrics.append(falcon_metric)
         if self.falcon_conf['test_run']:
             print(json.dumps(falcon_metrics))
         else:
             req = requests.post(self.falcon_conf['push_url'], data=json.dumps(falcon_metrics))
             print(datetime.now(), "INFO: [%s]" % self.ssdb_conf['endpoint'], "[%s]" % self.falcon_conf['push_url'], req.text)
     except Exception as e:
         if self.falcon_conf['test_run']:
             raise
         else:
             print(datetime.now(), "ERROR: [%s]" % self.ssdb_conf['endpoint'], e)
Example #4
0
 def __init__(self, config):
     BaseCache.__init__(self, config)
     self.default_timeout = config.get('default_timeout', 0)
     self.key_prefix = config.get('key_prefix', '')
     try:
         import ssdb
         #patch ssdb
         import six
         import datetime
         ssdb.connection.iteritems = six.iteritems
         def expire(self, name, ttl):
             if isinstance(ttl, datetime.timedelta):
                 ttl = ttl.seconds + ttl.days * 24 * 3600
             return self.execute_command('expire', name, ttl)
         ssdb.SSDB.expire = expire
     except ImportError:
         raise RuntimeError('no ssdb module found')
     kwargs = dict((k, v) for k, v in config.items() if k not in _redis_kwargs_exclusions)
     if 'socket_timeout' not in kwargs:
         kwargs['socket_timeout'] = _DEFAULT_SOCKET_TIMEOUT
     if 'socket_connect_timeout' not in kwargs:
         kwargs['socket_connect_timeout'] = _DEFAULT_SOCKET_TIMEOUT
     if 'socket_keepalive' not in kwargs:
         kwargs['socket_keepalive'] = 1
     if 'socket_keepalive_options':
         kwargs['socket_keepalive_options'] = _TCP_KEEP_ALIVE_OPTIONS
     connection_pool = _SsdbConnectionPool(ssdb.Connection(**kwargs))
     self._client = ssdb.SSDB(connection_pool=connection_pool)
Example #5
0
 def __init__(self):
     server = SSHTunnelForwarder(ssh_address_or_host="14.17.121.132",
                                 ssh_password="******",
                                 ssh_port=13389,
                                 ssh_username="******",
                                 remote_bind_address=("10.0.0.14", 7779))
     server.start()
     print("test:", server.local_bind_port)
     self.ssdb = ssdb.SSDB(host="127.0.0.1",
                           port=server.local_bind_port,
                           charset='utf8')
Example #6
0
    def __init__(self, host, port, timeout=0, prefix='', **kw):
        Base.__init__(timeout)

        # Currently most ssdb clients have not been updated and have a lot of quirks
        # There are no clients for Python 3.4+ available that support all ssdb functions properly
        import warnings
        warnings.warn('SSDB cache is deprecated, avoid using',
                      DeprecationWarning)

        self.prefix = prefix
        kw['host'] = host
        kw['port'] = port
        if 'socket_timeout' not in kw:
            kw['socket_timeout'] = _DEFAULT_SOCKET_TIMEOUT
        try:
            # This module don't support PY3.4+
            import ssdb
            # Patch ssdb
            import datetime
            ssdb.connection.iteritems = six.iteritems

            def expire(self, name, ttl):
                if isinstance(ttl, datetime.timedelta):
                    ttl = ttl.seconds + ttl.days * 24 * 3600
                return self.execute_command('expire', name, ttl)

            ssdb.SSDB.expire = expire

            if 'socket_connect_timeout' not in kw:
                kw['socket_connect_timeout'] = _DEFAULT_SOCKET_TIMEOUT
            if 'socket_keepalive' not in kw:
                kw['socket_keepalive'] = 1
            if 'socket_keepalive_options' not in kw:
                kw['socket_keepalive_options'] = _TCP_KEEP_ALIVE_OPTIONS

            connection_pool = _SsdbConnectionPool(ssdb.Connection(**kw))
            self._client = ssdb.SSDB(connection_pool=connection_pool)
        except ImportError:
            try:
                # This module don't support socket keepalive yet, and do not support some features
                import pyssdb
                self._client = pyssdb.Client(**kw)
            except ImportError:
                raise RuntimeError('no ssdb module found')
Example #7
0
 def setUp(self):
     self.ssdb = ssdb.SSDB('127.0.0.1', 8888)
Example #8
0
 def setUp(self):
     self.client = ssdb.SSDB(host="192.168.1.105")
     self.client.execute_command("auth", "1" * 32)
Example #9
0
 def __init__(self):
     self.ssdb = ssdb.SSDB(SsdbHost["host"], SsdbHost["port"])