hello, I have a script for monitoring simple queues using a telegram bot, but for data usage it only displays bytes, is there a way to change it to mb or gb to make it easier to read?
:local download;
:local upload;
:local bot "BOT ID";
:local chat "CHAT ID";
:local tanggal "Tanggal: $[/system clock get date] %0A";
:foreach queue in=[/queue simple find parent="CLIENT HOTSPOT"] do={
:local name ("Name".[/queue simple get value-name="name" $queue]."%0A")
:local byte ("Usage".[/queue simple get value-name="byte" $queue]." Bytes %0A")
:local trafik ("Trafik ".[/queue simple get value-name="rate" $queue]." %0A")
:local limit ("Limit ".[/queue simple get value-name="max-limit" $queue]." %0A")
:set download ($name.$byte.$trafik.$limit)
/tool fetch url="https://api.telegram.org/bot$bot/sendmessage\?chat_id=$chat&text=Pemakaian internet: %0A$tanggal$download" keep-result=no;
}
You can use simple arithmetic operators on returned values i.e. bytes → kilobytes is divide bytes by 1024 (( [bytes] / 1024) for instance), where 5120 bytes becomes 5kilobytes, continue up the chain by dividing 1024 t o get to desired value
bytes / 1024 = kilobytes
kb / 1024 = megabytes
mb / 1024 = gigabytes
gb / 1024 = terrabytes
so on…
You can use simple arithmetic operators on returned values i.e. bytes → kilobytes is divide bytes by 1024 (( [bytes] / 1024) for instance), where 5120 bytes becomes 5kilobytes, continue up the chain by dividing 1024 t o get to desired value
bytes / 1024 = kilobytes
kb / 1024 = megabytes
mb / 1024 = gigabytes
gb / 1024 = terrabytes
so on…
i tried to apply it like this but it still doesn’t work
:local download;
:local upload;
:local bot "BOT ID";
:local chat "CHAT ID";
:local tanggal "Tanggal: $[/system clock get date] %0A";
:foreach queue in=[/queue simple find parent="CLIENT"] do={
:local name ("Name".[/queue simple get value-name="name" $queue]."%0A")
:local byte ("Usage".[/queue simple get value-name="byte" $queue]." Bytes %0A")
:local byteMB ("Total Usage".($byte / 1024 / 1024)." Mb%0A")
:local trafik ("Trafik ".[/queue simple get value-name="rate" $queue]." %0A")
:local limit ("Limit ".[/queue simple get value-name="max-limit" $queue]." %0A")
:set download ($name.$byteMB.$trafik.$limit)
/tool fetch url="https://api.telegram.org/bot$bot/sendmessage\?chat_id=$chat&text=Internet usage: %0A$tanggal$download" keep-result=no;
}
:global bot "BOT ID"
:global chat "CHAT ID"
:global download ""
# unused :global upload ""
:global tanggal "Tanggal:+$[/system clock get date]%0A"
/queue simple
:foreach queue in=[find parent="CLIENT"] do={
:local name ("Name+".[get $queue "name"]."%0A")
:local ubyte ("Usage+".[get $queue "bytes"]."+Bytes%0A")
:local totalbyte ("Total+Usage+".[get $queue "total-bytes"]."+Bytes%0A")
:local trafik ("Trafik+".[get $queue "rate"]."%0A")
:local limit ("Limit+".[get $queue "max-limit"]."%0A")
:set download ($name.$ubyte.$totalbyte.$trafik.$limit)
/tool fetch keep-result=no url="https://api.telegram.org/bot$bot/sendmessage\?chat_id=$chat&text=Internet+usage:%0A$tanggal$download"
}
On terminal, for test keep \ before ?, but on script remember to remove it…
“total-bytes” and “bytes” returning only pair of values like “3454401/2081207”
It’s useless multiply It…
must be splitted first…
You can use simple arithmetic operators on returned values i.e. bytes → kilobytes is divide bytes by 1024 (( [bytes] / 1024) for instance), where 5120 bytes becomes 5kilobytes, continue up the chain by dividing 1024 t o get to desired value
bytes / 1024 = kilobytes
kb / 1024 = megabytes
mb / 1024 = gigabytes
gb / 1024 = terrabytes
so on…
Please update your knowledge.
1000 bit = 1 kilobit (kb)
1000 kb = 1 Megabit (Mb)
1000 Mb = 1 Gigabit (Gb)
1000 Gb = 1 Terabit (Tb)
8 bit = 1 Byte
1000 Byte = 1 kiloByte (kB)
1000 kB = 1 MegaByte (MB)
1000 MB = 1 GigaByte (GB)
1000 GB = 1 TeraByte (TB)
8 bit = 1 Byte
1024 Byte = 1 KibiByte (KiB)
1024 KiB = 1 MebiByte (MiB)
1024 MiB = 1 GibiByte (GiB)
1024 GiB = 1 TebiByte (TiB)
MikroTik follow the standard from 1999
https://en.wikipedia.org/wiki/Binary_prefix#Adoption_by_IEC,_NIST_and_ISO
:global bot "BOT ID"
:global chat "CHAT ID"
:global download ""
# unused :global upload ""
:global tanggal "Tanggal:+$[/system clock get date]%0A"
/queue simple
:foreach queue in=[find parent="CLIENT"] do={
:local name ("Name+".[get $queue "name"]."%0A")
:local ubyte ("Usage+".[get $queue "bytes"]."+Bytes%0A")
:local totalbyte ("Total+Usage+".[get $queue "total-bytes"]."+Bytes%0A")
:local trafik ("Trafik+".[get $queue "rate"]."%0A")
:local limit ("Limit+".[get $queue "max-limit"]."%0A")
:set download ($name.$ubyte.$totalbyte.$trafik.$limit)
/tool fetch keep-result=no url="https://api.telegram.org/bot$bot/sendmessage\?chat_id=$chat&text=Internet+usage:%0A$tanggal$download"
}
On terminal, for test keep \ before ?, but on script remember to remove it...
"total-bytes" and "bytes" returning only pair of values like "3454401/2081207"
It's useless multiply It...
must be splitted first...
and how to do it, do you have an example for me to make as a reference?