Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
zh:docs:guide-user:services:network_monitoring:bandwidthd [2022/11/20 12:18] – [Storing bandwidthd stats in external permanent storage] yodozh:docs:guide-user:services:network_monitoring:bandwidthd [2022/11/21 07:42] – [使用] yodo
Line 9: Line 9:
 **Note: bandwidthd in LEDE/OpenWRT 17.01 or higher tracks the SMTP data (ports 25, 465 and 587) while the version in the previous version of OpenWrt (Chaos Calmer and older) tracks the P2P data (Gnutella, eDonkey, etc.).  All of the other data (FTP, UDP, TCP, etc.) is tracked the same way in all versions.** **Note: bandwidthd in LEDE/OpenWRT 17.01 or higher tracks the SMTP data (ports 25, 465 and 587) while the version in the previous version of OpenWrt (Chaos Calmer and older) tracks the P2P data (Gnutella, eDonkey, etc.).  All of the other data (FTP, UDP, TCP, etc.) is tracked the same way in all versions.**
  
-**Bandwidthd is composed of packages: +**Bandwidthd涉及到4个软件包:**
-** +
-    **bandwidthd**: this package cannot save in a postgresql or sqlite database. This allows the router to generate bandwidth data that is accessible with a browser at http://192.168.1.1/bandwidthd.  **__//Use this package if you have no intention of storing the data on a postgresql or sqlite database.//__** +
-  -   **bandwidthd-pgsql**: this package can do everything the bandwidthd package can do, but in addition it can save the data to a postgresql database that can reside on the router or on another server.  This data can be analyzed by a series of PHP scripts and visualized with a browser.  Note that the router, the posgresql database and the graphing of the data by PHP can be on three different systems, one for each task (i.e.: __collecting the data__, __storing the postgresql data__ and __generating the graphs with PHP__).  Note that postgresql does not have to be installed on the router if the postgresql data is not stored on the router. **NOTE: install only one of the package: bandwidthd, bandwidthd-pgsql or bandwidthd-sqlite.** +
-  -   **bandwidthd-php**: This package contains the PHP files that are installed in /www/phphtdocs on the router.  It is only required if the OpenWrt router serves as the web server to generate the graphs from the data on the postgresql database by pointing the browser to http://192.168.1.1/phphtdocs.  **NOTE: if you installed bandwidthd-sqlite, do not install bandwidthd-php as bandwidthd-sqlite contains the required PHP files to graph the data.** +
-  - **bandwidthd-sqlite**.  This package, in addition to do what the plain bandwidthd package can do, stores the data in a sqlite database on the router and graph the data using PHP.  In a way, it is a combination of bandwidthd-pgsql and bandwidthd-php together, but using sqlite instead of postgresql.  **NOTE: install only one of the package: bandwidthd, bandwidthd-pgsql or bandwidthd-sqlite.**+
  
-The availability of each package varies according to which version of OpenWrt/LEDE you have:+**注意:bandwidthd, bandwidthd-pgsql, bandwidthd-sqliteinstall 只能安装三者中的一个!!** 
 + 
 +  -  **bandwidthd**: 如果安装这个包,不能保存数据到postgresql 或者 sqlite 数据库。路由器生成的bandwidth数据,可以通过这个网址访问 http://192.168.1.1/bandwidthd.  **__//也就是如果您不需要保存数据到 postgresql 或者 sqlite 数据库,那么安装这个包即可。注意:路由器重启后历史数据会丢失。//__** 
 +  -   **bandwidthd-pgsql**: bandwidthd能干的活,这个包也能干,同时还支持保存数据到postgresql数据库,这个数据库可以位于路由器或者其他服务器。这些数据可以由PHP脚本分析,并在浏览器内展现。需要知晓的是,路由器、posgresql数据库、生成图形的PHP服务,可以位于3个不同设备上,各自分工一项任务(例如:路由器收集数据,然后发送至单独的数据库服务器,然后PHP服务器调取数据库服务器的数据生成图形展示)。如果postgresql数据不保存在路由器上,那么没有必要安装postgresql包。 
 +  -   **bandwidthd-php**: 这个包提供了PHP文件位于路由器的/www/phphtdocs目录。只有在OpenWrt路由器作为网页服务器生成图形时才需要安装,访问 http://192.168.1.1/phphtdocs.  **注意:如果安装bandwidthd-sqlite则不要安装bandwidthd-php,因为bandwidthd-sqlite包含了所需的PHP文件用于生成图形文件。** 
 +  - **bandwidthd-sqlite**.  这软件包,除了bandwidthd能干的活以外,还可以保存数据到路由器的sqlite数据库,也能够通过PHP生成图形文件。在某种意义上来说,它是 bandwidthd-pgsql 和 bandwidthd-php 的组合, 但是是使用的sqlite数据库而不是postgresql。 
 + 
 +不同的版本的OpenWrt/LEDE可用包情况不一致:
  
 **bandwidthd** **bandwidthd**
Line 37: Line 39:
 ===== 安装 ===== ===== 安装 =====
  
-For the bandwidthd package:+安装bandwidthd包:
 <code bash> <code bash>
 opkg install bandwidthd uhttpd opkg install bandwidthd uhttpd
Line 46: Line 48:
 </code> </code>
  
-For the bandwidthd-pgsql package (note: do not install uhttpd if you do not plan for the router to perform the graphs):+安装bandwidthd-pgsql包(注意:如不在路由器上生成图形,那么可以不安装uhttpd):
 <code bash> <code bash>
 opkg install bandwidthd-pgsql uhttpd opkg install bandwidthd-pgsql uhttpd
Line 55: Line 57:
 </code> </code>
  
-With all dependencies it uses around 500 kB of storage space.  If you have not changes the IP address of your router (192.168.1.1), then the web page with the bandwidthd data will be available at http://192.168.1.1/bandwidthd.  If you have changed the IP address of your router, then edit the /etc/config/bandwidthd file to correct the address.+所需其他依赖大致需要500kB空间,如果路由器IP地址为默认的192.168.1.1,那么即可通过 http://192.168.1.1/bandwidthd 访问服务。 如果修改了路由器IP,那么编辑配置文件(/etc/config/bandwidthd)内的IP地址为修改后的IP。
  
 ===== 配置 ===== ===== 配置 =====
  
-Packages **bandwidth**, **bandwidthd-pgsql** and **bandwidthd-sqlite** use basically the same configuration file: ///etc/config/bandwidthd+3个软件包 **bandwidth**, **bandwidthd-pgsql** 和 **bandwidthd-sqlite** 默认使用同一个配置文件: ///etc/config/bandwidthd
 // //
  
-Each package installs the proper configuration file, and usually requires very little modifications, if any.+无论哪一个软件包,安装后都会自动生成合适的配置文件,通常需要修改的配置项目不多(如果有的话)。
  
-The options are the same for the packages, with two additional for **bandwidthd-pgsql** and two others for **bandwidthd-sqlite**.+3个软件包的基础配置选项是一样的。**bandwidthd-pgsql**有额外2个配置项,**bandwidthd-sqlite**也有另外2个配置项。
  
-Here are the various options:+具体配置选项:
  
-__option dev__: Device to listen on.  The default is __br-lan__.+__option dev__: 监听的设备,默认是 __br-lan__.
  
-__option subnets__: Subnets to collect statistics on.  Traffic that matches none of these subnets will be ignored. Syntax is either IP Subnet Mask or CIDR.  Ex: __"10.0.0.0 255.0.0.0"__, __"192.168.0.0/16"__ or __"172.16.0.0/12"__. The defaults is __"192.168.1.0/24"__.+__option subnets__: 子网设置,不是制定子网的流量信息不进行统计,设置选项可以是IP子网掩码或CIDR。例如: __"10.0.0.0 255.0.0.0"__, __"192.168.0.0/16"__ or __"172.16.0.0/12"__. 默认 __"192.168.1.0/24"__.
  
-__option skip_intervals__: An interval is 2.5 minutes, this is how many intervals to skip before doing a graphing run.  The default is __0__.+__option skip_intervals__: 重新生成图形文件的时间间隔,默认是 __0__.
  
-__option graph_cutoff__: Graph cutoff is how many k must be transferred by an ip before we bother to graph it.  The default is __1024__.+__option graph_cutoff__: 制定一个IP生成图形数据的起始流量大小,单位是K,默认是 __1024__.
  
-__option promiscuous__: Put interface in promiscuous mode to score to traffic that may not be routing through the host machine.  The default is __true__.+__option promiscuous__: 将接口设置为混杂模式,以对可能未通过主路由的流量进行记录,默认是 __true__.
  
-__option output_cdf__: Log data to cdf file __log.cdf__.  All packages can log to cdf files.  These are only useful if you are using the **bandwidthd** package as the other packages (**bandwidthd-pgsql** and **bandwidthd-sqlite**) can store the data in a database.  These files are located on the root of the router (/).  The cdf files can be read when bandwidthd is started (see the option recover_cdf), which is useful if you reboot the router to recover the bandwidth data.  The default is __false__.+__option output_cdf__: 将数据记录到cdf文件(log.cdf),所有软件包都可以记录到cdf文件,但仅在使用 bandwidthd 包时有用,因为其他包(bandwidthd-pgsql 和 bandwidthd-sqlite)可以将数据存储在数据库中。这些文件位于路由器的根目录 (/)。 bandwidthd启动时可以读取cdf文件(请参阅选项 recover_cdf),在您重启路由器可以恢复bandwidthd统计数据。 默认设置为 __false__.
  
-__option recover_cdf__: Read back the cdf file on startup.  See the comments for __output_cdf__ above.  The default is __false__.+__option recover_cdf__: 在启动时重新读取cdf文件。请参阅上面 __output_cdf__ 的说明。默认值为 __false__
  
-__option filter__: Libpcap format filter string used to control what bandwidthd see's.  Please always include "ip" in the string to avoid strange problems.  The default is __ip__.+__option filter__: Libpcap 格式过滤器字符串用于控制 bandwidthd 能看到的内容。请始终在字符串中包含“ip”以避免出现奇怪的问题。默认值为 __ip__
  
-__option graph__: Draw Graphs This default to true to graph the traffic bandwidthd is recording.  Usually set this to false if you only want cdf output or you are using the database output option (**bandwidthd-pgsql** or **bandwidthd-sqlite**).  Bandwidthd will use very little ram and cpu if this is set to false.  The defaults is __true__.+__option graph__: 生成图形文件 默认为 true 以绘制bandwidthd正在记录的流量图。如果您只需要 cdf 输出或者您正在使用数据库输出选项(**bandwidthd-pgsql** 或 **bandwidthd-sqlite**),那颗可将此设置为 false。如果设置为 false,Bandwidthd 将使用较少的内存和cpu。默认值为 __true__
  
-__option meta_refresh__: Set META REFRESH seconds (default 150, use to disable).  Default is __150__.+__option meta_refresh__: 设置元数据刷新时长,单位为秒(默认为150,设置0禁用),默认是 __150__.
  
-__option pgsql_connect_string__: Only used for **bandwidthd-pgsql**.  Standard postgres connect string.  The default is __"user = postgres dbname = bandwidthd host = 192.168.1.1"__.+__option pgsql_connect_string__: 仅用于 **bandwidthd-pgsql**。postgre数据库连接字符串。默认是 __"user = postgres dbname = bandwidthd host = 192.168.1.1"__.
  
-__option sensor_id__:  Used for **bandwidthd-pgsql** and **bandwidthd-sqlite**.  Arbitrary sensor name.  It can be anything you want for **bandwidthd-pgsql** but it has to be __"default"__ for **bandwidthd-sqlite**.  Default is __"openwrt"__ for **bandwidthd-pgsql**.+__option sensor_id__:  适用于 **bandwidthd-pgsql** 和 **bandwidthd-sqlite**,设置sensor名称,对于 **bandwidthd-pgsql**,可设置为任何内容,但对于 **bandwidthd-sqlite**,必须是 __"default"__。 **bandwidthd-pgsql** 的默认值为 __"openwrt"__。
  
-__option sqlite_filename__: Only used for **bandwidthd-sqlite**.  This is the sqlite database file.  Default is __"/www/bandwidthd/stats.db"__.+__option sqlite_filename__: 仅适用 **bandwidthd-sqlite**,这个是 sqlite 数据库文件。默认是 __"/www/bandwidthd/stats.db"__.
  
-The package **bandwidthd-php** uses another configuration file: ///etc/config/bandwidthd-php//.  Package **bandwidthd-sqlite** can also use the //bandwidthd-php// configuration file (**bandwidthd-sqlite** uses two configuration files: ///etc/config/bandwidthd// and ///etc/config/bandwith-php//).+**bandwidthd-php**软件包使用另外一个配置文件:///etc/config/bandwidthd-php//。这个配置文件**bandwidthd-sqlite**也可使用(**bandwidthd-sqlite** 适用2个配置文件: ///etc/config/bandwidthd// 和 ///etc/config/bandwith-php//)
  
-**NOTE:** the **bandwidthd-sqlite** package does not provide the ///etc/config/bandwidthd-php// file: it is not needed as the init file (///etc/init.d/bandwidthd//) will provide the bandwidthd application the default graph sizes (900 and 256) and interval (INT_DAILY) and the default sqlite database: ///www/bandwidthd/stats.db//.  Create a /etc/config/bandwidthd-php file for bandwidthd-sqlite if you need to change the default.+**注意:** **bandwidthd-sqlite** 软件包不提供 ///etc/config/bandwidthd-php// 文件(非必要),由于初始化文件(///etc/init.d/bandwidthd//)会为bandwidthd应用提供默认的图形尺寸(900256)和interval选项(INT_DAILY),以及默认的sqlite数据库: ///www/bandwidthd/stats.db//。如需修改默认,那么为bandwidthd-sqlite自行建立一个配置文件(/etc/config/bandwidthd-php)即可。
  
-Here are the options of the ///etc/config/bandwidthd-php// configuration file:+///etc/config/bandwidthd-php// 配置如下:
  
-__option dflt_width__:  Widthd of the graphs generated.  Default is __'900'__.+__option dflt_width__:  宽度。默认 __'900'__.
  
-__option dflt_height__: height of the graphs generated.  Default is __'256'__.+__option dflt_height__: 高度。默认 __'256'__.
  
-__option dflt_interval__: Defaultinterval for the graphs.  The default is __'INT_DAILY'__.  Options are: __INT_DAILY__,  __INT_WEEKLY__, __INT_MONTHLY__ and __INT_YEARLY__.+__option dflt_interval__: 图形展示的默认间隔时长,默认值是 __'INT_DAILY'__。可选项为: __INT_DAILY__,  __INT_WEEKLY__, __INT_MONTHLY__ and __INT_YEARLY__.
  
-__option host__: This is for the host that has the postgresql database.  The default is __'127.0.0.1'__ which is the router.+__option host__: 设置postgresql数据库服务器的IP,默认是 __'127.0.0.1'__ 也就是路由器本身。
  
-__option user__: This is the user owning the postgresql database.  Default is __'postgres'__.+__option user__: 设置访问postgresql数据库的用户名,默认是 __'postgres'__
  
-__option dbname__: This is the name of the postgresql database.  Default is __'bandwidthd'__+__option dbname__: 设置postgresql数据库的名称,默认是 __'bandwidthd'__
- +
-A ///etc/config/bandwidthd-php// for **bandwidthd-sqlite** will have the same structure, but the options __host__, __user__ and __dbname__ are not needed and are replaced by the following:+
  
 +为**bandwidthd-sqlite**建立的 ///etc/config/bandwidthd-php// 配置文件也是一样的数据结构,但是以下选项不需要 __host__, __user__ and __dbname__。替换为:
 __option sqlite_dbname "/www/bandwidthd/stats.db"__ __option sqlite_dbname "/www/bandwidthd/stats.db"__
  
Line 119: Line 120:
 ===== 使用 ===== ===== 使用 =====
  
-By default, bandwidthd hosts its statistics at /bandwidthd. All packages (**bandwidthd**, **bandwidthd-pgsql** and **bandwidthd-sqlite**) are set by default to graph and if this is not the behaviour that you want, then change the __option graph__ to __false__ in the configuration file (///etc/config/bandwidthd// For example, if the OpenWRT router'IP address is 192.168.1.1, bandwidthd's stats would be available at http://192.168.1.1/bandwidthd +默认情况下bandwidthd在 /bandwidthd 目录存放分析数据。任意一个软件包 (**bandwidthd**, **bandwidthd-pgsql** and **bandwidthd-sqlite**) 默认设置均会生成图形文件,如果不需要生成,修改配置文件(///etc/config/bandwidthd//)的 __option graph__ 选项为 __false__    如果路由器IP192.168.1.1,那么即可访问http://192.168.1.1/bandwidthd
- +
-**bandwidthd-pgsql** can store in a postgresql database and PHP has to be used to generate the graphs that are available at http://192.168.1.1/phphtdocs/index.php (see below) (of course, change the IP address to the one of the web server hosting the PHP files (your router or whatever web server you are using to graph the data)).+
  
 +**bandwidthd-pgsql** 可以将数据库保存到postgresql数据库,然后通过PHP生成图形文件,访问地址为:http://192.168.1.1/phphtdocs/index.php 
 +当然,这里的IP需要修改为web服务器(包含PHP文件)的IP,可以是你的路由器或者其他任何服务器(只要能生成图形文件)。
 ===== 在外置存储空间保存bandwidthd数据 ===== ===== 在外置存储空间保存bandwidthd数据 =====
  
-The default bandwidthd installation loses your previous statistics on each reboot and you need more space to save those. To keep statistics it is needed to modify "/etc/config/bandwidthd".+默认情况下bandwidthd会在重启后丢失之前的数据,如果保存历史数据,那么需要更大的储存空间。通过编辑"/etc/config/bandwidthd"配置文件,设置保存历史数据。
  
-You need to change "option output_cdf true" and "option recover_cdf true" and "option sqlite_filename    'file.db' "+修改3个选项: "option output_cdf true" 和 "option recover_cdf true" 和 "option sqlite_filename    'file.db' "
  
 <file> <file>
Line 141: Line 142:
  option graph true  option graph true
  option meta_refresh 150  option meta_refresh 150
-        option SQLite_filename  "/path/to/file.db"file gets created automatically and default path works pretty well+        option SQLite_filename  "/path/to/file.db"默认的配置可以自动生成数据库文件,通常能正常使用。 如果有外置储存空间,按需设置实际的储存空间目录。
 </file> </file>
  
  
-After modifying both of the files, restart the service. Afterwards, you will get a file and directory structure on your external mount like this:+修改完配置文件后,重启服务,然后在外置储存目录内会自动生成下列文件结构:
  
 <file> <file>
  • Last modified: 2022/11/21 11:33
  • by yodo