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"
|
||||
|
||||
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"' \\
|
||||
| sed 's/.*size=\([0-9]*\).*/\\1/' \\
|
||||
| tr '\\n' '+' \\
|
||||
| xargs -i echo {} )
|
||||
| xargs -i echo {}0 )
|
||||
echo ${OBJECT_ID} $(( ${SIZE}*${SUBSCRIBERS} ))
|
||||
}""") % current_date)
|
||||
|
||||
def monitor(self, mail_list):
|
||||
context = self.get_context(mail_list)
|
||||
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):
|
||||
last_date = timezone.localtime(self.get_last_date(mail_list.pk))
|
||||
return {
|
||||
'mailman_log': settings.LISTS_MAILMAN_POST_LOG_PATH,
|
||||
'list_name': mail_list.name,
|
||||
'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')
|
||||
def m2m_collector(sender, *args, **kwargs):
|
||||
# m2m relations without intermediary models are shit
|
||||
# model.post_save is not sent and by the time related.post_save is sent
|
||||
# the objects are not accessible with RelatedManager.all()
|
||||
# m2m relations without intermediary models are shit. Model.post_save is not sent and
|
||||
# by the time related.post_save is sent rel objects are not accessible via RelatedManager.all()
|
||||
# We have to use this inefficient technique of collecting the instances via m2m_changed.post_add
|
||||
if kwargs.pop('action') == 'post_add':
|
||||
for pk in kwargs['pk_set']:
|
||||
kwargs['instance'] = kwargs['model'].objects.get(pk=pk)
|
||||
if kwargs.pop('action') == 'post_add' and kwargs['pk_set']:
|
||||
for instance in kwargs['model'].objects.filter(pk__in=kwargs['pk_set']):
|
||||
kwargs['instance'] = instance
|
||||
OperationsMiddleware.collect(Operation.SAVE, **kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -99,6 +99,8 @@ class BackendOperation(models.Model):
|
|||
DELETE = 'delete'
|
||||
SAVE = 'save'
|
||||
MONITOR = 'monitor'
|
||||
EXCEEDED = 'exceeded'
|
||||
RECOVERY = 'recovery'
|
||||
|
||||
log = models.ForeignKey('orchestration.BackendLog', related_name='operations')
|
||||
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.update()
|
||||
if not resource.disable_trigger:
|
||||
if data.used > data.allocated:
|
||||
op = Operation.create(backend, obj, Operation.EXCEED)
|
||||
a = data.used
|
||||
b = data.allocated
|
||||
if data.used > (data.allocated or 0):
|
||||
op = Operation.create(backend, obj, Operation.EXCEEDED)
|
||||
triggers.append(op)
|
||||
elif data.used < data.allocated:
|
||||
elif data.used < (data.allocated or 0):
|
||||
op = Operation.create(backend, obj, Operation.RECOVERY)
|
||||
triggers.append(op)
|
||||
Operation.execute(triggers)
|
||||
|
|
|
@ -95,7 +95,7 @@ INSTALLED_APPS = (
|
|||
'admin_tools',
|
||||
'admin_tools.theming',
|
||||
'admin_tools.menu',
|
||||
# 'admin_tools.dashboard',
|
||||
'admin_tools.dashboard',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'passlib.ext.django',
|
||||
|
|
|
@ -164,3 +164,18 @@ def text2int(textnum, numwords={}):
|
|||
|
||||
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 New Issue