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()


    

from django.db import models

# Create your models here.


# 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()

class BackupTarget(models.Model):
    server = models.ForeignKey('Server',db_index=True)
    path = models.CharField(max_length=255)
    period = models.CharField(max_length=30)

class BackupLog(models.Model):
    server = models.ForeignKey('Server',db_index=True)
    log = models.TextField()
    datetime = models.DateTimeField()
    target = models.ForeignKey('BackupTarget',db_index=True)
    success = models.BooleanField()








Change model for attaching Backup to heartbeat