Beispiel #1
0
def nagios(request):
    if not getattr(settings, 'REDIS_MONITOR_ONLY_TRACK_TOTALS', False):
        return HttpResponse(
            'nagios only available in REDIS_MONITOR_ONLY_TRACK_TOTALS mode'
        )
    requests = get_instance('requests').get_totals()
    sqlops = get_instance('sqlops').get_totals()
    return render('django_redis_monitor/nagios.xml', {
        'db_count': calculate_estimate(sqlops.get('hits', 0)),
        'db_total_ms': calculate_estimate(int(int(sqlops.get('weight', 0)) / 1000.0)),
        'request_count': calculate_estimate(requests.get('hits', 0)),
        'request_total_ms': calculate_estimate(int(int(requests.get('weight', 0)) / 1000.0)),
    })
 def get_recent_hits_and_weights(
         self, hours = 0, minutes = 0, seconds = 0
     ):
     start = self._calculate_start(hours, minutes, seconds)
     start = start.replace(
         second = (start.second / 10) * 10, microsecond = 0
     )
     preloaded_hashes = {}
     gathered = []
     current = start
     now = datetime.datetime.utcnow().replace(
         second = (start.second / 10) * 10, microsecond = 0
     )
     while current < now:
         hash, slot = self._hash_and_slot(current)
         if hash not in preloaded_hashes:
             preloaded_hashes[hash] = self.r.hgetall(hash)
         hits = calculate_estimate(int(preloaded_hashes[hash].get(slot, 0)))
         weight = calculate_estimate(int(preloaded_hashes[hash].get(slot + 'w', 0)))
         gathered.append((current, hits, weight))
         current += datetime.timedelta(seconds = 10)
     return gathered