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).

!7

// works with certain versions of vnstat. Try apt-get install vnstat

module EstimatedMonthlyTrafficPercentage > DynBigNumber {
  start {
    doEvery(0.0, 10*60.0, r updateStats);
  }
  
  void updateStats enter {
    if (getMonthlyTrafficLimit() == 0)
      setValue("Please set traffic limit");
    else if (!isOnPATH('vnstat))
      setValue("vnstat not installed");
    else {
      S s = regexpReplaceWithNothing(",\\d+", parse_vnstat(backtick('vnstat)).thisMonthEstimated);
      long mb;
      if (s.endsWith("MiB")) mb = parseFirstLong(s);
      else if (s.endsWith("GiB")) mb = parseFirstLong(s)*1024;
      else ret with setValue("(?) " + s);
      setValue(intPercentRatio(mb, getMonthlyTrafficLimit()*1024) + " %");
    }
  }

  afterVisualize {
    componentPopupMenuItem(label, "Set traffic limit...", r setLimit);
    onLeftClick(label, r setLimit);
  }
  
  enhanceFrame {
    internalFramePopupMenuItem(f, "Set traffic limit...", r setLimit);
  }
  
  void setLimit enter {
    inputText("Monthly traffic limit (GB, 0 for unknown)", str(getMonthlyTrafficLimit()), voidfunc(S s) {
      setMonthlyTrafficLimit(parseLong(s));
      updateStats();
    });
  }
}

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: 204 / 134278
Version history: 6 change(s)
Referenced in: [show references]