-
Notifications
You must be signed in to change notification settings - Fork 7
/
cluesreports
executable file
·62 lines (56 loc) · 2.69 KB
/
cluesreports
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#
# CLUES - Cluster Energy Saving System
# Copyright (C) 2018 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import json
import clueslib.reports
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser("Generate reports from CLUES database")
parser.add_argument("DATABASE", metavar="<database file>", default=None, help="the database file that has generated CLUES")
parser.add_argument("-f", "--from", dest="FROM", default=0, type=int, help="the starting timestamp for the stats (a negative value means that we want that delta time from the end of the stats; see --to argument)")
parser.add_argument("-t", "--to", dest="TO", default=0, help="the end timestamp for the stats (use the special value 'now' to get the curren time, or '0' to get the last timestamp in the stats, or a negative value to get a relative end from the maximum value in the stats)")
parser.add_argument("-j", "--prepare-reports", dest="PREPAREJS", action="store_true", default=False, help="prepare the output for the reports: set the javascript variables needed in the offline web page")
options = parser.parse_args()
if options.DATABASE is None:
print("you need to specify a database file (option -d)")
sys.exit(1)
import os.path
if not os.path.isfile(options.DATABASE):
print("cannot find file %s" % options.DATABASE)
sys.exit(1)
import time
if options.TO=='now':
options.TO=time.time()
else:
try:
options.TO=int(options.TO)
except:
parser.print_help()
sys.exit(1)
connection_string = "sqlite://%s" % options.DATABASE
hostdata, min_t, max_t = clueslib.reports.get_reports_data(connection_string, options.FROM, options.TO)
if hostdata is None:
raise Exception("failed to get data from the database")
else:
requests, _, _ = clueslib.reports.get_requests_data(connection_string, options.FROM, options.TO)
result = {"hostevents":hostdata,"requests":requests, "mintime_avail": min_t, "maxtime_avail": max_t}
if options.PREPAREJS:
print("var cluesdata=%s;" % json.dumps(result))
else:
# Dump in JSON format
print(json.dumps(result))