Commit 1d291528 authored by Rafael Monnerat's avatar Rafael Monnerat

[slapos.collect] Minor cleanups and cosmetic changes.

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