def pools_usage(self, last_ts):
     """
     This info is not from proc atm, but will eventually be.
     """
     #  collect usage only if the data is more than 30 seconds old
     now = time.mktime(time.gmtime())
     if (now - last_ts < 30):
         return last_ts
     ts = datetime.utcnow().replace(tzinfo=utc)
     for p in Pool.objects.all():
         arb_disk = Disk.objects.filter(pool=p)[0].name
         try:
             usage = pool_usage(arb_disk)
             pu = None
             try:
                 pu = PoolUsage.objects.filter(pool=p.name).latest('id')
                 if ((ts - pu.ts).total_seconds() > 90):
                     pu = None
             except Exception, e:
                 e_msg = ('Unable to get latest pool usage object for '
                          'pool(%s). A new one will be created.' % p.name)
                 logger.error(e_msg)
             if (pu is None or pu.usage != usage[1]):
                 pu = PoolUsage(pool=p.name, usage=usage[1], ts=ts)
             else:
                 pu.ts = ts
                 pu.count = pu.count + 1
             self._save_wrapper(pu)
         except Exception, e:
             logger.debug('command exception while getting pool usage '
                          'for: %s' % (p.name))
             logger.exception(e)
Пример #2
0
 def pools_usage(self, last_ts):
     """
     This info is not from proc atm, but will eventually be.
     """
     #collect usage only if the data is more than 30 seconds old
     now = time.mktime(time.gmtime())
     if (now - last_ts < 30):
         return last_ts
     ts = datetime.utcnow().replace(tzinfo=utc)
     for p in Pool.objects.all():
         arb_disk = Disk.objects.filter(pool=p)[0].name
         try:
             usage = pool_usage(arb_disk)
             pu = None
             try:
                 pu = PoolUsage.objects.filter(pool=p.name).latest('id')
                 if ((ts - pu.ts).total_seconds() > 90):
                     pu = None
             except Exception, e:
                 e_msg = ('Unable to get latest pool usage object for '
                          'pool(%s). A new one will be created.' % p.name)
                 logger.error(e_msg)
             if (pu is None or pu.usage != usage[1]):
                 pu = PoolUsage(pool=p.name, usage=usage[1], ts=ts)
             else:
                 pu.ts = ts
                 pu.count = pu.count + 1
             self._save_wrapper(pu)
         except Exception, e:
             logger.debug('command exception while getting pool usage '
                          'for: %s' % (p.name))
             logger.exception(e)
Пример #3
0
 def pools_usage(self, last_ts):
     """
     This info is not from proc atm, but will eventually be.
     """
     #  collect usage only if the data is more than 30 seconds old
     now = time.mktime(time.gmtime())
     if (now - last_ts < 30):
         return last_ts
     ts = datetime.utcnow().replace(tzinfo=utc)
     for p in Pool.objects.all():
         total_reclaimable = 0
         try:
             #  get usage of all shares in this pool
             pool_device = Disk.objects.filter(pool=p)[0].name
             share_map = {}
             snap_map = {}
             for share in Share.objects.filter(pool=p):
                 share_map[share.qgroup] = share.name
                 for snap in Snapshot.objects.filter(share=share):
                     snap_map[snap.qgroup] = snap.real_name
             usaged = shares_usage(p, pool_device, share_map, snap_map)
             for s in usaged.keys():
                 try:
                     total_reclaimable += (
                         Share.objects.get(name=s).size - usaged[s][1])
                 except:
                     pass
                 su = None
                 try:
                     su = ShareUsage.objects.filter(name=s).latest('id')
                     if ((ts - su.ts).total_seconds() > 90):
                         su = None
                 except Exception, e:
                     e_msg = ('Unable to get latest share usage object '
                              'for share(%s). A new one will be created.'
                              % s)
                     logger.error(e_msg)
                 #  we check for changed in both referenced and exclusive
                 #  usage because in rare cases it's possible for only one
                 #  to change.
                 if ((su is None or su.r_usage != usaged[s][0] or
                      su.e_usage != usaged[s][1])):
                     su = ShareUsage(name=s, r_usage=usaged[s][0],
                                     e_usage=usaged[s][1], ts=ts)
                 else:
                     su.ts = ts
                     su.count = su.count + 1
                 self._save_wrapper(su)
         except Exception, e:
             logger.debug('command exception while getting shares usage '
                          'for pool: %s' % (p.name))
             logger.exception(e)
         try:
             usage = pool_usage('/%s/%s' % (settings.MNT_PT, p.name))
             total_free = usage[2]  # free + reclaimable
             pu = None
             try:
                 pu = PoolUsage.objects.filter(pool=p.name).latest('id')
                 if ((ts - pu.ts).total_seconds() > 90):
                     pu = None
             except Exception, e:
                 e_msg = ('Unable to get latest pool usage object for '
                          'pool(%s). A new one will be created.' % p.name)
                 logger.error(e_msg)
             if ((pu is None or
                  p.size - (pu.free + pu.reclaimable) != usage[1])):
                 pu = PoolUsage(pool=p.name,
                                free=total_free-total_reclaimable,
                                reclaimable=total_reclaimable, ts=ts)
             else:
                 pu.ts = ts
                 pu.count = pu.count + 1
             self._save_wrapper(pu)