2019-09-10 16:30:42 +02:00
|
|
|
"""
|
2019-12-19 12:24:53 +01:00
|
|
|
Network statistics
|
2019-09-10 16:30:42 +02:00
|
|
|
"""
|
2017-05-29 00:24:07 +02:00
|
|
|
import time
|
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
import asyncore_pollchoose as asyncore
|
2018-12-10 13:33:07 +01:00
|
|
|
from network.connectionpool import BMConnectionPool
|
|
|
|
from objectracker import missingObjects
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
lastReceivedTimestamp = time.time()
|
|
|
|
lastReceivedBytes = 0
|
|
|
|
currentReceivedSpeed = 0
|
|
|
|
lastSentTimestamp = time.time()
|
|
|
|
lastSentBytes = 0
|
|
|
|
currentSentSpeed = 0
|
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def connectedHostsList():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""List of all the connected hosts"""
|
2019-11-03 13:09:00 +01:00
|
|
|
return BMConnectionPool().establishedConnections()
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def sentBytes():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Sending Bytes"""
|
2017-08-09 17:36:52 +02:00
|
|
|
return asyncore.sentBytes
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def uploadSpeed():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Getting upload speed"""
|
|
|
|
# pylint: disable=global-statement
|
2017-05-29 00:24:07 +02:00
|
|
|
global lastSentTimestamp, lastSentBytes, currentSentSpeed
|
2017-08-09 17:36:52 +02:00
|
|
|
currentTimestamp = time.time()
|
|
|
|
if int(lastSentTimestamp) < int(currentTimestamp):
|
|
|
|
currentSentBytes = asyncore.sentBytes
|
2019-12-19 12:24:53 +01:00
|
|
|
currentSentSpeed = int(
|
|
|
|
(currentSentBytes - lastSentBytes) / (
|
|
|
|
currentTimestamp - lastSentTimestamp))
|
2017-08-09 17:36:52 +02:00
|
|
|
lastSentBytes = currentSentBytes
|
|
|
|
lastSentTimestamp = currentTimestamp
|
|
|
|
return currentSentSpeed
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def receivedBytes():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Receiving Bytes"""
|
2017-08-09 17:36:52 +02:00
|
|
|
return asyncore.receivedBytes
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def downloadSpeed():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Getting download speed"""
|
|
|
|
# pylint: disable=global-statement
|
2017-05-29 00:24:07 +02:00
|
|
|
global lastReceivedTimestamp, lastReceivedBytes, currentReceivedSpeed
|
2017-08-09 17:36:52 +02:00
|
|
|
currentTimestamp = time.time()
|
|
|
|
if int(lastReceivedTimestamp) < int(currentTimestamp):
|
|
|
|
currentReceivedBytes = asyncore.receivedBytes
|
2019-09-10 16:14:44 +02:00
|
|
|
currentReceivedSpeed = int(
|
2019-12-19 12:24:53 +01:00
|
|
|
(currentReceivedBytes - lastReceivedBytes) / (
|
|
|
|
currentTimestamp - lastReceivedTimestamp))
|
2017-08-09 17:36:52 +02:00
|
|
|
lastReceivedBytes = currentReceivedBytes
|
|
|
|
lastReceivedTimestamp = currentTimestamp
|
|
|
|
return currentReceivedSpeed
|
2017-05-29 00:24:07 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
def pendingDownload():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Getting pending downloads"""
|
2017-10-20 23:11:33 +02:00
|
|
|
return len(missingObjects)
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
|
|
|
|
def pendingUpload():
|
2019-09-10 16:30:42 +02:00
|
|
|
"""Getting pending uploads"""
|
2019-09-10 16:14:44 +02:00
|
|
|
# tmp = {}
|
|
|
|
# for connection in BMConnectionPool().inboundConnections.values() + \
|
|
|
|
# BMConnectionPool().outboundConnections.values():
|
|
|
|
# for k in connection.objectsNewToThem.keys():
|
|
|
|
# tmp[k] = True
|
|
|
|
# This probably isn't the correct logic so it's disabled
|
|
|
|
# return len(tmp)
|
2017-08-22 13:49:27 +02:00
|
|
|
return 0
|