Commit d5cb939a by Kálmán Viktor

monitor: instances per template

parent 392f026e
......@@ -79,7 +79,13 @@ celery.conf.update(
},
'monitor.check_celery_queues': {
'task': 'monitor.tasks.local_periodic_tasks.'
'check_celeries',
'check_celery_queues',
'schedule': timedelta(seconds=5),
'options': {'queue': 'localhost.man'}
},
'monitor.instance_per_template': {
'task': 'monitor.tasks.local_periodic_tasks.'
'instance_per_template',
'schedule': timedelta(seconds=5),
'options': {'queue': 'localhost.man'}
},
......
......@@ -23,7 +23,7 @@ from django.conf import settings
from manager.mancelery import celery
from vm.tasks.vm_tasks import check_queue
from vm.models import Node
from vm.models import Node, InstanceTemplate
from storage.models import DataStore
from monitor.client import Client
......@@ -68,3 +68,22 @@ def check_celery_queues():
"vm-" + s, is_queue_alive, time()))
Client().send(metrics)
@celery.task(ignore_result=True)
def instance_per_template():
graphite_string = lambda pk, state, val, time: (
"template.%d.instances.%s %d %s" % (
pk, state, val, time)
)
metrics = []
for t in InstanceTemplate.objects.all():
base = t.instance_set.filter(destroyed_at=None)
running = base.filter(status="RUNNING").count()
not_running = base.exclude(status="RUNNING").count()
metrics.append(graphite_string(t.pk, "running", running, time()))
metrics.append(graphite_string(t.pk, "not_running", not_running,
time()))
Client().send(metrics)
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