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

Question about Time Stamp and Dashboard suggestion #4

Open
allencar99 opened this issue May 24, 2021 · 7 comments
Open

Question about Time Stamp and Dashboard suggestion #4

allencar99 opened this issue May 24, 2021 · 7 comments

Comments

@allencar99
Copy link

Hi

Your opnsense-speedtest is perfect for what I need as we are having irregular speed fluctuations from our ISP and this will help me to provide conclusive evidence (in conjunction with a script to isolate the LAN ports and kick of the speed test) that it is them and not our network - Thank you :)

I do have a question however regarding the time stamp on the log. Is it possible to have the timestamp display in the local TZ? As in, the log timestamp is not GMT but follows the Time Zone setting of OPNsense.

Also, having a graphic display of say the last 20 log entries available on the dashboard would be a fun feature. It would only need to show the download speeds but having both in different colours would be a bonus :)

Do you have a buy me a coffee donate button or similar?

Regards

Allen

@mihakralj
Copy link
Owner

Timestamp change is easy to implement and I can do this change by the end of the week;
Adding an optional tail of recent x entries into a widget is also a straight-forward path, will try to roll it into the change.

But the graphics request is not that trivial - the current charting library in OPNsense is... Limited. And ancient. And I have very low desire to wrangle with it, yet I can't just slap a new modern charting library (like plotly.com) into OPNsense to support one single chart... Let me think about this one.

BTW, in case you didn't know, this plugin is now part of the repo that is maintained by Mimugmail; it includes whole bunch of community efforts, including speedtest: https://github.com/mimugmail/opn-repo

@mihakralj
Copy link
Owner

mihakralj commented May 30, 2021

Let me know if you are comfortable with the following change:
line 75 of /usr/local/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py should read like:
row[0]=datetime.fromtimestamp(float(row[0])).replace(tzinfo=timezone.utc).astimezone(tz=None).strftime('%Y-%m-%dT%H:%M:%S')

this will show the time in a short (24-hr) format but in the local timezone instead of GMT.

@mihakralj
Copy link
Owner

And here is the new version of the widget that displays 5 recent entries from the log; replace the content of /usr/local/www/widgets/widgets/speedtest.widget.php with the following:

<?php
require_once("guiconfig.inc");
?>
<script>
    $(document).ready(function() {
        ajaxGet("/api/speedtest/service/showstat", {}, function(l,status) {
            $('#stat_latency').html("<b>"+l.latency.avg+" ms<\/b><small> (min: "+l.latency.min+" ms, max: "+l.latency.max +" ms)</small>")
            $('#stat_download').html("<b>"+l.download.avg+" Mbps<\/b><small> (min: "+l.download.min+" Mbps, max: "+l.download.max +" Mbps)</small>")
            $('#stat_upload').html("<b>"+l.upload.avg+" Mbps<\/b><small> (min: "+l.upload.min+" Mbps, max: "+l.upload.max +" Mbps)</small>")
        });

        ajaxGet("/api/speedtest/service/showlog", {}, function(l,status) {
            for (var i = 0; i < 6; i++) {
                var obj = obj +
                    "<tr><td class=\"text-left\" style=\"\">" + l[i][0] + "</td>" +
                    "<td class=\"text-left\" style=\"\">" + parseFloat(l[i][5]).toFixed(2) + "</td>" +
                    "<td class=\"text-left\" style=\"\">" + parseFloat(l[i][6]).toFixed(2) + "</td>" +
                    "<td class=\"text-left\" style=\"\">" + parseFloat(l[i][7]).toFixed(2) + "</td></tr>"
            }
            $('#log_block').html(obj);
        });
    });
</script>
<!-- gateway table -->
<table id="speedtest_widget_table" class="table table-striped table-condensed">
  <tr><td style="width:25%">Avg Download:</td><td><div id="stat_download">0 Mbps (min: 0 Mbps, max: 0 Mbps)</div></td></tr>
  <tr><td>Avg Upload:</td><td><div id="stat_upload">0 Mbps (min: 0 Mbps, max: 0 Mbps)</div></td></tr>
  <tr><td>Avg Latency:</td><td><div id="stat_latency">0.00 ms (min: 0.00 ms, max: 0.00 ms)</div></td></tr>
</table>
<table>
<thead>
<tr id="log_head" data-advanced="true" ">
    <th data-column-id="Timestamp" class="text-left" style="width:7em;">Timestamp (GMT)</th>
    <th data-column-id="Latency" class="text-left" style="width:2em;">Download</th>
    <th data-column-id="DlSpeed" class="text-left" style="width:3em;">Upload</th>
    <th data-column-id="UlSpeed" class="text-left" style="width:3em;">Latency</th>
</tr>
</thead>
<tbody id="log_block" data-advanced="true" ">
</table>

You want 20 lines? Change the iterator in the line for (var i = 0; i < 6; i++) { from 6 to 21

@mihakralj
Copy link
Owner

How the new widget looks like:
image

@firestormo
Copy link

could we get these changes for date/time and the updated widget in the code.. i cant seem to get either change working when editing the files myself on opnsense 21.1.8_1 (also in the opnsense-repo) thx

@allencar99
Copy link
Author

Let me know if you are comfortable with the following change:
line 75 of /usr/local/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py should read like:
row[0]=datetime.fromtimestamp(float(row[0])).replace(tzinfo=timezone.utc).astimezone(tz=None).strftime('%Y-%m-%dT%H:%M:%S')

this will show the time in a short (24-hr) format but in the local timezone instead of GMT.

Hi Miha

I replaced the line 75 with your provided code but it stops the log from showing so I am assuming it can not parse the file with this code (maybe the date/time format?). So I decided just to update the widget and that worked seamlessly - thanks for that :)
Anyway our ISP must have found an issue at their end and our speeds are not fluctuating as much now as before but I still see peak time lag so I am still keen to see the times in the local time zone to make it easier to identify issues on the fly. So would it be possible for you to give me some pointers to trouble shoot this issue? I am thinking maybe I need to install some datetime dependencies? I will also reverse the date to dd/mm/yyyy too :D

I have updated the system to the latest version as per:
Type : opnsense-devel
Version : 21.7.r_61
Architecture : amd64
Flavour : OpenSSL 
Commit : 4ae1555e0
Mirror : https://mirror-opnsense.serverbase.ch/FreeBSD:12:amd64/21.7
Repositories : OPNsense, mimugmail
Updated on : Fri Jul 30 13:12:12 AEST 2021
Checked on : Fri Jul 30 15:18:20 AEST 2021

Kind regards
Allen Carr

@allencar99
Copy link
Author

Let me know if you are comfortable with the following change:
line 75 of /usr/local/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py should read like:
row[0]=datetime.fromtimestamp(float(row[0])).replace(tzinfo=timezone.utc).astimezone(tz=None).strftime('%Y-%m-%dT%H:%M:%S')

this will show the time in a short (24-hr) format but in the local timezone instead of GMT.

Hi Miha

Fixed it!

Need to amend line 35:
from datetime import datetime
to:
from datetime import datetime, timezone

That was all! :)

Now I need to work out where to change the (GMT) label?

Regards
Allen

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