bnhf/openvpn-admin-plus

Billing of incoming and outgoing traffic

Closed this issue · 5 comments

@bnhf

Scott, the incoming and outgoing traffic billing was violated in the 995f90c commit. Shows KB instead of MB. I guess it could have broken when you were fixing the correct display of RAM and swap file.

This commit broke traffic billing :( I'll think about what can be done.

Снимок экрана 2022-12-21 005705

@bnhf

I didn’t think of anything better than just declaring a new function))
I added to the funcmap.go file

beego.AddFuncMap("printmb_net", func(i interface{}) string {
    switch v := i.(type) {
    case uint64:
        return num2str(int64(i.(uint64)/1024/1024), '\u00A0')
    case int64:
        return num2str(i.(int64)/1024/1024, '\u00A0')
    default:
    beego.Error("Unknown type:", v)
    }
        return "Mapping error"
})

And then I changed the function in the index.html file

<span class="info-box-text">
    In: <span class="info-box-number2">{{ printmb_net .ovstats.BytesIn }} MB</span>
</span>
 <span class="info-box-text">
    Out: <span class="info-box-number2">{{ printmb_net .ovstats.BytesOut }} MB</span>
</span>

I'm certainly not a programmer, but the solution turned out to be working. Can I use my version to solve the problem, or will you, as a programmer, come up with a more beautiful solution? :))

I've already run it on my test car.

bnhf commented

@karabelnikov

I was thinking along the same lines of adding another function. We're getting this data from at least 3 sources now -- the gosigar library, the OpenVPN Management Interface and the /proc/meminfo file I'm using to fix the memory and swap problems with gosigar. Each has raw data that is presented differently, which is leading to this issue.

Let's use your approach for now, and I'll evaluate the other functions of printkb and printgb, to see which we need and which we don't, at some point in the future. It might make sense to use functions specifically written for each data source, like printGosigar, printOpenVPN and printMeminfo.

@bnhf

I also had an idea to use a function for each data type. This is rational. I will then send the edits of the method I proposed through PR to fix the problem.

@bnhf

Scott, I made new edits, I made the output of units of measurement as separate functions in the places where they are used.
printMemory, printNetServer and printNetClient

I tested it on my test stand, everything is fine. I think the task can be closed. I suggested edits via PR.