get_stats in core
This commit is contained in:
parent
5d19e72ab4
commit
d6a3c55efa
|
@ -79,7 +79,7 @@ class Core(
|
||||||
self.client_address = None
|
self.client_address = None
|
||||||
|
|
||||||
self.prefmanager = PreferencesManager()
|
self.prefmanager = PreferencesManager()
|
||||||
|
|
||||||
# Get config
|
# Get config
|
||||||
self.config = deluge.configmanager.ConfigManager("core.conf")
|
self.config = deluge.configmanager.ConfigManager("core.conf")
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class Core(
|
||||||
# Start the libtorrent session
|
# Start the libtorrent session
|
||||||
log.debug("Starting libtorrent session..")
|
log.debug("Starting libtorrent session..")
|
||||||
self.session = lt.session(fingerprint)
|
self.session = lt.session(fingerprint)
|
||||||
|
|
||||||
# Load the session state if available
|
# Load the session state if available
|
||||||
self.load_session_state()
|
self.load_session_state()
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ class Core(
|
||||||
|
|
||||||
# New release check information
|
# New release check information
|
||||||
self.new_release = None
|
self.new_release = None
|
||||||
|
|
||||||
component.start()
|
component.start()
|
||||||
|
|
||||||
self._should_shutdown = False
|
self._should_shutdown = False
|
||||||
|
@ -235,10 +235,10 @@ class Core(
|
||||||
# Save the DHT state if necessary
|
# Save the DHT state if necessary
|
||||||
if self.config["dht"]:
|
if self.config["dht"]:
|
||||||
self.save_dht_state()
|
self.save_dht_state()
|
||||||
|
|
||||||
# Save the libtorrent session state
|
# Save the libtorrent session state
|
||||||
self.save_session_state()
|
self.save_session_state()
|
||||||
|
|
||||||
# Shutdown the socket
|
# Shutdown the socket
|
||||||
try:
|
try:
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
|
@ -265,7 +265,7 @@ class Core(
|
||||||
lt.bencode(self.session.state()))
|
lt.bencode(self.session.state()))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Failed to save lt state: %s", e)
|
log.warning("Failed to save lt state: %s", e)
|
||||||
|
|
||||||
def load_session_state(self):
|
def load_session_state(self):
|
||||||
"""Loads the libtorrent session state"""
|
"""Loads the libtorrent session state"""
|
||||||
try:
|
try:
|
||||||
|
@ -273,7 +273,7 @@ class Core(
|
||||||
open(deluge.common.get_default_config_dir("session.state"), "rb").read()))
|
open(deluge.common.get_default_config_dir("session.state"), "rb").read()))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Failed to load lt state: %s", e)
|
log.warning("Failed to load lt state: %s", e)
|
||||||
|
|
||||||
def save_dht_state(self):
|
def save_dht_state(self):
|
||||||
"""Saves the dht state to a file"""
|
"""Saves the dht state to a file"""
|
||||||
try:
|
try:
|
||||||
|
@ -301,7 +301,7 @@ class Core(
|
||||||
self.signals.emit("new_version_available", self.new_release)
|
self.signals.emit("new_version_available", self.new_release)
|
||||||
return self.new_release
|
return self.new_release
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Exported Methods
|
# Exported Methods
|
||||||
def export_ping(self):
|
def export_ping(self):
|
||||||
"""A method to see if the core is running"""
|
"""A method to see if the core is running"""
|
||||||
|
@ -349,6 +349,32 @@ class Core(
|
||||||
# Run the plugin hooks for 'post_torrent_add'
|
# Run the plugin hooks for 'post_torrent_add'
|
||||||
self.plugins.run_post_torrent_add(torrent_id)
|
self.plugins.run_post_torrent_add(torrent_id)
|
||||||
|
|
||||||
|
|
||||||
|
def export_get_stats(self):
|
||||||
|
"""
|
||||||
|
returns: {
|
||||||
|
'download_rate':float(),
|
||||||
|
'upload_rate':float(),
|
||||||
|
'num_connections':int(),
|
||||||
|
'dht_nodes',int(),
|
||||||
|
'max_num_connections':int(),
|
||||||
|
'max_download':float(),
|
||||||
|
'max_upload':float()
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
#dynamic stats:
|
||||||
|
"download_rate":self.session.status().payload_download_rate,
|
||||||
|
"upload_rate":self.session.status().payload_upload_rate,
|
||||||
|
"num_connections":self.session.num_connections(),
|
||||||
|
"dht_nodes":self.session.status().dht_nodes,
|
||||||
|
#max config values:
|
||||||
|
"max_download":self.config["max_download_speed"],
|
||||||
|
"max_upload":self.config["max_upload_speed"],
|
||||||
|
"max_num_connections":self.config["max_connections_global"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def export_add_torrent_url(self, url, save_path, options):
|
def export_add_torrent_url(self, url, save_path, options):
|
||||||
log.info("Attempting to add url %s", url)
|
log.info("Attempting to add url %s", url)
|
||||||
|
|
||||||
|
@ -524,7 +550,7 @@ class Core(
|
||||||
"""Sets the torrent options for torrent_ids"""
|
"""Sets the torrent options for torrent_ids"""
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
self.torrents[torrent_id].set_options(options)
|
self.torrents[torrent_id].set_options(options)
|
||||||
|
|
||||||
def export_set_torrent_trackers(self, torrent_id, trackers):
|
def export_set_torrent_trackers(self, torrent_id, trackers):
|
||||||
"""Sets a torrents tracker list. trackers will be [{"url", "tier"}]"""
|
"""Sets a torrents tracker list. trackers will be [{"url", "tier"}]"""
|
||||||
return self.torrents[torrent_id].set_trackers(trackers)
|
return self.torrents[torrent_id].set_trackers(trackers)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
from deluge.ui.client import sclient
|
||||||
|
sclient.set_core_uri()
|
||||||
|
|
||||||
|
for key, val in sclient.get_stats().iteritems():
|
||||||
|
print "%s:%s" % (key,val)
|
|
@ -81,7 +81,7 @@ class json_rpc:
|
||||||
* methods : http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi
|
* methods : http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi
|
||||||
"""
|
"""
|
||||||
#extra exposed methods
|
#extra exposed methods
|
||||||
json_exposed = ["update_ui","get_stats","system_listMethods",
|
json_exposed = ["update_ui","system_listMethods",
|
||||||
"get_webui_config","set_webui_config","get_webui_templates"]
|
"get_webui_config","set_webui_config","get_webui_templates"]
|
||||||
cache = {}
|
cache = {}
|
||||||
|
|
||||||
|
@ -139,36 +139,6 @@ class json_rpc:
|
||||||
"system.listMethods() see json/xmlrpc docs"
|
"system.listMethods() see json/xmlrpc docs"
|
||||||
return sclient.list_methods() + self.json_exposed
|
return sclient.list_methods() + self.json_exposed
|
||||||
|
|
||||||
def get_stats(self):
|
|
||||||
"""
|
|
||||||
todo: move to core.
|
|
||||||
returns:
|
|
||||||
{
|
|
||||||
'download_rate':float(),
|
|
||||||
'upload_rate':float(),
|
|
||||||
'max_download':float(),
|
|
||||||
'max_upload':float(),
|
|
||||||
'num_connections':int(),
|
|
||||||
'max_num_connections':int(),
|
|
||||||
'dht_nodes',int()
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
stats = {}
|
|
||||||
|
|
||||||
aclient.get_download_rate(dict_cb('download_rate',stats))
|
|
||||||
aclient.get_upload_rate(dict_cb('upload_rate',stats))
|
|
||||||
aclient.get_config_value(dict_cb('max_download',stats)
|
|
||||||
,"max_download_speed")
|
|
||||||
aclient.get_config_value(dict_cb('max_upload',stats)
|
|
||||||
,"max_upload_speed")
|
|
||||||
aclient.get_num_connections(dict_cb("num_connections",stats))
|
|
||||||
aclient.get_config_value(dict_cb('max_num_connections',stats)
|
|
||||||
,"max_connections_global")
|
|
||||||
aclient.get_dht_nodes(dict_cb('dht_nodes',stats))
|
|
||||||
|
|
||||||
aclient.force_call(block=True)
|
|
||||||
|
|
||||||
return stats
|
|
||||||
|
|
||||||
def update_ui(self, keys ,filter_dict , cache_id = None ):
|
def update_ui(self, keys ,filter_dict , cache_id = None ):
|
||||||
"""
|
"""
|
||||||
|
@ -191,7 +161,7 @@ class json_rpc:
|
||||||
return {
|
return {
|
||||||
"torrents":sclient.get_torrents_status(filter_dict , keys),
|
"torrents":sclient.get_torrents_status(filter_dict , keys),
|
||||||
"filters":filters,
|
"filters":filters,
|
||||||
"stats":self.get_stats(),
|
"stats":sclient.get_stats(),
|
||||||
"cache_id":-1
|
"cache_id":-1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue