mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 14:41:43 +00:00
RemoteRepository: account rx/tx bytes
This commit is contained in:
parent
4862efe718
commit
f3c7e7cd36
1 changed files with 9 additions and 1 deletions
|
@ -507,6 +507,8 @@ def __init__(self, location, create=False, exclusive=False, lock_wait=None, lock
|
||||||
self.location = self._location = location
|
self.location = self._location = location
|
||||||
self.preload_ids = []
|
self.preload_ids = []
|
||||||
self.msgid = 0
|
self.msgid = 0
|
||||||
|
self.rx_bytes = 0
|
||||||
|
self.tx_bytes = 0
|
||||||
self.to_send = b''
|
self.to_send = b''
|
||||||
self.chunkid_to_msgids = {}
|
self.chunkid_to_msgids = {}
|
||||||
self.ignore_responses = set()
|
self.ignore_responses = set()
|
||||||
|
@ -607,6 +609,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
# in any case, we want to cleanly close the repo, even if the
|
# in any case, we want to cleanly close the repo, even if the
|
||||||
# rollback can not succeed (e.g. because the connection was
|
# rollback can not succeed (e.g. because the connection was
|
||||||
# already closed) and raised another exception:
|
# already closed) and raised another exception:
|
||||||
|
logger.debug('RemoteRepository: %d bytes sent, %d bytes received, %d messages sent',
|
||||||
|
self.tx_bytes, self.rx_bytes, self.msgid)
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -728,6 +732,7 @@ def handle_error(unpacked):
|
||||||
data = os.read(fd, BUFSIZE)
|
data = os.read(fd, BUFSIZE)
|
||||||
if not data:
|
if not data:
|
||||||
raise ConnectionClosed()
|
raise ConnectionClosed()
|
||||||
|
self.rx_bytes += len(data)
|
||||||
self.unpacker.feed(data)
|
self.unpacker.feed(data)
|
||||||
for unpacked in self.unpacker:
|
for unpacked in self.unpacker:
|
||||||
if isinstance(unpacked, dict):
|
if isinstance(unpacked, dict):
|
||||||
|
@ -752,6 +757,7 @@ def handle_error(unpacked):
|
||||||
data = os.read(fd, 32768)
|
data = os.read(fd, 32768)
|
||||||
if not data:
|
if not data:
|
||||||
raise ConnectionClosed()
|
raise ConnectionClosed()
|
||||||
|
self.rx_bytes += len(data)
|
||||||
data = data.decode('utf-8')
|
data = data.decode('utf-8')
|
||||||
for line in data.splitlines(keepends=True):
|
for line in data.splitlines(keepends=True):
|
||||||
handle_remote_line(line)
|
handle_remote_line(line)
|
||||||
|
@ -785,7 +791,9 @@ def handle_error(unpacked):
|
||||||
|
|
||||||
if self.to_send:
|
if self.to_send:
|
||||||
try:
|
try:
|
||||||
self.to_send = self.to_send[self.ratelimit.write(self.stdin_fd, self.to_send):]
|
written = self.ratelimit.write(self.stdin_fd, self.to_send)
|
||||||
|
self.tx_bytes += written
|
||||||
|
self.to_send = self.to_send[written:]
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
# io.write might raise EAGAIN even though select indicates
|
# io.write might raise EAGAIN even though select indicates
|
||||||
# that the fd should be writable
|
# that the fd should be writable
|
||||||
|
|
Loading…
Reference in a new issue