OpenWrt Forum Archive

Topic: vnstati package

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Here's a trunk diff for the vnStat image output package, vnstati.

graphs-vnstat.sh provides the same output as http://humdi.net/vnstat/cgidemo/ for the webif.  The vnStat subcategory is shown on 7.09 but not on the trunk so you will have to go to http://<OpenWrt>/cgi-bin/webif/graphs-vnstat.sh directly to see the image output.

Index: files/graphs-vnstat.sh
===================================================================
--- files/graphs-vnstat.sh    (revision 0)
+++ files/graphs-vnstat.sh    (revision 0)
@@ -0,0 +1,109 @@
+#!/usr/bin/webif-page
+<?
+
+. /usr/lib/webif/webif.sh
+. /www/cgi-bin/webif/graphs-subcategories.sh
+
+header_inject_head=$(cat <<EOF
+    <script type="text/javascript" src="/webif.js"></script>
+    <style type="text/css">
+    <!--
+    .monthly {
+        padding-top: 2px;
+    }
+    -->
+    </style>
+EOF
+)
+
+header "Graphs" "vnStat"
+has_pkgs vnstati
+
+LIB_D=${IPKG_INSTROOT}/var/lib/vnstat
+
+interfaces=$(ls $LIB_D)
+if [ -z "$interfaces" ]; then
+    echo "<pre>No database found, nothing to do. Use --help for help.</pre>"
+    echo "<br />"
+    echo "<pre>A new database can be created with the following command:</pre>"
+    echo "<pre>    vnstat -u -i eth0</pre>"
+    echo "<br />"
+    echo "<pre>Replace 'eth0' with the interface that should be monitored. A list</pre>"
+    echo "<pre>of available interfaces can be seen with the 'ifconfig' command.</pre>"
+else
+    interfaces_count=$(ls $LIB_D | wc -l)
+    if [ $interfaces_count -eq 1 ]; then
+        multiple=false;
+    else
+        multiple=true;
+    fi
+
+    BIN=${IPKG_INSTROOT}/usr/bin/vnstati
+    VAR_D=${IPKG_INSTROOT}/var/vnstat
+    WWW_D=${IPKG_INSTROOT}/www/vnstat
+
+    [ -d $VAR_D ] || mkdir -p $VAR_D
+    [ -d $WWW_D ] || mkdir -p $WWW_D
+
+    for interface in $interfaces; do
+        for output in hs s h d t m; do
+            [ -L $WWW_D/vnstat_${interface}_${output}.png ] || ln -sf $VAR_D/vnstat_${interface}_${output}.png $WWW_D/vnstat_${interface}_${output}.png
+            $BIN -${output} -i $interface -c 15 -o $VAR_D/vnstat_${interface}_${output}.png
+        done
+cat <<EOF 
+    <h2>Traffic of Interface $interface</h2>
+EOF
+        if $multiple; then
+cat <<EOF
+    <a href="#" title="Click to see ${interface}'s Details" onclick="set_visible('${interface}_summary', false); set_visible('${interface}_details', true);">
+        <img id="${interface}_summary" src="/vnstat/vnstat_${interface}_hs.png" alt="${interface} Summary" />
+    </a>
+    <a href="#" title="Click to see ${interface}'s Summary" onclick="set_visible('${interface}_details', false); set_visible('${interface}_summary', true);">
+        <table id="${interface}_details" summary="${interface} Details" style="display: none;">
+EOF
+        else
+cat <<EOF
+    <table id="${interface}_details" summary="${interface} Details">
+EOF
+        fi
+cat <<EOF
+        <tbody>
+            <tr>
+                <td>
+                    <img src="/vnstat/vnstat_${interface}_s.png" alt="${interface} Summary" />
+                </td>
+                <td>
+                    <img src="/vnstat/vnstat_${interface}_h.png" alt="${interface} Hourly" />
+                </td>
+            </tr>
+            <tr>
+                <td valign="top">
+                    <img src="/vnstat/vnstat_${interface}_d.png" alt="${interface} Daily" />
+                </td>
+                <td valign="top">
+                    <img src="/vnstat/vnstat_${interface}_t.png" alt="${interface} Top 10" />
+                    <br />
+                    <img class="monthly" src="/vnstat/vnstat_${interface}_m.png" alt="${interface} Monthly" />
+                </td>
+            </tr>
+        </tbody>
+EOF
+        if $multiple; then
+cat <<EOF
+        </table>
+    </a>
+
+EOF
+        else
+cat <<EOF
+    </table>
+
+EOF
+        fi
+    done
+fi
+
+footer ?>
+<!--
+##WEBIF:name:Graphs:0:vnStat
+-->

Property changes on: files/graphs-vnstat.sh
___________________________________________________________________
Name: svn:executable
   + *

Index: Makefile
===================================================================
--- Makefile    (revision 0)
+++ Makefile    (revision 0)
@@ -0,0 +1,66 @@
+#
+# Copyright (C) 2008 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=vnstati
+PKG_VERSION:=beta3
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://humdi.net/vnstat
+PKG_MD5SUM:=5652b955e16716cec48da464b083c76f
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/vnstati
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:=+vnstat +libgd +webif
+  TITLE:=vnStat image output - png image output support for vnStat
+  URL:=http://humdi.net/vnstat/
+endef
+
+define Package/vnstati/description
+    The purpose of vnstati is to provide image output support for statistics
+    collected using vnstat(1). However, the image file format is limited to
+    png. All basic outputs of vnStat are supported excluding live traffic
+    features. The image can be outputted either to a file or to standard
+    output.
+endef
+
+define Package/vnstati/conffiles
+/etc/vnstat.conf
+endef
+
+define Build/Compile
+    $(MAKE) -C $(PKG_BUILD_DIR) \
+        $(TARGET_CONFIGURE_OPTS) \
+        CFLAGS+="-I$(STAGING_DIR)/usr/include -L$(STAGING_DIR)/usr/lib -Wl,-rpath-link,$(STAGING_DIR)/usr/lib"
+endef
+
+define Package/vnstati/install    
+    $(INSTALL_DIR) $(1)/usr/bin
+    $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/vnstati $(1)/usr/bin/
+    $(INSTALL_DIR) $(1)/etc
+    $(INSTALL_DATA) $(PKG_BUILD_DIR)/cfg/vnstat.conf $(1)/etc/
+    $(INSTALL_DIR) $(1)/www/cgi-bin/webif
+    $(INSTALL_BIN) ./files/graphs-vnstat.sh $(1)/www/cgi-bin/webif/
+endef
+
+define Package/vnstati/postrm
+#!/bin/sh
+VAR_D=$${IPKG_INSTROOT}/var/vnstat
+WWW_D=$${IPKG_INSTROOT}/www/vnstat
+
+rm -rf $$VAR_D
+rm -f $$WWW_D/vnstat_*.png
+endef
+
+$(eval $(call BuildPackage,vnstati))

I can't get it to compile

make[3]: Leaving directory `/home/mrplow/Desktop/openwrt/trunk/package/uci'
make[3]: Entering directory `/home/mrplow/Desktop/openwrt/trunk/package/vnstati'
Makefile:66: *** missing separator.  Stop.
make[3]: Leaving directory `/home/mrplow/Desktop/openwrt/trunk/package/vnstati'
make[2]: *** [package/vnstati/compile] Error 2
make[2]: Leaving directory `/home/mrplow/Desktop/openwrt/trunk'
make[1]: *** [/home/mrplow/Desktop/openwrt/trunk/staging_dir/mipsel/stamp/.package_compile] Error 2
make[1]: Leaving directory `/home/mrplow/Desktop/openwrt/trunk'
make: *** [world] Error 2
mrplow@mrplow-desktop:~/Desktop/openwrt/trunk$
mrplow wrote:

I can't get it to compile

Replace any leading spaces in the Makefile with tabs for the description, compile, and install sections.

damn tried that and still get the same error

dude, is there any ipkg file (.ipk) so i can install and see in the webif? coz as u explain people need to re-compile theirselfs and there are alot of stupid people in this world so they want something easier so if someone can compile the vnstati to .ipk would be eleet, or tell us how to add it into cgi-bin coz in this humdi website i dont read something like "openwrt" or something or any help how to include it into webif

First of all, i installed vnstat package from ipkg.be

http://ipkg.be/package/5036812

And, i made myself an graphs-vnstat.sh in the cgi-bin/webif dir

After that:

root@null:/www/cgi-bin/webif$ vnstat
Error:
Unable to open database directory "/var/lib/vnstat".
Make sure it exists and is read enabled for this user.
Exiting...

After that:

root@null:~/lib$ vnstat -u -i vlan1
Error:
Unable to read database "/var/lib/vnstat/vlan1".
New database generated.

And After that:

root@null:~/lib$ vnstat
 vlan1: Not enough data available yet.
root@null:~/lib$ ps x | grep vnstat
 2153 root        280 S   grep vnstat
root@null:~/lib$ vnstat -h
 vlan1: Not enough data available yet.
root@null:~/lib$ pwd
/var/lib

The database exists on:

root@null:~/lib/vnstat$ pwd
/var/lib/vnstat
root@null:~/lib/vnstat$ ls -l
-rw-r--r--    1 root     root         2784 Jun  1 13:07 vlan1
root@null:~/lib/vnstat$

But still it wont work..

vnstat relies upon a cronjob, such as the following part of https://dev.openwrt.org/ticket/3461, to update the database:

echo "0-55/5 *   * * *   root    if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi" >> /etc/crontabs/root

Cron also needs to be running:

/etc/init.d/cron start

If the Makefile works for anybody else, or someone points out the problem(s) with the Makefile, then maybe they can produce the vnstat (hopefully picking up the vnstat version bump and cronjob, if not the other pieces of https://dev.openwrt.org/ticket/3461) and vnstati packages for your kamikaze platform.

Copying the graphs-vnstat.sh is pointless without said vnstati package.

The discussion might have continued from here.