from django.db import models

# Create your models here.

ProcessUsage_Type = (
        ('C','CPU'),
        ('M','Memory'),
)

# To-do 
# Server class should have the attribute about backup status
class Server(models.Model):
    name = models.CharField(unique=True, max_length=30)
    alias = models.CharField(max_length=255)
    ip = models.GenericIPAddressField()
    key = models.CharField(max_length=255)

class UsageLog(models.Model):
    server = models.ForeignKey('Server', db_index=True)
    datetime = models.DateTimeField() # 서버에서 저장시간 or client들이 정보 얻을때의 시간?
    
class CpuUsage(models.Model):
    usagelog = models.ForeignKey('UsageLog', db_index=True)
    user = models.Decimal(max_digits=20, decimal_place=3) # 100%는 어떻게함
    system = models.Decimal(max_digits=20, decimal_place=3)
    idle = models.Decimal(max_digits=20, decimal_place=3)

class MemoryUsage(models.Model):
    usagelog = models.ForeignKey('UsageLog', db_index=True)
    swap_total = models.IntegerField() # byte
    swap_used = models.IntegerField() # byte
    virt_avail = models.IntegerField() # byte
    virt_used = models.IntegerField() # byte

class DiskUsage(models.Model):
    usagelog = models.ForeignKey('UsageLog', db_index=True)
    device_name = models.CharField(max_length=30) # ex) dev/sda ...
    fs_type = models.CharField(max_length=10) # Filesystem type
    mount_point = models.CharField(max_length=30) # Disk mount path
    used = models.IntegerField() # byte
    total = models.IntegerField() # byte

class ProcessUsage(models.Model): 
    ProcessUsage_Type = (
        ('C','CPU'),
        ('M','Memory'),
    )

    usagelog = models.ForeignKey('UsageLog', db_index=True)
    name = models.CharField(max_length=127)
    order = models.IntegerField() #top 10 order
    cpu = models.DecimalField(max_digits=20, decimal_place=3)
    memory = models.DecimalField(max_digits=20, decimal_place=3)
    type = models.CharField(max_length=1, choices=ProcessUsage_Type)

class ErrorLog(models.Model):
    usagelog = models.ForeignKey('UsageLog', db_index=True)
    datetime = models.DateTimeField() # 서버저장시간 or client 정보 획슫 시간?
    log = models.TextField()


    

@@ -676,32 +676,37 @@
 = models.Decimal
+Field
 (max_digits=20, 
@@ -718,16 +718,17 @@
 al_place
+s
 =3) # 10
@@ -755,32 +755,37 @@
 = models.Decimal
+Field
 (max_digits=20, 
@@ -789,32 +789,33 @@
 0, decimal_place
+s
 =3)%0A    idle = m
@@ -827,16 +827,21 @@
 .Decimal
+Field
 (max_dig
@@ -857,24 +857,25 @@
 ecimal_place
+s
 =3)%0A%0Aclass M
@@ -976,32 +976,35 @@
 _total = models.
+Big
 IntegerField() #
@@ -1024,32 +1024,35 @@
 p_used = models.
+Big
 IntegerField() #
@@ -1073,32 +1073,35 @@
 _avail = models.
+Big
 IntegerField() #
@@ -1121,32 +1121,35 @@
 t_used = models.
+Big
 IntegerField() #
@@ -1150,24 +1150,70 @@
 ld() # byte%0A
+    virt_total = models.BigIntegerField()%0A    
 %0Aclass DiskU
@@ -1889,32 +1889,33 @@
 0, decimal_place
+s
 =3)%0A    memory =
@@ -1963,16 +1963,17 @@
 al_place
+s
 =3)%0A    
@@ -2228,11 +2228,4 @@
 d()%0A
-%0A%0A    %0A

fix wrong model fields