Commit bf1908bb authored by Lutra Conseil's avatar Lutra Conseil Committed by Rafael Monnerat

[slapos.collect] Minor cleanups and cosmetic changes.

parent 40b2cf24
......@@ -23,5 +23,4 @@ class CollectCommand(ConfigCommand):
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
# Make sure ipv4 is working
do_collect(configp)
......@@ -4,6 +4,10 @@ from slapos.collect.db import Database
from slapos.util import mkdir_p
# Local import
from snapshot import ProcessSnapshot, SystemSnapshot, ComputerSnapshot
from slapos.collect.reporter import SystemJSONReporterDumper, \
RawCSVDumper, \
SystemCSVReporterDumper
from entity import get_user_list, Computer
def _get_time():
......@@ -44,10 +48,9 @@ def do_collect(conf):
except (KeyboardInterrupt, SystemExit, NoSuchProcess):
raise
# XXX: we should use a value from the config file and not a hardcoded one
instance_root = conf.get("slapos", "instance_root")
mkdir_p("%s/var/data-log/" % instance_root)
database = Database("%s/var/data-log/" % instance_root)
log_directory = "%s/var/data-log" % conf.get("slapos", "instance_root")
mkdir_p(log_directory)
database = Database(log_directory)
computer = Computer(ComputerSnapshot())
computer.save(database, collected_date, collected_time)
......@@ -55,10 +58,8 @@ def do_collect(conf):
for user in user_dict.values():
user.save(database, collected_date, collected_time)
from slapos.collect.reporter import SystemJSONReporterDumper, RawCSVDumper, SystemCSVReporterDumper
#SystemJSONReporterDumper(database).dump()
SystemCSVReporterDumper(database).dump("%s/var/data-log/" % instance_root)
RawCSVDumper(database).dump("%s/var/data-log/" % instance_root)
SystemCSVReporterDumper(database).dump(log_directory)
RawCSVDumper(database).dump(log_directory)
except AccessDenied:
print "You HAVE TO execute this script with root permission."
......
......@@ -39,8 +39,6 @@ class Database:
"date, time) values " \
"('%s', %s, '%s', %s, %s, %s, %s, %s, %s, %s, '%s', '%s' )"
INSERT_COMPUTER_TEMPLATE = "insert into computer("\
" cpu_num_core, cpu_frequency, cpu_type," \
"memory_size, memory_type, partition_list," \
......
......@@ -44,7 +44,6 @@ class User(object):
database.commit()
database.close()
class Computer(dict):
def __init__(self, computer_snapshot):
......@@ -87,7 +86,6 @@ class Computer(dict):
insertion_date=collected_date,
insertion_time=collected_time)
def _save_disk_partition_snapshot(self, database, collected_date, collected_time):
for disk_partition in self.computer_snapshot.get("disk_snapshot_list"):
database.insertDiskPartitionSnapshot(
......
......@@ -25,7 +25,6 @@ class SystemReporter(Dumper):
partition_id = partition.split("-")[0].split("/")[-1]
item = "memory_%s" % partition.split("-")[1]
self.writeFile("disk_%s_%s" % (item, partition_id), folder, collected_item_list)
self.writeFile("disk_%s_%s" % (item, partition_id), folder, collected_item_list)
self.db.close()
......
......@@ -64,9 +64,6 @@ class FakeDatabase(object):
def insertDiskPartitionSnapshot(self, *args, **kw):
self.invoked_method_list.append(("insertDiskPartitionSnapshot", (args, kw)))
class TestCollectDatabase(unittest.TestCase):
def setUp(self):
......@@ -217,9 +214,6 @@ class TestCollectSnapshot(unittest.TestCase):
if os.path.exists(self.temp_dir):
shutil.rmtree(self.temp_dir)
def tearDown(self):
pass
def test_process_snapshot(self):
process = psutil.Process(os.getpid())
process_snapshot = snapshot.ProcessSnapshot(process)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment