-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from furaihan/upstream
- menambahkan perintah ``/monitoring`` yang berfungsi untuk mengamati transfer rate dan received rate dari interface, juga bisa untuk mengamati penggunaan CPU serta RAM - menambah perintah ``/stop`` untuk menghentikan proses monitoring yang sedang berjalan di telegram video: [YouTube](https://www.youtube.com/watch?v=0HEuqgMZVp4)
- Loading branch information
Showing
4 changed files
with
236 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
:local send [:parse [/system script get tg_sendMessage source]] | ||
:local tolower [:parse [/system script get func_lowercase source]] | ||
:local param1 [:pick $params 0 [:find $params " "]] | ||
:local param2 [:pick $params ([:find $params " "]+1) [:len $params]] | ||
:local param3 [:pick [:pick $params ([:find $params " "]+1) [:len $params]] ([:find [:pick $params ([:find $params " "]+1) [:len $params]] " "]+1) [:len [:pick $params ([:find $params " "]+1) [:len $params]]]] | ||
:if ([:len [:find $param2 " "]]>0) do={ | ||
:set param2 [:pick [:pick $params ([:find $params " "]+1) [:len $params]] 0 [:find [:pick $params ([:find $params " "]+1) [:len $params]] " "]] | ||
} else={ | ||
:set param3 "" | ||
} | ||
|
||
:local fconfig [:parse [/system script get tg_config source]] | ||
:local config [$fconfig] | ||
:local botID ($config->"botAPI") | ||
|
||
:local counting 0; | ||
|
||
#======================================================= | ||
#monitoring akan dipaksa berhenti setelah x detik (default 50) | ||
:local forceStopAfter 50; | ||
#======================================================= | ||
|
||
:local paramsLower [$tolower $params] | ||
:local param1Lower [$tolower $param1] | ||
:local param2Lower [$tolower $param2] | ||
:local param3Lower [$tolower $param3] | ||
|
||
:local forceStop do={ | ||
:global monitoring; | ||
:set monitoring false; | ||
:delay 2s; | ||
/system script environment remove monitoring; | ||
/system script job remove [find where script=tg_getUpdates]; | ||
} | ||
|
||
:local prepare do={ | ||
:local gkey [:parse [/system script get tg_getkey source]] | ||
:local fconfig [:parse [/system script get tg_config source]] | ||
:local config [$fconfig] | ||
:local botID ($config->"botAPI") | ||
:local url ("https://api.telegram.org/bot".$botID."/sendMessage\?chat_id=$chatid&text=Preparing...") | ||
:put $url | ||
:local fetching ([/tool fetch url=$url output=user as-value]->"data") | ||
:local msgID [$gkey key="message_id" text=$fetching] | ||
:return $msgID | ||
} | ||
|
||
:global monitoring true; | ||
|
||
:if ($param1Lower = "interface") do={ | ||
:if ([:len [/interface find where name=$param2]] > 0) do={ | ||
:local msgid [$prepare chatid=$chatid] | ||
:put $msgid | ||
:while ($monitoring) do={ | ||
:local rxData ((([/interface monitor-traffic $param2 once as-value]->"rx-bits-per-second")/1000)/1); | ||
:local txData ((([/interface monitor-traffic $param2 once as-value]->"tx-bits-per-second")/1000)/1); | ||
:local text ("$param2%0ARX: $rxData kb/s%0ATX: $txData kb/s"); | ||
/tool fetch url="https://api.telegram.org/bot$botID/editMessageText\?chat_id=$chatid&message_id=$msgid&text=$text" output=none | ||
:set counting ($counting + 1); | ||
:if ($counting > $forceStopAfter) do={$forceStop;} | ||
} | ||
:return true; | ||
|
||
} else={ | ||
$send chat=$chatid text=("Interface $param2 tidak ditemukan") | ||
} | ||
} | ||
|
||
:if ($paramsLower = "cpu") do={ | ||
:local msgid [$prepare chatid=$chatid] | ||
:put $msgid | ||
:local identity ([/system identity get name]) | ||
:while ($monitoring) do={ | ||
:local cpuLoad [/system resource get cpu-load] | ||
:local text ("Router Id: ".$identity."%0ACPU-LOAD: ".$cpuLoad."%25") | ||
/tool fetch url="https://api.telegram.org/bot$botID/editMessageText\?chat_id=$chatid&message_id=$msgid&text=$text" output=none | ||
:set counting ($counting + 1); | ||
:if ($counting > $forceStopAfter) do={$forceStop;} | ||
} | ||
} | ||
|
||
:if (($paramsLower = "ram") or ($paramsLower = "memory")) do={ | ||
:local msgid [$prepare chatid=$chatid] | ||
:put $msgid | ||
:local totalMemory ([/system resource get total-memory] / 1024 / 1024) | ||
:local identity ([/system identity get name]) | ||
:while ($monitoring) do={ | ||
:local clockTime [/system clock get time] | ||
:local freeMemory ([/system resource get free-memory] / 1024 / 1024) | ||
:local text ("Router Id: ".$identity."%0ATime: $clockTime%0AFree Memory: $freeMemory/$totalMemory MiB") | ||
/tool fetch url="https://api.telegram.org/bot$botID/editMessageText\?chat_id=$chatid&message_id=$msgid&text=$text" output=none | ||
:set counting ($counting + 1); | ||
:if ($counting > $forceStopAfter) do={$forceStop;} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:global monitoring; | ||
:set monitoring false; | ||
:delay 5s; | ||
/system script environment remove monitoring; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters