You are not logged in.

#1 2009-03-11 18:54:43

oew
Member
From: Norway
Registered: 2006-11-08
Posts: 105

HOWTO: rtorrent stats in conky

Hi all!


I've been trying to get rtorrent stats in conky for ages and today I finally found a solution.

1. You'll need rtorrent with xmlrpc-c support. The easiest way to get this is to install rtorrent-svn from AUR.
2. Make a dir for rpc.socket (I used ~/.rtorrent_rdp/) and add this line to .rtorrent.rc:

scgi_local = ~/.rtorrent_rdp/rpc.socket

3. Download the script xmlrpc2scgi.py from this site: http://libtorrent.rakshasa.no/wiki/UtilsXmlrpc2scgi. I used the version added by glenn on 05/23/08 06:02:00.
4. Save this script as something.sh:

#!/bin/sh
test -S "$2" &&
"$@" d.multicall default \
   d.get_name= \
   d.get_up_rate= \
   d.get_down_rate= \
   d.get_completed_chunks= \
   d.get_size_chunks= \
   d.is_active= \
|
xmlstarlet sel -t -v / |
awk '/./ {
   if (++i%6 == 1) name=$0
   else if (i%6 == 2) up[name]=$0
   else if (i%6 == 3) down[name]=$0
   else if (i%6 == 4) done[name]=$0
   else if (i%6 == 5) size[name]=$0
   else if (i%6 == 0) active[name]=$0
} END {
   for(name in up) {
      if(active[name]) {
         up_sum += up[name]
         down_sum += down[name]
         #if(++j<=4)
         {
            printf("Name: %s\n", name)
            printf("Done: %d%%\n", 100 * done[name] / size[name])
            printf("Up: %.1f kB/s\n", up[name] / 1024)
            printf("Down: %.1f kB/s\n", down[name] / 1024)
            printf("\n\b")
         }
      }
   }
   printf("Total up: %.1f kB/s\n", up_sum / 1024)
   printf("Total down: %.1f kB/s\n", down_sum / 1024)
}' |
xargs -d'\b' -n1 printf '%s\0' |
sort -z |
xargs -0 -n1 printf '%s'

5. Finally add this line to .conkyrc:

${execi 1 ~/something.sh ~/.rtorrent_rpc/xmlrpc2scgi.py ~/.rtorrent_rpc/rpc.socket}

The conky output will look something like this (I translated the output to english):
Conky_With_rTorrent_by_BadOmen02.jpg

It's easy to customize the output. You only need to edit the something.sh to your liking.
Check out http://libtorrent.rakshasa.no/wiki/RTorrentCommands and http://libtorrent.rakshasa.no/wiki/RTorrentCommandsRaw for more information.
I made it fit with my conky statusbar in dwm:

DOWN: 0K  UP: 77K  LEECH: 0  SEED: 9

I can upload my script if requested.

Disclaimer:
All credits for this goes to BadOmen at the ubuntu-se.org forum.
I just wanted to share this with my fellow archers, so I've customized the install process to Arch Linux.
Also the original thread is in swedish, so it ain't easy to understand for anyone outside off Scandinavia.
Link to original thread: http://ubuntu-se.org/phpBB3/viewtopic.php?f=19&t=30454


Edit: typo

___
oew

Last edited by oew (2009-03-11 18:58:00)


there's no place like ~/

Offline

#2 2009-03-11 22:15:40

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: HOWTO: rtorrent stats in conky

I suppose I should put this in another thread (I hope you don't mind), but since this is here, I'll share a little python script I made for getting the status of torrents from Deluge. This one is made for use with dzen but can be modified for conky by changing the output and removing the loop.

#!/usr/bin/env python
import sys
from deluge.ui.client import sclient
from time import sleep

# Connect to Deluge core
sclient.set_core_uri()

# Loop forever
while sclient.connected():
    torrent_ids = sclient.get_session_state() # Make sure we keep track of all torrents

    print "^fg(lightblue)Torrents", # Print Torrents without a newline

    for id in torrent_ids: # Loop through torrents and get status of each and then pretty print it all for dzen
        info = sclient.get_torrent_status(id, ['name', 'progress', 'download_payload_rate', 'total_done', 'total_size', 'ratio'])

        if info['progress'] == 100: # Use a shorter format
            if len(info['name']) > 10:
                info['name'] = info['name'][0:8] + ".."
            print "^fg(white)| ^fg(grey50)\"" + info['name'] + "\" " + str(round(info['ratio'], 2)),
        else:
            if len(info['name']) > 20:
                info['name'] = info['name'][0:18] + ".."
            print "^fg(white)| ^fg(grey50)\"^fg(white)" + info['name'] + "^fg(grey50)\" ^fg(lightblue)" + str(info['total_done'] / 1000000) + "^fg(grey50)M/^fg(lightblue)" + str(info['total_size'] / 1000000) + "^fg(grey50)M (^fg(lightblue)" + str(round(info['progress'], 1)) + "^fg(grey50)%) ^fg(white)^i(ICONSFOLDERGOESHERE/net_down_03.xbm) ^fg(lightblue)" + str(round(info['download_payload_rate'] / 1000, 1)) + "^fg(grey50)K/s",

    print # Print newline so dzen updates
    sys.stdout.flush()
    sleep(2)

Last edited by HashBox (2009-03-11 22:16:07)

Offline

#3 2009-03-12 03:14:50

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: HOWTO: rtorrent stats in conky

Please post HOWTOs on the arch wiki. It's too easy to get lost here on the forums

Offline

#4 2009-06-16 17:17:39

kyotocafe
Member
From: Japan
Registered: 2009-01-28
Posts: 19

Re: HOWTO: rtorrent stats in conky

It works great. Thanks a lot for your big efforts.

Offline

#5 2009-06-19 02:31:47

ditto
Member
Registered: 2009-06-19
Posts: 1

Re: HOWTO: rtorrent stats in conky

Thank you for this tutorial.

How would I just display "Active" torrents and not all torrents in conky?

Offline

#6 2009-10-12 21:00:18

gajo
Member
Registered: 2008-04-01
Posts: 93
Website

Re: HOWTO: rtorrent stats in conky

Hey, a very nice script, thanks a lot;
However, there's a bit of a modification i'd suggest: get rid off the

test -S "$2" &&

It isn't verbose at all so it doesn't help much anyway, and it causes a problem if instead of the local rpc.socket you're using a scgi port, like scgi://localhost:33000 (which is often for those that use an additional web interface to rtorrent). Also a thing that might be causing a problem, add text_buffer_size <some big number> otherwise the text will be cut in half, you can (and should) also uncomment the

if(++j<=4)

part of the script so you can limit the amount of torrents that are getting displayed.

Offline

#7 2010-01-08 21:50:06

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: HOWTO: rtorrent stats in conky

that worked perfect thanks big_smile


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#8 2010-01-09 23:39:12

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: HOWTO: rtorrent stats in conky

i was wondering if you could help me.

i have got wtorrent front end running, which requires scgi_port to be set, and when i set this i cannot use scgi_local. is there a way i can have both the wtorrent webui and be able to have my stats in conky.

thanks Markp1989


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#9 2010-01-25 11:30:52

samuele.mattiuzzo
Member
From: Treviso, IT
Registered: 2009-10-12
Posts: 307
Website

Re: HOWTO: rtorrent stats in conky

hi all, i have an issue: when launching xmlrpc2scgi it gives me 2 errors

- xmlstarlet command not found
- newline error after DOCTYPE declaration

any hint on how to fix this problem?

Offline

#10 2010-01-28 02:13:37

BigKahunaca
Member
From: Charlottetown, PE
Registered: 2009-03-03
Posts: 4

Re: HOWTO: rtorrent stats in conky

samuele.mattiuzzo wrote:

- xmlstarlet command not found

I am also getting the same error...

Offline

#11 2010-01-28 13:24:16

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: HOWTO: rtorrent stats in conky

You can use pkgfile to search the repos for the owning package.

Offline

#12 2010-01-28 16:05:00

oew
Member
From: Norway
Registered: 2006-11-08
Posts: 105

Re: HOWTO: rtorrent stats in conky

You need to install xmlstarlet from aur.


there's no place like ~/

Offline

#13 2010-09-06 15:19:27

BadOmen
Member
Registered: 2010-09-06
Posts: 2

Re: HOWTO: rtorrent stats in conky

Hi,
Nice to see that the code has come to use smile

In the post i did 03 nov 2008, 15:10 in this(swidish) thread:
http://ubuntu-se.org/phpBB3/viewtopic.php?f=19&t=30454
That code makes it possible to see remaining time and to specify different color in the output like

printf ("${color red}%.15s ", name) 

will print the name of the torrent in red and show the 15 first  characters.

But to use it you have to change your 5. to

 ${execpi 1 ~/something.sh ~/.rtorrent_rpc/xmlrpc2scgi.py ~/.rtorrent_rpc/rpc.socket}

or:

${execp ~/something.sh ~/.rtorrent_rpc/xmlrpc2scgi.py ~/.rtorrent_rpc/rpc.socket}

Else you will not get the text coloring.

And just a note, the time interval for execi/execpi can't be less then update_interval in configuration.
And if the time interval is set to 3 seconds then the time left will not be more exact than that, but it is possible to comment away the seconds and just show hour and minutes.

I have not tested the code with conky > 1.6 so i don't know how it works now and I am using Ubuntu, not Arche.
(no flame war, I have heard a lot of good things about Arche Linux)

oew: maybe you feel like trying it out and translate some parts of the code if it looks like it's still working and post it here. Don't ask me way some variables is in Swedish... I just don't know smile

Offline

#14 2010-09-10 18:05:34

BadOmen
Member
Registered: 2010-09-06
Posts: 2

Re: HOWTO: rtorrent stats in conky

I am in the process of learning python so be nice smile

It can look like this:
rtorrent_in_conky_by_badomen02-d2yfeir.png

Script Info:
This script collects information from the torrents in rTorrent and prints it out.
If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent.

it is possible to configure it under def  __init__() and make change in def __main__ if needed.(colors and other stuff)

Dependencies:
rtorrent with xmlrpc-c working.
xmlrpc2scgi.py to be in the same directory as this script.

xmlrpc2scgi.py can be downloaded at the bottom of this site: http://libtorrent.rakshasa.no/wiki/UtilsXmlrpc2scgi

.conkyrc setting
Conky needs this line in the Text part:
${execp /Path/To/Script/xmlrpc2rtorrent.py}
Set the text_buffer_size so it's not cutting the output.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Script Version 1.1
#----      
#      Copyright 2010 Jonas Lindberg
#      
#      This program is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Public License as published by
#      the Free Software Foundation; either version 2 of the License, or
#      (at your option) any later version.
#      
#      This program is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU General Public License for more details.
#      
#      You should have received a copy of the GNU General Public License
#      along with this program; if not, write to the Free Software
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#      MA 02110-1301, USA.
#      
# Contact:  Jonas Lindberg <badomen02 gmail>
#----

#Script Info:
# This script collects information from the torrents in rTorrent and prints it out.
# If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent.
# it is possible to configure it under def  __init__() and change def __main__ if needed.

#Dependencies:
# rtorrent with xmlrpc-c working.
# xmlrpc2scgi.py to be in the same directory as this script.

# xmlrpc2scgi.py can be downloaded at the bottom of this site: http://libtorrent.rakshasa.no/wiki/UtilsXmlrpc2scgi

#.conkyrc setting
# Conky needs this line in the Text part:
# ${execp ~/Dokument/programmering/workspace/prjXMLrpc2scgi/src/xmlrpc2rtorrent.py}
# Set the text_buffer_size so it's not cutting the output.

from __future__ import print_function
from xmlrpc2scgi import do_scgi_xmlrpc_request_py
import socket

class TorrentInfo():

    def __init__(self):
        # Change settings here.
        self.rpcSocketPath='/home/jonas/rtorrent_rpc/rpc.socket'
        
        self.visible=6
        # Just one of them can be true at the same time. if all is False then Just Total Down/Up will be shown.
        self.showActiveTorrents=False
        self.showClosedTorrents=False
        self.showActAndCloTorrents=True
        self.showDownTorrents=False
        self.showUpTorrents=False
        self.showDowUpTorrents=False

        
        self.maxNameLength=40
        # Replacing a color with an empty string '' will show your default Conky color.
        self.activeColor = 'green'
        self.closedColer = 'red'
        self.txtColor = 'white'
        self.downColor = 'orange'
        self.upColor = 'brown'
        self.totalColor = 'purple'
        self.totalDoUpColor = 'LightGreen'
        self.timeColor = 'grey'
        self.lineColor = 'cyan'
        self.procentColor ='yellow'
        self.receivedColor = 'LightBlue'
        
        # Do not change this:
        self.countVisible = 1
        self.countLines=0
        self.totalUpSpeed=0
        self.totalDownSpeed=0
        self.rTorrentOff=False
    
    def iterTorrents(self):
        """ A iterator that returns a dictionary with information from every torrent in rTorrent. """
        
        self.params=('default', 'd.get_name=','d.get_up_rate=','d.get_down_rate=','d.get_completed_chunks=','d.get_size_chunks=','d.get_size_bytes=','d.get_bytes_done=','d.is_active=')
        self.dictKey=('name','up_rate','down_rate','done','size','total_bytes','bytes_done','is_active')
        try:
            self.lolRtorrents = do_scgi_xmlrpc_request_py(self.rpcSocketPath, 'd.multicall',self.params)
        except socket.error:
            self.rTorrentOff=True
            pass
        else:
            self.lodTorrents=[]
            for self.torrent in self.lolRtorrents:
                self.lodTorrents.append(dict(zip(self.dictKey,self.torrent)))
               
            for self.torrent in self.lodTorrents:
                yield self.torrent
        
    def collectTorrentInfo(self,torrent):
        """Collects information from the torrent.
        
        This must be called for every torrent"""
        self.totalUpSpeed+=torrent['up_rate'] 
        self.totalDownSpeed+=torrent['down_rate']
        self.fProcentDone=float(torrent['bytes_done'])/float(torrent['total_bytes'])*100
        self.name=torrent['name']
        self.downRate=float(torrent['down_rate']) / 1024

        self.upRate=float(torrent['up_rate'])  / 1024
        self.totalBytes=float(torrent['total_bytes']) / 1024 / 1024
        self.receivedMB=float(torrent['bytes_done']) / 1024 / 1024
        self.isActive=torrent['is_active']
                
    def __showTorrentInfo(self):
        """ Is colled from showTorrentInfo to display the correct torrents specified in __init__. """
        
        if self.countVisible<=self.visible:
            self.countVisible+=1  
            if self.isActive:
                print('${{color {0}}}Active:${{color {1}}} {2:.{3}s}'.format(self.activeColor,self.txtColor,self.name,self.maxNameLength), end='\n')
            else:
                print('${{color {0}}}Closed:${{color {1}}} {2:.{3}s}'.format(self.closedColer,self.txtColor,self.name,self.maxNameLength), end='\n')
    
            print('${{color {0}}}Down:${{color {1}}} {2:.1f} KB/s'.format(self.downColor,self.txtColor,self.downRate), end='\n')
            print('${{color {0}}}Up:${{color {1}}} {2:.1f} KB/s'.format(self.upColor,self.txtColor,self.upRate), end='\n')
            print('${{color {0}}}Received:${{color {1}}} {2:.1f} MB'.format(self.receivedColor,self.txtColor,self.receivedMB))
            print('${{color {0}}}Total:${{color {1}}} {2:.1f} MB'.format(self.totalColor,self.txtColor,self.totalBytes) ,end='\n')
            print('${{color {0}}}Done:${{color {1}}} {2:.2f}%'.format(self.procentColor,self.txtColor,self.fProcentDone))
                   
    def showTorrentInfo(self):
        """ Shows the torrent that you have specified in __init__. """
        if self.showActiveTorrents:
            if self.isActive:
                self.__showTorrentInfo()
        elif self.showClosedTorrents:
            if not self.isActive:
                self.__showTorrentInfo()
        elif self.showActAndCloTorrents:
            self.__showTorrentInfo()
        elif self.showDownTorrents and self.downRate!=0:
            self.__showTorrentInfo()
        elif self.showUpTorrents and self.upRate!=0:
            self.__showTorrentInfo()
        elif self.showDowUpTorrents and (self.upRate!=0 or self.downRate!=0):
            self.__showTorrentInfo()

 
    def ShowTimeLeft(self,torrent):
        """ Calls __ShowTimeLeft() just when needed. """
        if (self.showActiveTorrents or self.showActAndCloTorrents) and self.countVisible<=self.visible:
            if self.isActive:
                self.__ShowTimeLeft(torrent)

        elif self.showDownTorrents and self.downRate!=0 and self.countVisible<=self.visible:
            self.__ShowTimeLeft(torrent)
        
        elif self.showDowUpTorrents and self.downRate!=0:
            self.__ShowTimeLeft(torrent)
                                
        
    def __ShowTimeLeft(self,torrent):
        if torrent['total_bytes'] != torrent['bytes_done'] and (torrent['down_rate'] / 512) !=0:
            if (float(torrent['down_rate']) / 1024) >= 0.4:
                self.seconds_left = (torrent['total_bytes'] - torrent['bytes_done']) / ((torrent['down_rate'] / 512) * 512)
                self.seconds = self.seconds_left % 60
                self.minutes = self.seconds_left / 60 % 60
                self.hours = self.seconds_left / 60 / 60 % 24
                self.days = self.seconds_left / 60 / 60 / 24
                                                                  
                if self.seconds == 60:
                    self.minutes+=1
                    self.seconds = 0
                                      
                if self.minutes == 60:
                    self.hours+=1
                    self.minutes = 0
                print('${{color {0}}}Countdown: ${{color {1}}}{2:02d}:{3:02d}:{4:02d}:{5:02d}'.format(self.timeColor,self.txtColor,self.days,self.hours,self.minutes,self.seconds))
        
     
    def showTotalSpeed(self):
        """ Shows the total upload and download speed """
        if not self.rTorrentOff:
            self.totalDownSpeedKB=float(self.totalDownSpeed)/1024
            self.totalUpSpeedKB=float(self.totalUpSpeed)/1024
            print('${{color {0}}}Total Down/Up:${{color {1}}} {2:.1f}/{3:.1f} KB/s'.format(self.totalDoUpColor,self.txtColor,self.totalDownSpeedKB,self.totalUpSpeedKB),end='\n')

    def showLine(self):
        """ Shows the line and makes shore that the liens just show up for the visible torrents."""
        if self.countLines < self.countVisible-1:
            self.countLines+=1
            print('${{color {0}}}-----'.format(self.lineColor))
    
            
def main():
    Ti=TorrentInfo()
    for torrent in Ti.iterTorrents():
        Ti.collectTorrentInfo(torrent)
        Ti.showTorrentInfo()
        Ti.ShowTimeLeft(torrent)
        Ti.showLine()
        
    Ti.showTotalSpeed()

if __name__ == "__main__":
    main()

Edit: I changed Procent to Done. >> Done: 8.6%
Edit: Updated the script: Added more config options.

Last edited by BadOmen (2010-09-17 10:13:43)

Offline

#15 2012-04-28 17:12:21

eli
Member
Registered: 2012-04-28
Posts: 1

Re: HOWTO: rtorrent stats in conky

BadOmen wrote:

I am in the process of learning python so be nice smile
Script Info:
This script collects information from the torrents in rTorrent and prints it out.
If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent.

.

Is it possible to know how much data my rtorrent client has uploaded (seeded or served ) ??? I am new to the world of python..Please guide me .

Offline

#16 2012-06-16 00:13:46

pyroscope
Member
Registered: 2011-03-11
Posts: 33
Website

Re: HOWTO: rtorrent stats in conky

$ alias total
alias total='awk '\''{tot=tot+$1} END {print tot}'\'''
$ rtcontrol -qo uploaded // | total
6525387960

Or as a complete solution: http://code.google.com/p/pyroscope/wiki … y_to_conky

Of course, that's only what's still loaded in the client, i.e. excluding the upload for any items you deleted. I hope to come around to record some statistics in RRD archives soon, then that's solved, too.

Last edited by pyroscope (2012-06-16 00:15:21)

Offline

Board footer

Powered by FluxBB