What's new

[Beta] VNSTAT on Merlin; CLI, UI and email data use monitoring (install script offline for now)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Status
Not open for further replies.
Perfect! Good job!

I'm struggling with attaching the png to email, or at least puting it in-line.
If using div-email.sh try changing
Code:
mailbody=$2
to
Code:
mailbody=$2
mailpng=$3                        # Martineau Hack

and replace
Code:
 echo " $(cat $mailbody)" >>/tmp/mail.txt
with
Code:
if [ -n "$mailpng" ] && [ -f "$mailpng" ];then            # Martineau Hack
    echo "MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"MULTIPART-MIXED-BOUNDARY\"

--MULTIPART-MIXED-BOUNDARY
Content-Type: multipart/alternative; boundary=\"MULTIPART-ALTERNATIVE-BOUNDARY\"

--MULTIPART-ALTERNATIVE-BOUNDARY
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline" >>/tmp/mail.txt
fi

cat $mailbody >>/tmp/mail.txt

if [ -n "$mailpng" ] && [ -f "$mailpng" ];then            # Martineau Hack
    # PNG
    echo "--MULTIPART-ALTERNATIVE-BOUNDARY--
--MULTIPART-MIXED-BOUNDARY
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$mailpng\"" >>/tmp/mail.txt

    # convert .png to base64 and append to the upload file
    cat $mailpng | openssl base64 >>/tmp/mail.txt        # Martineau Hack

    # end of uploaded file
    echo "--MULTIPART-MIXED-BOUNDARY--" >>/tmp/mail.txt    # Martineau Hack
fi

then you can optionally additionally specify which PNG you wish to attach

e.g.
Code:
/jffs/addons/vnstat.d/div-email.sh "Warning" /tmp/report.txt /tmp/var/wwwext/vnstat/vnstat.png
 
Last edited:
If you're referencing the "daily report" email, it's either sent as a text file attachment (if using the send-vnstat script) or embedded as text in the email (if using the div-email.sh script). Which command do you have loaded in cron for the daily report? Please post or PM the vnstat-related output of cru l (that's a lowercase L - el).
Hello! The daily report is being sent perfectly with the report attached as txt.
What I am saying is that I can't attach also the png image
 

Attachments

  • Screenshot_20210213-140810857_1.jpg
    Screenshot_20210213-140810857_1.jpg
    51.9 KB · Views: 106
If using div-email.sh try changing
Code:
mailbody=$2
to
Code:
mailbody=$2
mailpng=$3                        # Martineau Hack

and replace
Code:
 echo " $(cat $mailbody)" >>/tmp/mail.txt
with
Code:
if [ -n "$mailpng" ] && [ -f "$mailpng" ];then            # Martineau Hack
    echo "MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"MULTIPART-MIXED-BOUNDARY\"

--MULTIPART-MIXED-BOUNDARY
Content-Type: multipart/alternative; boundary=\"MULTIPART-ALTERNATIVE-BOUNDARY\"

--MULTIPART-ALTERNATIVE-BOUNDARY
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline" >>/tmp/mail.txt
fi

cat $mailbody >>/tmp/mail.txt
 
if [ -n "$mailpng" ] && [ -f "$mailpng" ];then            # Martineau Hack
    # PNG
    echo "--MULTIPART-ALTERNATIVE-BOUNDARY--
--MULTIPART-MIXED-BOUNDARY
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$mailpng\"" >>/tmp/mail.txt

    # convert file.zip to base64 and append to the upload file
    cat $mailpng | openssl base64 >>/tmp/mail.txt        # Martineau Hack

    # end of uploaded file
    echo "--MULTIPART-MIXED-BOUNDARY--" >>/tmp/mail.txt    # Martineau Hack
fi

then you can optionally additionally specify which PNG you wish to attach

e.g.
Code:
/jffs/addons/vnstat.d/div-email.sh "Warning" /tmp/report.txt /tmp/var/wwwext/vnstat/vnstat.png
Thanks!
And what if using send-vnstat.sh?
 
Hello! The daily report is being sent perfectly with the report attached as txt.
What I am saying is that I can't attach also the png image
send-vnstat was not developed to attach images. Feel free to extend the script to include it, and put the information back out for others to use!

(Makemime can probably be used for this purpose, but would require you to determine the specific commands.)
 
Having issues with latest Martineau install script v1.07b3.- not able to load images in GUI TAB. Tried running Vnstat-ww.sh and refreshing page - no go.
This is on an RT-AC86U. The following messages at end of install script. I am using PPPoE as WAN Connection type.

Code:
convert: UnableToOpenBlob '/tmp/var/wwwext/vnstat/vnstat.png': No such file or directory @ error/blob.c/OpenBlob/3496.
convert: WriteBlob Failed `/tmp/var/wwwext/vnstat/vnstat.png' @ error/png.c/MagickPNGErrorHandler/1715.
vnstat_totals: summary generated
vnstats: vnstati updating stats for UI

The files in tmp/var/wwwext/vnstat/ are
Code:
vnstat_ppp0_d.png
vnstat_ppp0_h.png
vnstat_ppp0_hs.png
vnstat_ppp0_m.png
vnstat_ppp0_s.png
vnstat_ppp0_t.png

Code:
nvram get wan0_ifname
eth0

I had to use
Code:
/jffs/scripts/vnstat-install.sh install eth0
to get the GUI Tab to work. All graphs now show eth0 as interface.
 
Last edited:
Having issues with latest Martineau install script v1.07b3.- not able to load images in GUI TAB. Tried running Vnstat-ww.sh and refreshing page - no go.
This is on an RT-AC86U. The following messages at end of install script. I am using PPPoE as WAN Connection type.

Code:
convert: UnableToOpenBlob '/tmp/var/wwwext/vnstat/vnstat.png': No such file or directory @ error/blob.c/OpenBlob/3496.
convert: WriteBlob Failed `/tmp/var/wwwext/vnstat/vnstat.png' @ error/png.c/MagickPNGErrorHandler/1715.
vnstat_totals: summary generated
vnstats: vnstati updating stats for UI

The files in tmp/var/wwwext/vnstat/ are
Code:
vnstat_ppp0_d.png
vnstat_ppp0_h.png
vnstat_ppp0_hs.png
vnstat_ppp0_m.png
vnstat_ppp0_s.png
vnstat_ppp0_t.png

Code:
nvram get wan0_ifname
eth0

I had to use
Code:
/jffs/scripts/vnstat-install.sh install eth0
to get the GUI Tab to work. All graphs now show eth0 as interface.
Yes already reported

However, if you immediately re-run vnstat-stats the error apparently goes away.

vnstat-install.sh v1.07b3 attempted to rectify the broken links during the creation of the Addon GUI Tab during the boot process, but even with an enforced 60 sec delay before calling vnstat-stats (hoping it was merely a timing issue)

/jffs//post-mount
Code:
(sh /jffs/addons/vnstat.d/vnstat-ui && sleep 60 && /opt/bin/vnstat -u && sh /jffs/addons/vnstat.d/vnstat-stats && sh /jffs/addons/vnstat.d/vnstat-ww.sh) & # 'vnstat-ui generate' Hack
unfortunately running in debug mode shows that vnstat-stats frustratingly silently fails during the boot process:

1613301031021.png
 
Last edited:
send-vnstat was not developed to attach images. Feel free to extend the script to include it, and put the information back out for others to use!

(Makemime can probably be used for this purpose, but would require you to determine the specific commands.)
Simply add the '.png' to the list of files to be processed by the makemime command?

e.g. for convenience

Change
Code:
makemime -a"Subject: $FRIENDLY_ROUTER_NAME vnstat Stats at $(date +"%H.%M on %F")" -a"From: $FROM" -o /home/root/output.msg /home/root/vnstat.txt
to
Code:
if [ -n "$1" ] && [ -f "$1" ];then            # Martineau Hack
    mailpng=$1                                # Martineau Hack
fi

makemime -a"Subject: $FRIENDLY_ROUTER_NAME vnstat Stats at $(date +"%H.%M on %F")" -a"From: $FROM" -o /home/root/output.msg /home/root/vnstat.txt $mailpng
then supply the additional .png to the e-mail request

e.g. hour report
Code:
/opt/bin/vnstat -u && sh /jffs/addons/vnstat.d/vnstat-stats && sh /jffs/addons/vnstat.d/send-vnstat /tmp/var/wwwext/vnstat/vnstat_eth0_h.png
 
I'm working on it (with Jack Yaz and with input from Martineau). I need to test updated UI script this weekend.
Sigh. I disconnected my AC66_B1 from the mesh to try out the new script only to find that both USB ports have crapped out, so I have no way to install Diversion and connmon to test the script changes. I'm off to fleabay to secure a test router to replace it. Fortunately it still functions as a node... no idea what happened in the last month. Tried reflashing with 384.19, 386.1 and 386.1_2, with no luck.

I've put the modified script in the development branch (https://github.com/de-vnull/vnstat-on-merlin/blob/development/scripts/vnstat-ui)... @Martineau, is it possible to modify the script to allow for access to the development branch (for example passing along a variable when calling the install script)?
 
Last edited:
Having issues with latest Martineau install script v1.07b3.- not able to load images in GUI TAB. Tried running Vnstat-ww.sh and refreshing page - no go.
This is on an RT-AC86U. The following messages at end of install script. I am using PPPoE as WAN Connection type.

The files in tmp/var/wwwext/vnstat/ are
Code:
vnstat_ppp0_d.png
vnstat_ppp0_h.png
vnstat_ppp0_hs.png
vnstat_ppp0_m.png
vnstat_ppp0_s.png
vnstat_ppp0_t.png

Code:
nvram get wan0_ifname
eth0

I had to use
Code:
/jffs/scripts/vnstat-install.sh install eth0
to get the GUI Tab to work. All graphs now show eth0 as interface.
Part of this is because the UI expects to have "eth0" in the png name... it's an artifact of the nature of the original design (my interface was eth0).

I'll have to give some thought to how to address this. Options include forcing the name of the pngs regardless of the interface, through to updating the UI page with the name of the interface/expected png naming.
 
I've put the modified script in the development branch (https://github.com/de-vnull/vnstat-on-merlin/blob/development/scripts/vnstat-ui)... @Martineau, is it possible to modify the script to allow for access to the development branch (for example passing along a variable when calling the install script)?
Probably, but for a quick hack I have submitted a pull request to modify

vnstat-ui

Code:
    update)                                                                # { update [dev[velopment]] }
    
        [ "${2:0:3}" == "dev" ] && BRANCH="development" || BRANCH="main"
        
        Print_Output true "Updating $SCRIPT_NAME from Github $BRANCH branch"
        
        curl -# -L https://raw.githubusercontent.com/de-vnull/vnstat-on-merlin/${BRANCH}/scripts/$SCRIPT_NAME -o $SCRIPT_DIR/$SCRIPT_NAME  && chmod 755 $SCRIPT_DIR/$SCRIPT_NAME && dos2unix $SCRIPT_DIR/$SCRIPT_NAME
    
    ;;
 
Part of this is because the UI expects to have "eth0" in the png name... it's an artifact of the nature of the original design (my interface was eth0).

I'll have to give some thought to how to address this. Options include forcing the name of the pngs regardless of the interface, through to updating the UI page with the name of the interface/expected png naming.
Hotfix: For now I've updated vnstat-ww.sh so that the png naming matches the UI html.

If you are using an interface other than eth0 and are having issues with the images on the UI, you can either re-install or if you want to make a more targeted fix, download the updated vnstat-ww.sh from here. Save it to the /jffs/scripts folder on your device, make sure it's executable, and run /opt/bin/vnstat -u && sh -x /jffs/scripts/vnstat-ww.sh from the CLI

(You should see the output /opt/bin/vnstati -s -i YOUR_INTERFACE -o /www/user/vnstat/vnstat_eth0_s.png... m.png, etc.)

A future update will better harmonize the naming and the UI.

EDIT: The above is deprecated with @Martineau's updated script. The vnstat-ww.sh has been re-reverted to use the interface name in the png. Advise if you have any problems with script 1.08b.
 
Last edited:
I've pushed vnstat-install v1.08b to modify the GUI .asp file to refer to the WAN interface .png files if not using the default 'eth0'
OK, but this now deprecates the hotfix with the naming convention over-ride.

EDIT: reverted png naming covention to reflect user-specified interface.

I've not had a chance to test this new script since my test bed is dead.

@Martineau, can we coordinate a little better since I'm trying to fix things while staying compliant with your install script. I'm on EST (EDT) so am available later afternoon/evenings EST (EDT) most days. I do appreciate the collaboration, I just don't want to break things we're both working on.
 
Last edited:
OK, but this now deprecates the hotfix with the naming convention over-ride.

EDIT: reverted png naming covention to reflect user-specified interface.

I've not had a chance to test this new script since my test bed is dead.

@Martineau, can we coordinate a little better since I'm trying to fix things while staying compliant with your install script. I'm on EST (EDT) so am available later afternoon/evenings EST (EDT) most days. I do appreciate the collaboration, I just don't want to break things we're both working on.
You're absolutely right, its your project.

Script deleted.
 
You're absolutely right, its your project.

Script deleted.
@Martineau as I said, I (and the broader user community) here completely appreciate the creation of the scripts for this project.

Please don't delete the script - I am just asking that we communicate the changes so that we stay aligned on what each other is doing. That way I can roll-back anything that I've done to work-around issues.

If v1.08b updates the png names in the UI page, that would match my roll-back of the vnstat-www.sh png naming, so that would be most helpful to keep active. I speak for the myself and community when I ask that you keep that critical update available for our community.
 
I suspect it is time to put this on pause until the SME again has a test bed.
 
I suspect it is time to put this on pause until the SME again has a test bed.
Actually, I think I am fully capable of identifying, understanding and fully testing this simple apt - yet apparently contentious - one-line patch to my script.

i.e.
Changed v1.07b?
Code:
$INSTALL_DIR/vnstat-ui
to insert the one-line patch
Code:
sed -i "s~/vnstat_.*_~/vnstat_${WAN_IF}_~g" /jffs/addons/vnstat-ui.d/vnstat-ui.asp    # v1.08
$INSTALL_DIR/vnstat-ui
 
Last edited:
Actually, I think I am fully capable of identifying, understanding and fully testing this simple apt - yet apparently contentious - one-line patch to my script.
That one line script gives me a rare chance to agree by describing you as "sedulous". :D

But I missed my chance to try 1.08b.
 
My goodness, the language.
I will agree, though.
 
This project is excellent - thank you to dev_null and Martineau for providing yet another brilliant addition to our routers.
It is very very close to my daily usage as reported by my ISP. Exetel - a few hunded MB.

Whereas on the AC86U Traffic Analyser Statistics daily shows underreporting by at least 1.5GB/day ( as compared with ISP- Exetel) and Traffic Monitor daily shows at least double the actual usage by ISP for the same day. So totally inaccurate both ways.

Now I have usage one can rely on 100%.
Thanks again guys.

PS - 2nd site AX86U -ISP Spintel - Traffic Analyser Statistics daily show grossly underreported usage -: eg 64MB when ISP total is 2.13GB . Traffic Monitor daily shows three to four times the actual ISP reported usage for the same day -eg 7.35GB compared with ISP 2.13GB.

VNSTAT is within +0.6GB.
 
Last edited:
Wanted to give this a try and install. What am I doing wrong?

jadmin@RT-AC86U-07F8:/tmp/home/root# curl --retry 3 "https://raw.githubusercontent.com/MartineauUK/vnstat/main/vnstat-install.sh" -o "/jffs/scripts/vnstat-install.sh" && chmod
755 "/jffs/scripts/vnstat-install.sh" && /jffs/scripts/vnstat-install.sh install
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14 100 14 0 0 93 0 --:--:-- --:--:-- --:--:-- 105
/jffs/scripts/vnstat-install.sh: line 1: 404:: not found
jadmin@RT-AC86U-07F8:/tmp/home/root#
 
Status
Not open for further replies.

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top