aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: xChat xas.pl  (Read 3692 times)

pleur

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 27
xChat xas.pl
« on: June 23, 2006, 12:20:26 PM »

I used the xas.pl (find it @ files, utils), and found out that all values got screwed up, i guess the amulesig.dat has been changed it's format, so i fixxed it (last update for the script, 2004!)

Code: [Select]
#!/usr/bin/perl
# we register the script
# if someone knows how to unload it clean....do tell
IRC::register("xas", "1.6", "", "Xchat Amule Statistics");
# welcome message
IRC::print "\n\0033  Follow the \0034 white\0033 rabbit\0038...\003\n";
IRC::print "\n\0035 Use command \0038/xas\0035 to print out aMule statistics\003";
# we have no life. we are robots...and we hang around in here:
IRC::print "\0035 (#amule @ irc.freenode.net)\003";
# command that we use
IRC::add_command_handler("xas","xas");

#23-06-2006 - pleur     : fixxed *all* wrong values (amulesig.dat format update?)
#12.10.2004 - bisley    : added session/total ratios
#16.06.2004 - niet      : added support for memory usage and binary name
#05.05.2004 - Jacobo221 : fixed typos, sig 2 support, new outputs, crash detect
#29.04.2004 - niet      : renamed astats to xas (X-Chat Amule statistics)
#22.04.2004 - citroklar : added smp support
#      2004 - bootstrap : some hints on file opening
#      2004 - niet      : used some of cheetah.pl script and so astats was born

# Five status currently: online, connecting, offline, closed, crashed
sub xas
{
#amule program name
chomp(my $amulename = `ps --no-header -u $ENV{USER} -o ucmd --sort start_time|grep amule|head -n 1`);
#amule binary date (because we still don't have date in CVS version). GRRRRRR
#ls -lAF `ps --no-header -u j -o cmd --sort start_time|grep amule|head -n 1|awk '{print $2}'`
# system uptime
chomp(my $uptime = `uptime|cut -d " " -f 4- | tr -s " "`);
# number of cpu's calculated from /proc/cpuinfo
chomp(my $number_cpus = `cat /proc/cpuinfo | grep 'processor' -c`);
# type of cpu
        chomp(my $cpu = `cat /proc/cpuinfo | grep 'model name' -m 1 | cut -f 2 -d ":" | cut -c 2-`);
# cpu speed
chomp(my $mhz = `cat /proc/cpuinfo | grep "cpu MHz" -m 1 | cut -f 2 -d ":" | cut -c 2-`);
# what is the aMule's load on cpu
chomp(my $amulecpu = `ps --no-header -C $amulename -o %cpu --sort start_time|head -n 1`);
# how much memory is aMule using
chomp(my $amulemem = (sprintf("%.02f", `ps --no-header -C $amulename  -o rss --sort start_time|head -n 1` / 1024 )));

# bootstrap
# there is no spoon...err.... signature
open(amulesig,"$ENV{'HOME'}/.aMule/amulesig.dat") or die "aMule online signature not found. Did you enable it ?";
chomp(@amulesigdata = );
close amulesig;

# are we high or what ? :-Q
if ($amulesigdata[4] eq "H")
{$amuleid="high"}
else
{$amuleid="low"};

# are we online / offline / connecting
if ($amulesigdata[0]==0) {
$amulestatus="offline";
$amulextatus="" }
elsif ($amulesigdata[0]==2) { # Since aMule v2-rc4
$amulestatus="connecting";
                $amulextatus="" }
else {
$amulestatus="online";
$amulextatus="with $amuleid ID on server $amulesigdata[1] [ $amulesigdata[2]:$amulesigdata[3] ]" };

# total download traffic in Gb
my $tdl = (sprintf("%.02f", $amulesigdata[11] / 1073741824));

# total upload traffic in Gb
my $tul = (sprintf("%.02f", $amulesigdata[12] / 1073741824));

# session download traffic in Gb
my $sdl = (sprintf("%.02f", $amulesigdata[14] / 1048576));

# session upload traffic in Gb
my $sul = (sprintf("%.02f", $amulesigdata[15] / 1048576));
 
# ratio
my $totalratio = (sprintf("%0.1f",$tdl/$tul));
my $sessionratio = (sprintf("%0.1f",$sdl/$sul));


# convert runtime from sec to string
my $seconds = $amulesigdata[16];
my $days    = pull_count($seconds, 86400);
        my $hours   = pull_count($seconds, 3600);
        my $minutes = pull_count($seconds, 60);

my $runtime;

if ($days > 0) {
$runtime = sprintf "%02iD %02ih %02imin %02is", $days, $hours, $minutes, $seconds;
}
        elsif ($hours > 0) {
$runtime = sprintf "%02ih %02imin %02is", $hours, $minutes, $seconds;
}
elsif ($minutes > 0) {
$runtime = sprintf "%02imin %02is", $minutes, $seconds;
}
else {
$runtime = sprintf "%02is", $seconds;
}

# and display it

# if current user isn't running aMule
if ( ! `ps --no-header -u $ENV{USER} | grep amule`) {
IRC::command "/say $amulesigdata[10] is not running";
# Crash detection is implemented since v2-rc4, so XAS should be backwards compatible
if ( grep(/^1./,$amulesigdata[13]) || $amulesigdata[13]=="2.0.0rc1" || $amulesigdata[13]=="2.0.0rc2" || $amulesigdata[13]=="2.0.0rc3" ) {
IRC::command "/say aMule $amulesigdata[13] was closed after $runtime!" }
elsif ( ! grep(/^00 /,$runtime)) {
IRC::command "/say aMule $amulesigdata[13] crashed after $runtime!" }
else {
IRC::command "/say aMule $amulesigdata[13] was closed" };
IRC::command "/say Total download traffic: $tdl Gb";
IRC::command "/say Total upload traffic:   $tul Gb" }
# if aMule is running
else {
IRC::command "/say $amulesigdata[10] is $amulestatus $amulextatus";
IRC::command "/say aMule $amulesigdata[13] is using $amulecpu% CPU, $amulemem MB of memory and it has been running for $runtime";

# we only display "number of cpus" when we have more then one
if ($number_cpus > 1) {
IRC::command "/say on $number_cpus x $cpu @ $mhz up $uptime" }
else {
IRC::command "/say on $cpu @ $mhz MHz up $uptime" };

IRC::command "/say Sharing $amulesigdata[9] files with $amulesigdata[8] clients in queue";
IRC::command "/say Total download traffic: $tdl Gb, total upload traffic: $tul Gb, Total Ratio: 1:$totalratio";
IRC::command "/say Session download traffic: $sdl Mb, session upload traffic: $sul Mb, Session Ratio: 1:$sessionratio";
IRC::command "/say Current DL speed: $amulesigdata[6] KB/s, current UL speed:  $amulesigdata[7] KB/s" };
return 1;
# that's it
}

# usage: $count = pull_count(seconds, amount)
# remove from seconds the amount quantity, altering caller's version.
# return the integral number of those amounts so removed.
sub pull_count {
    my($answer) = int($_[0] / $_[1]);
    $_[0] -= $answer * $_[1];
    return $answer;
}
Logged
Hoe liev ben jij vandaag?

stefanero

  • Some Support
  • Developer
  • Hero Member
  • *****
  • Karma: 8
  • Offline Offline
  • Posts: 4235
Re: xChat xas.pl
« Reply #1 on: June 23, 2006, 12:42:04 PM »

did you check the cvs tarballs and the last releases its all up2date already
Logged
In its default setup, Windows XP on the Internet amounts to a car
parked in a bad part of town, with the doors unlocked, the key in
the ignition and a Post-It note on the dashboard saying, "Please
don't steal this."

pleur

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 27
Re: xChat xas.pl
« Reply #2 on: June 23, 2006, 01:27:30 PM »

ic, then i guess al that needs to be updated is the file at the download-section

 :]


sorry :))
Logged
Hoe liev ben jij vandaag?

stefanero

  • Some Support
  • Developer
  • Hero Member
  • *****
  • Karma: 8
  • Offline Offline
  • Posts: 4235
Re: xChat xas.pl
« Reply #3 on: June 23, 2006, 01:39:04 PM »

yup, but there are some lazy board admis around  :rolleyes:
Logged
In its default setup, Windows XP on the Internet amounts to a car
parked in a bad part of town, with the doors unlocked, the key in
the ignition and a Post-It note on the dashboard saying, "Please
don't steal this."

Kry

  • Ex-developer
  • Retired admin
  • Hero Member
  • *****
  • Karma: -665
  • Offline Offline
  • Posts: 5795
Re: xChat xas.pl
« Reply #4 on: June 23, 2006, 04:44:58 PM »

Including you :P
Logged

stefanero

  • Some Support
  • Developer
  • Hero Member
  • *****
  • Karma: 8
  • Offline Offline
  • Posts: 4235
Re: xChat xas.pl
« Reply #5 on: June 23, 2006, 04:49:37 PM »

I dont have the powa to change the link  :rolleyes:
Logged
In its default setup, Windows XP on the Internet amounts to a car
parked in a bad part of town, with the doors unlocked, the key in
the ignition and a Post-It note on the dashboard saying, "Please
don't steal this."

Kry

  • Ex-developer
  • Retired admin
  • Hero Member
  • *****
  • Karma: -665
  • Offline Offline
  • Posts: 5795
Re: xChat xas.pl
« Reply #6 on: June 23, 2006, 05:15:44 PM »

Yes you do. You just don't know it.

Don't try, Anakin. Do it!
Logged

stefanero

  • Some Support
  • Developer
  • Hero Member
  • *****
  • Karma: 8
  • Offline Offline
  • Posts: 4235
Re: xChat xas.pl
« Reply #7 on: June 23, 2006, 09:22:00 PM »

I wanne be luke plz, can I?
Logged
In its default setup, Windows XP on the Internet amounts to a car
parked in a bad part of town, with the doors unlocked, the key in
the ignition and a Post-It note on the dashboard saying, "Please
don't steal this."

Xavy

  • Approved Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
Re: xChat xas.pl
« Reply #8 on: June 29, 2007, 12:56:48 PM »

Yep, they must be definitely lazy (or definitely too occupied in other questions), as today i found the same problem. It is very easy to solve, just adding 1 value to any amulesigdata, but most users perhaps won't realize this ;)
Logged