Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1020791 // Monthly Traffic Estimate Percentage [of traffic limit]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (23154L/146K).

1  
!7
2  
3  
// works with certain versions of vnstat. Try apt-get install vnstat
4  
5  
module EstimatedMonthlyTrafficPercentage > DynBigNumber {
6  
  start {
7  
    doEvery(0.0, 10*60.0, r updateStats);
8  
  }
9  
  
10  
  void updateStats enter {
11  
    if (getMonthlyTrafficLimit() == 0)
12  
      setValue("Please set traffic limit");
13  
    else if (!isOnPATH('vnstat))
14  
      setValue("vnstat not installed");
15  
    else {
16  
      S s = regexpReplaceWithNothing(",\\d+", parse_vnstat(backtick('vnstat)).thisMonthEstimated);
17  
      long mb;
18  
      if (s.endsWith("MiB")) mb = parseFirstLong(s);
19  
      else if (s.endsWith("GiB")) mb = parseFirstLong(s)*1024;
20  
      else ret with setValue("(?) " + s);
21  
      setValue(intPercentRatio(mb, getMonthlyTrafficLimit()*1024) + " %");
22  
    }
23  
  }
24  
25  
  afterVisualize {
26  
    componentPopupMenuItem(label, "Set traffic limit...", r setLimit);
27  
    onLeftClick(label, r setLimit);
28  
  }
29  
  
30  
  enhanceFrame {
31  
    internalFramePopupMenuItem(f, "Set traffic limit...", r setLimit);
32  
  }
33  
  
34  
  void setLimit enter {
35  
    inputText("Monthly traffic limit (GB, 0 for unknown)", str(getMonthlyTrafficLimit()), voidfunc(S s) {
36  
      setMonthlyTrafficLimit(parseLong(s));
37  
      updateStats();
38  
    });
39  
  }
40  
}

Author comment

Began life as a copy of #1020626

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020791
Snippet name: Monthly Traffic Estimate Percentage [of traffic limit]
Eternal ID of this version: #1020791/7
Text MD5: 33d03afc754b9aafd09ccfe879a516ce
Transpilation MD5: 27679685666061b980ef0a06c480359d
Author: stefan
Category: javax / networking
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-02 21:23:29
Source code size: 1218 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 278 / 169519
Version history: 6 change(s)
Referenced in: [show references]