Example #1
0
def main():
    usage = "usage: %prog [options] <filename>"
    parser = optparse.OptionParser(usage)

    parser.add_option("-i",
                      "--indent",
                      type=int,
                      default=None,
                      help="Indent JSON")

    parser.add_option(
        "-d",
        "--daily",
        default=None,
        help="Daily units b (bytes),k (KiB),m (MiB),g (GiB) default is b")

    parser.add_option(
        "-m",
        "--monthly",
        default=None,
        help="Monthly units b (bytes),k (KiB),m (MiB),g (GiB) default is b")

    options, args = parser.parse_args()

    if len(args) == 1 and isfile(args[0]):
        history = RStatsHistory(args[0])
        output = RStatsOutput(history)
        output.to_json(options.daily, options.monthly, options.indent)
    else:
        print("Incorrect arguments")
        sys.exit(2)
Example #2
0
 def format_date(self, xtime):
     date = RStatsHistory.get_date(xtime)
     return date.strftime("%Y/%m/%d")
Example #3
0
 def counter(self, bandwidth, unit):
     return {
         "date" : self.format_date(bandwidth.date),
         "upload" : RStatsHistory.to_unit(bandwidth.up, unit),
         "download" : RStatsHistory.to_unit(bandwidth.down, unit)
     }
Example #4
0
 def format_date(self, xtime):
     date = RStatsHistory.get_date(xtime)
     return date.strftime("%Y/%m/%d")
Example #5
0
 def counter(self, bandwidth, unit):
     return {
         "date": self.format_date(bandwidth.date),
         "upload": RStatsHistory.to_unit(bandwidth.up, unit),
         "download": RStatsHistory.to_unit(bandwidth.down, unit)
     }