Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get interface statistic (TZ-1145) #97

Closed
3 tasks done
motters opened this issue Sep 17, 2024 · 10 comments
Closed
3 tasks done

Get interface statistic (TZ-1145) #97

motters opened this issue Sep 17, 2024 · 10 comments

Comments

@motters
Copy link

motters commented Sep 17, 2024

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Described the feature in detail and justified the reason for the request.
  • Provided specific use cases and examples.

Feature description

It would be nice to be able to obtain interface statistics to monitor data usage.

Global stats for all interfaces seem to be available at lwip/stats.h easily enough. However it combines all interfaces (OpenThread, Wifi, Ethernet etc).

It would be better if these stats were accessible for each interface. These seem to be available through via stats_mib2_netif_ctrs at:
esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")->lwip_netif->mib2_counters

However i cannot access this struct without getting compiler errors:
error: invalid use of incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'}

With stats_mib2_netif_ctrs, lwip/stats.h and OpenThread History Functions it would be possible to gain useful statistics on each interface.

Use cases

This would help when the border router is using a cellular interface. Allowing you to keep track for any data increases and where the increase came from.

It also gives a deep in sight into the use of the OpenThread network and backbone.

Alternatives

lwip/stats.h and OpenThread History Functions are available but they don't give all the information such as total number of octets received on the interface which stats_mib2_netif_ctrs does.

Additional context

How can we access the stats_mib2_netif_ctrs for each interface?

@github-actions github-actions bot changed the title Get interface statistic Get interface statistic (TZ-1145) Sep 17, 2024
@motters
Copy link
Author

motters commented Sep 17, 2024

Seem you can access netif via
auto if = (struct netif*) esp_netif_get_netif_impl(network::wifi::get_netif());

However i'm not sure how to enable MIB2_STATS

@zwx1995esp
Copy link
Collaborator

Hi @motters, thanks for addressing this. So just to confirm, for now, you only want to use the lwIP mib_stats feature, correct?

@motters
Copy link
Author

motters commented Sep 18, 2024

Hi,

Yes.

How can we access mib_stats feature (struct stats_mib2_netif_ctrs) for each network interface (WiFi, Ethernet, OpenThread)? Then we can wrap some REST APIs around it.

Cheers!

@zwx1995esp
Copy link
Collaborator

zwx1995esp commented Sep 26, 2024

Hi @motters , just ask the question how to enable the feature mib_stats in lwip to who is responsable to LwIP, and here are the replies:
For now, we do not have a menuconfigration to enable this feature via idf.py menuconfig. And if you want to use this feature, you can refer to here: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#customized-lwip-options-from-esp-idf-build-system.
I have tried this, and it might work with these two changes:

  1. add these two lines in the file components/lwip/CMakeLists.txt
    idf_component_get_property(lwip lwip COMPONENT_LIB)
    target_compile_definitions(${lwip} PRIVATE "-DMIB2_STATS=1")
  1. enable the LWIP_STATS via idf.py menuconfig
    image

then build your apps.

Please have a try. The LwIP group will support to enable this feature via idf.py menuconfig later.

@motters
Copy link
Author

motters commented Sep 27, 2024

Thanks @zwx1995esp I'll give this a try and report back what information can be obtained.

@motters
Copy link
Author

motters commented Oct 31, 2024

@zwx1995esp Sorry slow on this. I've tried the about bit still cannot access.

I cannot access the lwip_netif struct
error: invalid use of incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'} 56 | auto wifi_data = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")->lwip_netif;

I cannot include the struct esp_netif_t as it's defined with esp_netif_lwip_internal.h which is not accessible.

@zwx1995esp
Copy link
Collaborator

Hi, @motters try this:

netif *wifi_data = esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));

@motters
Copy link
Author

motters commented Nov 1, 2024

@zwx1995esp Thanks thats works netif *wifi_data = (struct netif*) esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));

However to gain access to wifi_data->mib2_counters i had to open esp/v5.1/esp-idf/components/lwip/lwip/src/include/lwip/opt.h and add #define MIB2_STATS 1to line 2251

The code now compiles however the values within mib2_counters are always zero no matter how much data is transferred via the interface.

@zwx1995esp
Copy link
Collaborator

The code now compiles however the values within mib2_counters are always zero no matter how much data is transferred via the interface.

Hi @motters , this seems to be related to the lwIP components. you can create an issue in ESP-IDF to ask for some help from the person responsible for lwIP components.

@chshu
Copy link
Collaborator

chshu commented Nov 29, 2024

@motters please follow up in the IDF lwip component, feel free to link the new issue here.

@chshu chshu closed this as completed Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants