Show More
@@ -19,9 +19,11 b'' | |||||
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import os |
|
21 | import os | |
|
22 | import re | |||
22 | import time |
|
23 | import time | |
23 | import datetime |
|
24 | import datetime | |
24 | import dateutil |
|
25 | import dateutil | |
|
26 | ||||
25 | from rhodecode.model.db import DbSession, Session |
|
27 | from rhodecode.model.db import DbSession, Session | |
26 |
|
28 | |||
27 |
|
29 | |||
@@ -140,11 +142,51 b' class FileAuthSessions(BaseAuthSessions)' | |||||
140 | return stats['callbacks'] |
|
142 | return stats['callbacks'] | |
141 |
|
143 | |||
142 |
|
144 | |||
|
145 | ||||
143 | class MemcachedAuthSessions(BaseAuthSessions): |
|
146 | class MemcachedAuthSessions(BaseAuthSessions): | |
144 | SESSION_TYPE = 'ext:memcached' |
|
147 | SESSION_TYPE = 'ext:memcached' | |
|
148 | _key_regex = re.compile(r'ITEM (.*_session) \[(.*); (.*)\]') | |||
|
149 | ||||
|
150 | def _get_client(self): | |||
|
151 | import memcache | |||
|
152 | client = memcache.Client([self.config.get('beaker.session.url')]) | |||
|
153 | return client | |||
|
154 | ||||
|
155 | def _get_telnet_client(self, host, port): | |||
|
156 | import telnetlib | |||
|
157 | client = telnetlib.Telnet(host, port, None) | |||
|
158 | return client | |||
|
159 | ||||
|
160 | def _run_telnet_cmd(self, client, cmd): | |||
|
161 | client.write("%s\n" % cmd) | |||
|
162 | return client.read_until('END') | |||
|
163 | ||||
|
164 | def key_details(self, client, slab_ids, limit=100): | |||
|
165 | """ Return a list of tuples containing keys and details """ | |||
|
166 | cmd = 'stats cachedump %s %s' | |||
|
167 | for slab_id in slab_ids: | |||
|
168 | for key in self._key_regex.finditer( | |||
|
169 | self._run_telnet_cmd(client, cmd % (slab_id, limit))): | |||
|
170 | yield key | |||
145 |
|
171 | |||
146 | def get_count(self): |
|
172 | def get_count(self): | |
147 | return self.NOT_AVAILABLE |
|
173 | client = self._get_client() | |
|
174 | count = self.NOT_AVAILABLE | |||
|
175 | try: | |||
|
176 | slabs = [] | |||
|
177 | for server, slabs_data in client.get_slabs(): | |||
|
178 | slabs.extend(slabs_data.keys()) | |||
|
179 | ||||
|
180 | host, port = client.servers[0].address | |||
|
181 | telnet_client = self._get_telnet_client(host, port) | |||
|
182 | keys = self.key_details(telnet_client, slabs) | |||
|
183 | count = 0 | |||
|
184 | for _k in keys: | |||
|
185 | count += 1 | |||
|
186 | except Exception: | |||
|
187 | return count | |||
|
188 | ||||
|
189 | return count | |||
148 |
|
190 | |||
149 | def get_expired_count(self, older_than_seconds=None): |
|
191 | def get_expired_count(self, older_than_seconds=None): | |
150 | return self.NOT_AVAILABLE |
|
192 | return self.NOT_AVAILABLE |
General Comments 0
You need to be logged in to leave comments.
Login now