"""
<parameters>
<company>DSSL</company>
<title>Memlog</title>
<version>2.0</version>
<parameter>
<type>caption</type>
<name>Настройки</name>
</parameter>
<parameter>
<type>integer</type>
<name>Интервал сбора лога(мин)</name>
<id>DELAY</id>
<value>60</value>
<min>1</min>
<max>100000</max>
</parameter>
</parameters>
"""
import os
from subprocess import PIPE, Popen
from datetime import datetime
log_path = os.path.join(settings('system_wide_options')['screenshots_folder'], "memlog_v2.log")
def start():
proc = Popen(["top","-b","-n","1"], stdout=PIPE)
res = proc.stdout.read()
dt_str = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
with open(log_path, "a") as f:
f.write("\n" + "="*30 + dt_str + "="*30 + "\n")
f.write(res)
host.stats()["run_count"] += 1
timeout(1000 * 60 * DELAY, start)
start()