Commit 113c28e4 by Bach Dániel

monitor: add allocated_memory() task

parent c3c52c3c
......@@ -61,6 +61,12 @@ celery.conf.update(
'schedule': timedelta(seconds=30),
'options': {'queue': 'localhost.monitor'}
},
'monitor.allocated_memory': {
'task': 'monitor.tasks.local_periodic_tasks.'
'allocated_memory',
'schedule': timedelta(seconds=30),
'options': {'queue': 'localhost.monitor'}
},
}
)
......@@ -17,7 +17,6 @@
from logging import getLogger
from django.db.models import Sum
from django.utils.translation import ugettext_noop
from common.models import HumanReadableException
......@@ -95,8 +94,7 @@ def has_enough_ram(ram_size, node):
unused = total - used
overcommit = node.ram_size_with_overcommit
reserved = (node.instance_set.aggregate(
r=Sum('ram_size'))['r'] or 0) * 1024 * 1024
reserved = node.allocated_ram
free = overcommit - reserved
retval = ram_size < unused and ram_size < free
......
......@@ -107,3 +107,19 @@ def instance_per_template():
time()))
Client().send(metrics)
@celery.task(ignore_result=True)
def allocated_memory():
graphite_string = lambda hostname, val, time: (
"circle.%s.memory.allocated %d %s" % (
hostname, val, time)
)
metrics = []
for n in Node.objects.all():
print n.allocated_ram
metrics.append(graphite_string(
n.host.hostname, n.allocated_ram, time()))
Client().send(metrics)
......@@ -24,7 +24,7 @@ import requests
from django.conf import settings
from django.db.models import (
CharField, IntegerField, ForeignKey, BooleanField, ManyToManyField,
FloatField, permalink,
FloatField, permalink, Sum
)
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext_noop
......@@ -116,6 +116,11 @@ class Node(OperatedMixin, TimeStampedModel):
info = property(get_info)
@property
def allocated_ram(self):
return (self.instance_set.aggregate(
r=Sum('ram_size'))['r'] or 0) * 1024 * 1024
@property
def ram_size(self):
warn('Use Node.info["ram_size"]', DeprecationWarning)
return self.info['ram_size']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment