Add disk usage statistics
- add model CustomerPackageDiskUsage for hosting package disk usage statistics - add REST API endpoint for submittings statistics for disk, mysql and pgsql usage - add disk usage information to hosting package detail view - add separate hosting package disk usage statistic view
This commit is contained in:
parent
affb49a971
commit
cb62bd63e2
10 changed files with 379 additions and 16 deletions
|
@ -269,6 +269,31 @@ class CustomerHostingPackage(HostingPackageBase):
|
|||
return DISK_SPACE_FACTORS[unit][min_unit] * diskspace
|
||||
return DISK_SPACE_FACTORS[min_unit][unit] * diskspace
|
||||
|
||||
disk_space = property(get_disk_space)
|
||||
|
||||
def get_used_disk_space_sum(self, unit=None):
|
||||
"""
|
||||
Get the used disk space of this hosting package from submitted disk space statistics.
|
||||
|
||||
:param unit: value from :py:data:`DISK_SPACE_UNITS` or :py:const:`None`
|
||||
:return: disk space in unit or bytes (if parameter unit is :py:const:`None`)
|
||||
:rtype: int
|
||||
|
||||
"""
|
||||
sum = 0
|
||||
for usage in self.customerpackagediskusage_set.all():
|
||||
sum += usage.size_in_bytes
|
||||
if unit is None:
|
||||
return sum
|
||||
return DISK_SPACE_FACTORS[0][unit] * sum
|
||||
|
||||
used_disk_space_sum = property(get_used_disk_space_sum)
|
||||
|
||||
def get_space_level(self):
|
||||
return self.used_disk_space_sum / self.disk_space * 100.0
|
||||
|
||||
space_level = property(get_space_level)
|
||||
|
||||
def get_package_space(self, unit=None):
|
||||
"""
|
||||
Get the total disk space reserved for this package without looking at
|
||||
|
@ -474,3 +499,34 @@ class CustomerMailboxOption(MailboxOptionBase, CustomerHostingPackageOption):
|
|||
help_text=_("The mailbox option template that this mailbox option is based on"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
|
||||
class CustomerPackageDiskUsage(TimeStampedModel):
|
||||
"""
|
||||
This class represents disk usage statistics for a customer hosting package.
|
||||
"""
|
||||
|
||||
package = models.ForeignKey(
|
||||
CustomerHostingPackage,
|
||||
verbose_name=_("hosting package"),
|
||||
help_text=_("The hosting package"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
source = models.CharField(
|
||||
verbose_name=_("data source"),
|
||||
choices=(("disk", _("disk")), ("mysql", _("mysql")), ("pgsql", _("pgsql"))),
|
||||
)
|
||||
item = models.CharField(verbose_name=_("data item"))
|
||||
used_kb = models.PositiveBigIntegerField(
|
||||
verbose_name=_("space used in KiB"), default=0
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("package", "source", "item")
|
||||
|
||||
def __str__(self):
|
||||
return "%s %s = %d KiB" % (self.source, self.item, self.used_kb)
|
||||
|
||||
@property
|
||||
def size_in_bytes(self):
|
||||
return self.used_kb * 1024
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue