FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
642 views 6 comments
by anonymous
Hi everybody!

I want to find out the "answers" from a Teltonika router for the following params, using JSON-RPC:

- CPU Load

- Memory usage (RAM and/or flash)

- Uptime

- IN/OUT data traffic for WAN interface (bytes or so)

- IN/OUT data traffic for LAN interface for all ports (bytes or so)

If there are not JSON-RPC support for any commands, please specify other ways to extract these info.

Thanks a lot!

1 Answer

0 votes
by anonymous

Hello,

Thank you for reaching out!

Indeed, this information can be received when using JSON-RPC. Here are some ways how to gather the needed parameters:

  • CPU Load:
    • Command top with argument -n1 could be used. This will return CPU usage, RAM usage, and running processes.
    • JSON syntax would look like this:
{
    "jsonrpc": "2.0", "id": 1, "method": "call", "params": 
    [
        "[session_id]", "file", "exec",
        {
            "command":"top",
            "params":
            [
                "-n1"
            ]
        }
    ]
}
  • Memory usage (RAM and/or flash):
    • RAM can be retrieved with the previously mentioned command. 
    • For storage, command ubus call vuci.system "diskfree" can be used. An alternative is the command df:
{
    "jsonrpc": "2.0", "id": 1, "method": "call", "params": 
    [
        "[session_ID]", "file", "exec",
        {
            "command":"df"
        }
    ]
}
  • Uptime:
    • For the rest of the commands I won't post the entire query, but the commands themselves, as they follow the same structure.
    • for uptime command cat can be used with argument /proc/uptime;
    • This will return values like 350735.47 234388.90, where:
      • 350735.47 - number of seconds from system boot;
      • 234388.90 - sum of how much time each core has spent idle, in seconds;
  • IN/OUT data traffic for WAN interface (bytes or so):
    • For this, AT commands can be utilized;
    • Bytes send from the WAN interface - gsmctl -e eth1 (gsmctl is the command, -e eth1 are the arguments)
    • Bytes received from the WAN interface - gsmctl -r eth1
    • Interface name (eth1) may differ from device to device;
  • IN/OUT data traffic for LAN interface for all ports (bytes or so):
    • The same command gsmctl can be utilized, except interface br-lan should be used.
More information about JSON-RPC can be found here. JSON-RPC is very versatile and can be used to control almost anything on the device using ubus, uci, and other commands.
  

Let me know if any more information is needed!

Best regards,
DaumantasG 

by anonymous

Thank you, very much!

I have two more questions:

1. I didn't succed to test the commands regarding the traffic: they work on CLI but don't work with JSON PRC- should I change the firmware? (my current firmware is: RUT2XX_R_00.01.14.3). The received JSON string is:

{
    "jsonrpc""2.0",
    "id"1,
    "result": [
        0,
        {
            "code"0,
            "stdout""N/A\n",
            "stderr""GSMCTL error: reading message\n"
        }
    ]
}

2. You said the "eth1" logical interfaces can vary from a device to another. How can I found out how the logical interfaces are named (WAN, LAN)?

by anonymous

Hello,

these commands were tested on 07.03, however, they should work on any version above v7. The newest firmware can be downloaded here.

As for your addressed issues:

  • I didn't succed to test the commands regarding the traffic: they work on CLI but don't work with JSON PRC- should I change the firmware? (my current firmware is: RUT2XX_R_00.01.14.3).
    • This is most likely because of outdated firmware. Try updating it and let me know if it still does not work.
  • You said the "eth1" logical interfaces can vary from a device to another. How can I found out how the logical interfaces are named (WAN, LAN)?
    • Logical interface names can be found by using the command ifconfig or ls -l /sys/class/net/ | grep eth when using SSH or CLI. However, for RUT240 eth1 should be the WAN interface.
Let me know if any more help is needed!
Best regards,
DaumantasG
by anonymous

Thank you DaumantasG for your previous answer!

Still got problems: I upgraded my R240 to 07.03 firmware, made a query about WAN traffic

{

    "jsonrpc": "2.0", "id": 1, "method": "call", "params":

    [

        "50371b1fc7c35fbc94c3c9cc3bf78c97", "file", "exec",

        {

            "command":"gsmctl",

            "params":

            [

                "-e eth1"

            ]

        }

    ]

}

and got the error:

{

    "jsonrpc""2.0",

    "id"1,

    "result": [

        0,

        {

            "code"0,

            "stderr""[handle_requests:344] error: Failed to get request.\n"

        }

    ]

}

The command works properly under CLI.

What should I do?

Thanks a lot!

What can I do?

by anonymous

Hello,

as -e and eth1 are separate parameters, they should also be separated in the query. So the JSON query should look like this:

{

    "jsonrpc": "2.0", "id": 1, "method": "call", "params": 

    [

        "[session_id]", "file", "exec",

        {

            "command":"gsmctl",

            "params":

            [

                "-e",

                "eth0"

            ]

        }

    ]

}

Best regards,
DaumantasG

by anonymous

Wow, right!

Thank you very much, DaumantasG!

M. Buican

by anonymous
You're welcome!

Feel free to contact us if any further issues arise!

Best regards,
DaumantasG