Community discussions

MikroTik App
 
User avatar
gustkiller
Member
Member
Topic Author
Posts: 419
Joined: Sat Jan 07, 2006 5:15 am
Location: Brazil
Contact:

print simple queue name and stats in the same command..

Sat May 24, 2008 10:07 pm

Hi

needing a script that do something like

simple queue print name, txbytes, rxbytes in the same command..

coz simple queue print prints the queue name, but the simple queue prin stats prints everything but name ..

thanks in advice.
 
User avatar
gustkiller
Member
Member
Topic Author
Posts: 419
Joined: Sat Jan 07, 2006 5:15 am
Location: Brazil
Contact:

Re: print simple queue name and stats in the same command..

Sat May 24, 2008 11:44 pm

:foreach i in=[/queue simple find rate=8] do={:put (
"nome" . [/queue simple get $i name] . "TOTAL" . [/queue simple get $i total-byte
s]);}



just figured it out :)

but theres any way to do something like "order by" total bytes?
 
User avatar
Giepie
Member
Member
Posts: 433
Joined: Mon Sep 13, 2004 12:33 pm
Location: Western Cape, South Africa
Contact:

Re: print simple queue name and stats in the same command..

Sun Jun 22, 2008 9:20 am

Hi all

Thought you might be interested in my script. I have not tested it for dynamic queues as I only need it for static queues:

:log info "Starting QUEUE Statistics Checker"

#####DEFINE VARIABLES#####
:local slashchecker
:local slashcheckertotal
:local bytecountedup
:local bytecounteddown
:local megcountedup
:local megcounteddown
:local slashcounter
:local precalcbytes
:local pickbegin
:local pickend
:local slashcounted
:local slashcounted1
:local numberofqueues
:local test
:local interfacename
:local emailvariable
:local highsitename
:local fromemailaddress
:local toemailaddress
#####VARIABLES DEFINED#####

########## CHANGE INDIVIDUAL DETAILS HERE: ##########
:set fromemailaddress "highsite@domain.co.za"
:set toemailaddress "admin@domain.co.za"
########## END OF INDIVIDUAL DETAILS ##########

#####COUNT NUMBER OF QUEUES#####
:set numberofqueues [/queue simple print count-only]
:set highsitename [/system identity get name]
##ADD DETAILS TO E-MAIL VARIABLE##
:set emailvariable "QUEUE STATISTICS FOR:
$highsitename

TOTAL NUMBER OF QUEUES: $numberofqueues"
##ADD DETAILS TO E-MAIL VARIABLE DONE##

#####BEGIN MAIN LOOP FOR QUEUE PROCESSING#####
/queue simple
:foreach n in=[/queue simple find priority=8] do={
:local interfacename [/queue simple get [$n] name]

#####SEPERATE UP/DOWN BYTES FROM QUEUE#####
##PRESET VARIABLES##
:local precalcbytes [:pick [/queue simple get [$n] bytes] 0 30]
:set slashcheckertotal $precalcbytes
:set pickbegin 1
:set pickend 2
:set slashcounter 0

#####START SLASH CHECKER#####
/queue simple
:for i from=1 to=20 do={

:set pickbegin (pickbegin + 1)
:set pickend (pickend + 1)
:set slashchecker [:pick $slashcheckertotal $pickbegin $pickend]

:if ($slashchecker = "/") do={
:set slashcounted $pickbegin } else={ :set slashcounter ($slashcounter +1)}
}
#:log info "SLASHCOUNTED: $slashcounted"
#####SLASHCHECKER LOOP END#####

#####GOT SLASH PICK COUNT, STARTING BYTES UP AND DOWN SPLIT#####
:set slashcounted1 ($slashcounted + 1)
:set bytecountedup [:pick $precalcbytes 0 $slashcounted]
:set bytecounteddown [:pick $precalcbytes $slashcounted1 30]
:set megcountedup ($bytecountedup / 1000000)
:set megcounteddown ($bytecounteddown / 1000000)
#:log info "INTERFACE NAME: $interfacename"
#:log info "PRECALCBYTES: $precalcbytes"
#:log info "BYTECOUNTEDUP $bytecountedup BYTES"
#:log info "BYTECOUNTEDDOWN $bytecounteddown BYTES"
#:log info "MEGCOUNTEDUP $megcountedup MB"
#:log info "MEGCOUNTEDDOWN $megcounteddown MB"
#:log info " "
#:log info " "
##ADD ABOVE INFO TO EMAIL VARIABLE##
:set emailvariable "$emailvariable

QUEUE NAME:\t\t\t$interfacename
TOTAL BYTES:\t\t$precalcbytes
UPLOADED BYTES:\t\t$megcountedup MB
DOWNLOADED BYTES:\t\t$megcounteddown MB

"
##UPDATE OF EMAIL VARIABLE DONE##

}
#####END OF QUEUE PROCCESSOR LOOP#####


#####SENDING DETAIL TO EMAIL#####
:set emailvariable "$emailvariable
END OF QUEUE STATISTICS FOR: $highsitename"

/tool e-mail send from=$fromemailaddress to=$toemailaddress server=196.25.240.94 subject="$highsitename QUEUE Statistics" body=$emailvariable
#####END OF SENDING EMAIL#####

:log info "Total number of queues processed: $numberofqueues"
:log info "QUEUE Statistics Check DONE and E-Mailed to $toemailaddress"



ENJOY!
 
pjotr
just joined
Posts: 3
Joined: Mon Feb 23, 2009 10:53 pm

Re: print simple queue name and stats in the same command..

Mon Feb 23, 2009 11:38 pm

In the version 3.20 does not work
Please advice
Thanks
Hi all

Thought you might be interested in my script. I have not tested it for dynamic queues as I only need it for static queues:

:log info "Starting QUEUE Statistics Checker"

#####DEFINE VARIABLES#####
:local slashchecker
:local slashcheckertotal
:local bytecountedup
:local bytecounteddown
:local megcountedup
:local megcounteddown
:local slashcounter
:local precalcbytes
:local pickbegin
:local pickend
:local slashcounted
:local slashcounted1
:local numberofqueues
:local test
:local interfacename
:local emailvariable
:local highsitename
:local fromemailaddress
:local toemailaddress
#####VARIABLES DEFINED#####

########## CHANGE INDIVIDUAL DETAILS HERE: ##########
:set fromemailaddress "highsite@domain.co.za"
:set toemailaddress "admin@domain.co.za"
########## END OF INDIVIDUAL DETAILS ##########

#####COUNT NUMBER OF QUEUES#####
:set numberofqueues [/queue simple print count-only]
:set highsitename [/system identity get name]
##ADD DETAILS TO E-MAIL VARIABLE##
:set emailvariable "QUEUE STATISTICS FOR:
$highsitename

TOTAL NUMBER OF QUEUES: $numberofqueues"
##ADD DETAILS TO E-MAIL VARIABLE DONE##

#####BEGIN MAIN LOOP FOR QUEUE PROCESSING#####
/queue simple
:foreach n in=[/queue simple find priority=8] do={
:local interfacename [/queue simple get [$n] name]

#####SEPERATE UP/DOWN BYTES FROM QUEUE#####
##PRESET VARIABLES##
:local precalcbytes [:pick [/queue simple get [$n] bytes] 0 30]
:set slashcheckertotal $precalcbytes
:set pickbegin 1
:set pickend 2
:set slashcounter 0

#####START SLASH CHECKER#####
/queue simple
:for i from=1 to=20 do={

:set pickbegin (pickbegin + 1)
:set pickend (pickend + 1)
:set slashchecker [:pick $slashcheckertotal $pickbegin $pickend]

:if ($slashchecker = "/") do={
:set slashcounted $pickbegin } else={ :set slashcounter ($slashcounter +1)}
}
#:log info "SLASHCOUNTED: $slashcounted"
#####SLASHCHECKER LOOP END#####

#####GOT SLASH PICK COUNT, STARTING BYTES UP AND DOWN SPLIT#####
:set slashcounted1 ($slashcounted + 1)
:set bytecountedup [:pick $precalcbytes 0 $slashcounted]
:set bytecounteddown [:pick $precalcbytes $slashcounted1 30]
:set megcountedup ($bytecountedup / 1000000)
:set megcounteddown ($bytecounteddown / 1000000)
#:log info "INTERFACE NAME: $interfacename"
#:log info "PRECALCBYTES: $precalcbytes"
#:log info "BYTECOUNTEDUP $bytecountedup BYTES"
#:log info "BYTECOUNTEDDOWN $bytecounteddown BYTES"
#:log info "MEGCOUNTEDUP $megcountedup MB"
#:log info "MEGCOUNTEDDOWN $megcounteddown MB"
#:log info " "
#:log info " "
##ADD ABOVE INFO TO EMAIL VARIABLE##
:set emailvariable "$emailvariable

QUEUE NAME:\t\t\t$interfacename
TOTAL BYTES:\t\t$precalcbytes
UPLOADED BYTES:\t\t$megcountedup MB
DOWNLOADED BYTES:\t\t$megcounteddown MB

"
##UPDATE OF EMAIL VARIABLE DONE##

}
#####END OF QUEUE PROCCESSOR LOOP#####


#####SENDING DETAIL TO EMAIL#####
:set emailvariable "$emailvariable
END OF QUEUE STATISTICS FOR: $highsitename"

/tool e-mail send from=$fromemailaddress to=$toemailaddress server=196.25.240.94 subject="$highsitename QUEUE Statistics" body=$emailvariable
#####END OF SENDING EMAIL#####

:log info "Total number of queues processed: $numberofqueues"
:log info "QUEUE Statistics Check DONE and E-Mailed to $toemailaddress"



ENJOY!
 
User avatar
Giepie
Member
Member
Posts: 433
Joined: Mon Sep 13, 2004 12:33 pm
Location: Western Cape, South Africa
Contact:

Re: print simple queue name and stats in the same command..

Tue Feb 24, 2009 12:56 am

Hi pjotr

What exactly isn't working with your script?

Are you aware of the fact that the SAIX IP address have changed? SAIX recommends you use smtp.saix.net instead of it's IP, as certain segments of their network resolve to different addresses. If your problem is that the script won't send out the mail, it's probably due to the SMTP address, try pinging smtp.saix.net from the highsite and see where it resolves to.

If your problem is that the script won't run due to something else we could further investigate.

I looked through the script real quick but couldn't see any obvious problems.

Perhaps send us more info on what exactly doesn't work.

My rule of thumb for trouble shooting is usually to # out most of the script and removing the # until it stop working. (or alternatively put :log error "script is here" messages in some lines, run the script, and move the :log entry down until you find where it stops...)

Hope the info was useful!

G
 
pjotr
just joined
Posts: 3
Joined: Mon Feb 23, 2009 10:53 pm

Re: print simple queue name and stats in the same command..

Tue Feb 24, 2009 4:50 pm

if the simple queue in one of the rules of any data statistics, so the script fails
 
puzlan
just joined
Posts: 1
Joined: Fri Feb 03, 2012 8:47 pm

Re: print simple queue name and stats in the same command..

Tue Feb 14, 2012 3:43 pm

If the number of> 1 queue simple, displays an error

[admin@H] > /system script run script1                                      
2
Script Error: cannot divide string by time interval
 
neophyte
just joined
Posts: 18
Joined: Tue Dec 11, 2012 10:39 am

Re: print simple queue name and stats in the same command..

Fri Mar 15, 2013 5:52 pm

work
#####GOT SLASH PICK COUNT, STARTING BYTES UP AND DOWN SPLIT#####
:set slashcounted1 ($slashcounted + 1)
:set bytecountedup [:pick $precalcbytes 0 $slashcounted]
:set bytecounteddown [:pick $precalcbytes $slashcounted1 30]
#########################################################
:if ($bytecountedup ="0/0") do={
               :set bytecountedup "0"
                :set bytecounteddown "0"
            }
#########################################################
:set megcountedup ($bytecountedup / 1000000)
:set megcounteddown ($bytecounteddown / 1000000)

#:log info "INTERFACE NAME: $interfacename"
#:log info "PRECALCBYTES: $precalcbytes"
#:log info "BYTECOUNTEDUP $bytecountedup BYTES"
#:log info "BYTECOUNTEDDOWN $bytecounteddown BYTES"
#:log info "MEGCOUNTEDUP $megcountedup MB"
#:log info "MEGCOUNTEDDOWN $megcounteddown MB"
#:log info " "
#:log info " "
##ADD ABOVE INFO TO EMAIL VARIABLE##
:set emailvariable "$emailvariable

COMPUTER IP:\t\t\t$interfacename
TOTAL BYTES:\t\t$precalcbytes
UPLOADED MEGABYTES:\t\t$megcountedup MB
DOWNLOADED MEGABYTES:\t\t$megcounteddown MB
"
 
wmp1988
just joined
Posts: 5
Joined: Fri Jul 20, 2012 10:13 am

Re: print simple queue name and stats in the same command..

Thu Oct 24, 2013 11:23 am

Hi Guys,

I know its an old topic but was wondering how to get this to work on ROS 6.5.

I just need to get the Total TX and RX bytes stats for all my queues.

My queues are static created, and all have Local - xxxxx or Management - xxxxx in the name section of the Queue. i havent used comments on any of the Queues.

any info would be greatly appreciated.

Regards
Wes
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: print simple queue name and stats in the same command..

Fri Oct 25, 2013 7:22 pm

If you want the total bytes of ALL simple queues added together, try this (edit the /tool email line with your info):

ros code

/queue simple
:local upload 0
:local download 0
:foreach i in=[find] do={
  :local bytes [get $i bytes]
  :set upload ($upload + [:pick $bytes 0 [:find $bytes "/"]])
  :set download ($download + [:pick $bytes ([:find $bytes "/"]+1) [:len $bytes]])
}
/tool e-mail ... body="Queue Stats - u: $upload, d: $download"
If you want to test it in the console, enclose the whole script in brackets { } and replace the "/tool email..." line with:

ros code

:put "u: $upload, d: $download"
You can also view each queue's stats by putting this line after the ":set download..." line:

ros code

:put ([get $i name] . " - " . [:pick $bytes 0 [:find $bytes "/"]] . " / " . [:pick $bytes ([:find $bytes "/"]+1) [:len $bytes]])