Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access specific values in the alert object #1953

Closed
MaChengxin opened this issue Apr 27, 2017 · 9 comments
Closed

Unable to access specific values in the alert object #1953

MaChengxin opened this issue Apr 27, 2017 · 9 comments
Labels

Comments

@MaChengxin
Copy link
Contributor

libtorrent version (or branch):
1.1.3.0

platform/architecture:
Ubuntu 16.04, x64

compiler and compiler version:
gcc (GCC) 5.4.0

Python version:
Python 2.7.12

please describe what symptom you see, what you would expect to see instead and
how to reproduce it.

I am trying to access session statistics and I am only interested in a few of them. It is suggested by the doc that "Always query the metrics first, to find out the index at which the value is stored".
However, the alert object returned by calling post_session_stats() doesn't support indexing.

TypeError: 'session_stats_alert' object has no attribute '_getitem_'

So here come two questions:

  1. How do we use the returned index of lt.find_metric_idx("NAME_OF_STATS")?
  2. Can we just use alert.values["NAME_OF_STATS"] to get the stats? (e.g. alert.values["ses.num_incoming_choke"])
@arvidn
Copy link
Owner

arvidn commented Apr 27, 2017

right, the python binding turns the array into a dictionary mapping the names to the values. i.e. in python you don't have to look up any index up-front

@arvidn
Copy link
Owner

arvidn commented Apr 27, 2017

This should probably be documented in the python binding documentation. if you're up for it, please submit pull request!

@MaChengxin
Copy link
Contributor Author

Thanks for the answer.
Speaking of the python binding documentation, do you mean the following one?
https://github.com/arvidn/libtorrent/blob/master/docs/python_binding.rst

@arvidn
Copy link
Owner

arvidn commented Apr 27, 2017

yes

@MaChengxin
Copy link
Contributor Author

So I tried to use alert.values["NAME_OF_STATS"] to get the stats that I am interested in:

alerts = ses.pop_alerts()
for a in alerts:
	if a.category() & lt.alert.category_t.error_notification:
		print(a)
	elif a.category() & lt.alert.category_t.stats_notification:
		'''
		total number of bytes sent and received by the session
		'''
		print("net.sent_bytes: ", a.values["net.sent_bytes"])
		print("net.sent_payload_bytes: ", a.values["net.sent_payload_bytes"])
		print("net.sent_ip_overhead_bytes: ", a.values["net.sent_ip_overhead_bytes"])
		print("net.sent_tracker_bytes: ", a.values["net.sent_tracker_bytes"])

		print("net.recv_bytes: ", a.values["net.recv_bytes"])
		print("net.recv_payload_bytes: ", a.values["net.recv_payload_bytes"])
		print("net.recv_ip_overhead_bytes: ", a.values["net.recv_ip_overhead_bytes"])
		print("net.recv_tracker_bytes: ", a.values["net.recv_tracker_bytes"])

		print("net.recv_failed_bytes: ", a.values["net.recv_failed_bytes"])
		print("net.recv_redundant_bytes: ", a.values["net.recv_redundant_bytes"])

It worked, but the result looks like incorrent:

net.sent_bytes:  6920
net.sent_payload_bytes:  0
net.sent_ip_overhead_bytes:  112076
net.sent_tracker_bytes:  379
net.recv_bytes:  2007475
net.recv_payload_bytes:  2004514
net.recv_ip_overhead_bytes:  110820
net.recv_tracker_bytes:  3765
net.recv_failed_bytes:  0
net.recv_redundant_bytes:  0

I was expecting sent_bytes = sent_payload_bytes + sent_ip_overhead_bytes + sent_tracker_bytes, but the result isn't.
Can you please explain why is that?

@arvidn
Copy link
Owner

arvidn commented Apr 28, 2017

payload refers to the actual content of the torrent. The difference between "bytes" and "payload" is the bittorrent protocol overhead (like, sending requests, heartbeats, haves etc.). In your case it looks like you're downloading, so the majority of those bytes are likely requests and haves. If you have a high churn of peers it may also be bitfields.

@MaChengxin
Copy link
Contributor Author

Yes indeed, I am measuring downloading statistics.
From what you said, I infer that net.sent_bytes only includes net.sent_payload_bytes and protocol overhead, which isn't got explicitly, but rather requires a simple calculation (net.sent_bytes - net.sent_payload_bytes). Moreover, net.sent_ip_overhead_bytes and net.sent_tracker_bytes are not included in net.sent_bytes.
Am I right?

@arvidn
Copy link
Owner

arvidn commented Apr 28, 2017

I seem to recall sent_bytes including tracker traffic as well, but probably not the IP overhead.

arvidn pushed a commit that referenced this issue May 1, 2017
Explain retrieving session statistics in python. Based on the discussion here: #1953
@stale
Copy link

stale bot commented Feb 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 29, 2020
@stale stale bot closed this as completed Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants