Fixes on mailman traffic monitor backend
This commit is contained in:
parent
66fa3bb4c6
commit
d601773bf3
|
@ -160,26 +160,25 @@ class MailmanTraffic(ServiceMonitor):
|
||||||
MAILMAN_LOG="$4"
|
MAILMAN_LOG="$4"
|
||||||
|
|
||||||
SUBSCRIBERS=$(list_members ${LIST_NAME} | wc -l)
|
SUBSCRIBERS=$(list_members ${LIST_NAME} | wc -l)
|
||||||
SIZE=$(grep ' post to ${LIST_NAME} ' "${MAILMAN_LOG}" \\
|
SIZE=$(grep " post to ${LIST_NAME} " "${MAILMAN_LOG}" \\
|
||||||
| awk '"$LAST_DATE"<=$0 && $0<="%s"' \\
|
| awk '"$LAST_DATE"<=$0 && $0<="%s"' \\
|
||||||
| sed 's/.*size=\([0-9]*\).*/\\1/' \\
|
| sed 's/.*size=\([0-9]*\).*/\\1/' \\
|
||||||
| tr '\\n' '+' \\
|
| tr '\\n' '+' \\
|
||||||
| xargs -i echo {} )
|
| xargs -i echo {}0 )
|
||||||
echo ${OBJECT_ID} $(( ${SIZE}*${SUBSCRIBERS} ))
|
echo ${OBJECT_ID} $(( ${SIZE}*${SUBSCRIBERS} ))
|
||||||
}""") % current_date)
|
}""") % current_date)
|
||||||
|
|
||||||
def monitor(self, mail_list):
|
def monitor(self, mail_list):
|
||||||
context = self.get_context(mail_list)
|
context = self.get_context(mail_list)
|
||||||
self.append(
|
self.append(
|
||||||
'monitor %(object_id)i %(last_date)s "%(list_name)s" "%(mailman_log)s{,.1}"' % context)
|
'monitor %(object_id)i "%(last_date)s" "%(list_name)s" %(mailman_log)s{,.1}' % context)
|
||||||
|
|
||||||
def get_context(self, mail_list):
|
def get_context(self, mail_list):
|
||||||
last_date = timezone.localtime(self.get_last_date(mail_list.pk))
|
|
||||||
return {
|
return {
|
||||||
'mailman_log': settings.LISTS_MAILMAN_POST_LOG_PATH,
|
'mailman_log': settings.LISTS_MAILMAN_POST_LOG_PATH,
|
||||||
'list_name': mail_list.name,
|
'list_name': mail_list.name,
|
||||||
'object_id': mail_list.pk,
|
'object_id': mail_list.pk,
|
||||||
'last_date': last_date.strftime("%b %d %H:%M:%S"),
|
'last_date': self.get_last_date(mail_list.pk).strftime("%b %d %H:%M:%S"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,12 @@ def pre_delete_collector(sender, *args, **kwargs):
|
||||||
|
|
||||||
@receiver(m2m_changed, dispatch_uid='orchestration.m2m_collector')
|
@receiver(m2m_changed, dispatch_uid='orchestration.m2m_collector')
|
||||||
def m2m_collector(sender, *args, **kwargs):
|
def m2m_collector(sender, *args, **kwargs):
|
||||||
# m2m relations without intermediary models are shit
|
# m2m relations without intermediary models are shit. Model.post_save is not sent and
|
||||||
# model.post_save is not sent and by the time related.post_save is sent
|
# by the time related.post_save is sent rel objects are not accessible via RelatedManager.all()
|
||||||
# the objects are not accessible with RelatedManager.all()
|
|
||||||
# We have to use this inefficient technique of collecting the instances via m2m_changed.post_add
|
# We have to use this inefficient technique of collecting the instances via m2m_changed.post_add
|
||||||
if kwargs.pop('action') == 'post_add':
|
if kwargs.pop('action') == 'post_add' and kwargs['pk_set']:
|
||||||
for pk in kwargs['pk_set']:
|
for instance in kwargs['model'].objects.filter(pk__in=kwargs['pk_set']):
|
||||||
kwargs['instance'] = kwargs['model'].objects.get(pk=pk)
|
kwargs['instance'] = instance
|
||||||
OperationsMiddleware.collect(Operation.SAVE, **kwargs)
|
OperationsMiddleware.collect(Operation.SAVE, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,8 @@ class BackendOperation(models.Model):
|
||||||
DELETE = 'delete'
|
DELETE = 'delete'
|
||||||
SAVE = 'save'
|
SAVE = 'save'
|
||||||
MONITOR = 'monitor'
|
MONITOR = 'monitor'
|
||||||
|
EXCEEDED = 'exceeded'
|
||||||
|
RECOVERY = 'recovery'
|
||||||
|
|
||||||
log = models.ForeignKey('orchestration.BackendLog', related_name='operations')
|
log = models.ForeignKey('orchestration.BackendLog', related_name='operations')
|
||||||
backend = models.CharField(_("backend"), max_length=256)
|
backend = models.CharField(_("backend"), max_length=256)
|
||||||
|
|
|
@ -41,10 +41,12 @@ def monitor(resource_id, ids=None, async=True):
|
||||||
data = ResourceData.get_or_create(obj, resource)
|
data = ResourceData.get_or_create(obj, resource)
|
||||||
data.update()
|
data.update()
|
||||||
if not resource.disable_trigger:
|
if not resource.disable_trigger:
|
||||||
if data.used > data.allocated:
|
a = data.used
|
||||||
op = Operation.create(backend, obj, Operation.EXCEED)
|
b = data.allocated
|
||||||
|
if data.used > (data.allocated or 0):
|
||||||
|
op = Operation.create(backend, obj, Operation.EXCEEDED)
|
||||||
triggers.append(op)
|
triggers.append(op)
|
||||||
elif data.used < data.allocated:
|
elif data.used < (data.allocated or 0):
|
||||||
op = Operation.create(backend, obj, Operation.RECOVERY)
|
op = Operation.create(backend, obj, Operation.RECOVERY)
|
||||||
triggers.append(op)
|
triggers.append(op)
|
||||||
Operation.execute(triggers)
|
Operation.execute(triggers)
|
||||||
|
|
|
@ -95,7 +95,7 @@ INSTALLED_APPS = (
|
||||||
'admin_tools',
|
'admin_tools',
|
||||||
'admin_tools.theming',
|
'admin_tools.theming',
|
||||||
'admin_tools.menu',
|
'admin_tools.menu',
|
||||||
# 'admin_tools.dashboard',
|
'admin_tools.dashboard',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
'passlib.ext.django',
|
'passlib.ext.django',
|
||||||
|
|
|
@ -164,3 +164,18 @@ def text2int(textnum, numwords={}):
|
||||||
|
|
||||||
return result + current
|
return result + current
|
||||||
|
|
||||||
|
|
||||||
|
UNITS_CONVERSIONS = {
|
||||||
|
1024**4: ['TB', 'TiB', 'TERABYTES'],
|
||||||
|
1024**3: ['GB', 'GiB', 'GYGABYTES'],
|
||||||
|
1024**2: ['MB', 'MiB', 'MEGABYTES'],
|
||||||
|
1024: ['KB', 'KiB', 'KYLOBYTES'],
|
||||||
|
1: ['B', 'BYTES'],
|
||||||
|
}
|
||||||
|
|
||||||
|
def unit_to_bytes(unit):
|
||||||
|
unit = unit.upper()
|
||||||
|
for bytes, units in UNITS_CONVERSIONS.iteritems():
|
||||||
|
if unit in units:
|
||||||
|
return bytes
|
||||||
|
raise KeyError("%s is not a valid unit." % unit)
|
||||||
|
|
Loading…
Reference in a new issue