Fixed some issues, store dates in utc.
This commit is contained in:
@ -11,7 +11,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class Robor(BaseModel):
|
||||
date = DateField(index=True, default=datetime.date.today(), null=False)
|
||||
date = DateField(index=True, default=datetime.date.today, null=False)
|
||||
field = TextField(null=False)
|
||||
value = FloatField(null=False)
|
||||
|
||||
|
@ -10,7 +10,7 @@ import yfinance as yf
|
||||
|
||||
|
||||
class Stocks(BaseModel):
|
||||
date = DateTimeField(index=True, default=datetime.datetime.now(), null=False)
|
||||
date = DateTimeField(index=True, default=datetime.datetime.utcnow, null=False)
|
||||
ticker = TextField(null=False)
|
||||
label = TextField(null=False)
|
||||
value_open = FloatField(null=False)
|
||||
@ -29,6 +29,7 @@ class StocksPlugin(Plugin):
|
||||
for ticker, label in config.STOCKS_TICKERS.items():
|
||||
# Get last existing date
|
||||
latest_date = Stocks.select(Stocks.date) \
|
||||
.where(Stocks.ticker == ticker) \
|
||||
.order_by(Stocks.date.desc()) \
|
||||
.limit(1) \
|
||||
.scalar()
|
||||
@ -51,6 +52,6 @@ class StocksPlugin(Plugin):
|
||||
entry.value_high = row.High
|
||||
entry.value_low = row.Low
|
||||
entry.save()
|
||||
print(model_to_dict(entry))
|
||||
|
||||
except BaseException as e:
|
||||
print(e)
|
@ -10,7 +10,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class Cpu(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
cpu = SmallIntegerField(null=True)
|
||||
idle_pct = FloatField(null=False)
|
||||
user_pct = FloatField(null=False)
|
||||
|
@ -11,7 +11,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class DiskUsage(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
partition = TextField(null=False)
|
||||
mountpoint = TextField(null=False)
|
||||
total = BigIntegerField(null=False)
|
||||
@ -20,7 +20,7 @@ class DiskUsage(BaseModel):
|
||||
|
||||
|
||||
class DiskIO(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
disk = TextField(null=True)
|
||||
read_count = FloatField(null=False) # all values are per second
|
||||
write_count = FloatField(null=False)
|
||||
|
@ -9,7 +9,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class Memory(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
total = BigIntegerField(null=False)
|
||||
available = BigIntegerField(null=False)
|
||||
used = BigIntegerField(null=False)
|
||||
|
@ -11,7 +11,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class NetworkIO(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
nic = TextField(null=True)
|
||||
packets_sent = FloatField(null=False) # all values are per second
|
||||
packets_recv = FloatField(null=False)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import asyncio
|
||||
import subprocess
|
||||
import re
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
@ -13,7 +13,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class Ping(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
host = TextField(null=False)
|
||||
ping = FloatField(null=True) # null = timeout or error
|
||||
|
||||
@ -22,18 +22,15 @@ class PingPlugin(Plugin):
|
||||
models = [Ping]
|
||||
|
||||
def __init__(self):
|
||||
self.__timeout = config.PING_INTERVAL // 3
|
||||
self.__timeout = 20
|
||||
|
||||
def get_interval(self):
|
||||
return config.PING_INTERVAL
|
||||
|
||||
async def do_ping(self, host):
|
||||
def do_ping(self, host):
|
||||
command = ['ping', '-c', '1', '-W', str(self.__timeout), host]
|
||||
proc = await asyncio.create_subprocess_shell(' '.join(command),
|
||||
stdout=asyncio.subprocess.PIPE)
|
||||
|
||||
stdout,_ = await proc.communicate()
|
||||
stdout = stdout.decode()
|
||||
proc = subprocess.run(command, stdout=subprocess.PIPE)
|
||||
stdout = proc.stdout.decode()
|
||||
|
||||
entry = Ping()
|
||||
entry.host = host
|
||||
@ -45,16 +42,6 @@ class PingPlugin(Plugin):
|
||||
|
||||
entry.save()
|
||||
|
||||
async def execute_internal(self):
|
||||
await asyncio.gather(*[self.do_ping(host) for host in config.PING_HOSTS])
|
||||
|
||||
def execute(self):
|
||||
if getattr(asyncio, 'run', None) is not None:
|
||||
# Python 3.7+
|
||||
asyncio.run(self.execute_internal())
|
||||
else:
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(self.execute_internal())
|
||||
loop.close()
|
||||
|
||||
|
||||
for host in config.PING_HOSTS:
|
||||
self.do_ping(host)
|
||||
|
@ -11,7 +11,7 @@ from plugins.plugin import Plugin
|
||||
|
||||
|
||||
class Temperatures(BaseModel):
|
||||
time = DateTimeField(index=True, default=datetime.now)
|
||||
time = DateTimeField(index=True, default=datetime.utcnow)
|
||||
sensor = TextField(null=False)
|
||||
sensor_label = TextField(null=False)
|
||||
current = FloatField(null=False) # all values are per second
|
||||
|
Reference in New Issue
Block a user