简体   繁体   English

用于检查有关CPU,内存,网络,NAT表使用情况的信息的API

[英]API to check information about CPU, memory, network, NAT table usage

I am developing an embedded Linux system (2.6 kernel and uclibc) and I need to check for cpu, memory, network, NAT Table usage, etc... 我正在开发嵌入式Linux系统(2.6内核和uclibc),我需要检查cpu,内存,网络,NAT表的使用情况等。

Which API should I use? 我应该使用哪个API? Where can i check it? 我在哪里可以查看? I have visited some websites about the Linux kernel API but didnt find any direct information about. 我已经访问了一些有关Linux内核API的网站,但没有找到任何有关它的直接信息。 Any suggestion or recommendation? 有什么建议或建议吗?

My program is written in C with uclibc and gcc 3.4.6 我的程序是用uclibc和gcc 3.4.6用C编写的

Thanks 谢谢

All the information you're after (and much, much more) is available in procfs: 您所需要的所有信息(甚至更多)都可以在procfs中找到:

  • CPU: /proc/uptime , /proc/stat CPU: /proc/uptime/proc/stat
  • Memory: /proc/meminfo 内存: /proc/meminfo
  • Network: /proc/net/dev 网络: /proc/net/dev
  • NAT: /proc/net/ip_conntrack NAT: /proc/net/ip_conntrack

As an aside: GCC 3.4.6 is reeealllly old. 顺便说一句:GCC 3.4.6确实已经过时了。 The oldest currently maintained version is 4.4; 当前最旧的维护版本是4.4; I'd recommend upgrading if possible. 如果可能,我建议升级。 Buildroot will automate a lot of the process for you. Buildroot将为您自动化许多过程。

the proc file system is fairly optimal: it is a virtual file system, where all of the contents are actually created upon a read. proc文件系统是相当理想的:它是一个虚拟文件系统,其中的所有内容实际上都是在读取时创建的。 So if noone reads info, it isn't generated. 因此,如果没有人阅读信息,则不会生成信息。

The beauty of a text file-based interface is that it is both human readable and machine readable at the same time. 基于文本文件的界面的优点在于,它既是人类可读的又是机器可读的。 Secondly, there are no endianess issues and things like that - it works better across architectures. 其次,没有任何局限性问题之类的东西-在整个体系结构中效果更好。 Compared to running ioctls, which was done for a few subsystems including V4L and ALSA, it has the beauty that it is also compiler (eg #pragma pack) and ABI independent - ask ARM developers about the OABI to EABI change if you enjoy horror stories... 与运行ioctls相比,后者是针对包括V4L和ALSA在内的一些子系统完成的,它的优点在于它也是编译器(例如,#pragma pack)和ABI独立的-如果您喜欢恐怖的故事,请向ARM开发人员询问有关OABI向EABI的更改...

Note that the contents of procfs and sysfs are considered part of the stable kernel interfaces, no developer is allowed to change anything at random. 请注意,procfs和sysfs的内容被视为稳定内核接口的一部分,不允许开发人员随意更改任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM