Esempio n. 1
0
func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.CacheStats) error {
	cs := new(utils.CacheStats)
	cs.Destinations = cache2go.CountEntries(utils.DESTINATION_PREFIX)
	cs.RatingPlans = cache2go.CountEntries(utils.RATING_PLAN_PREFIX)
	cs.RatingProfiles = cache2go.CountEntries(utils.RATING_PROFILE_PREFIX)
	cs.Actions = cache2go.CountEntries(utils.ACTION_PREFIX)
	cs.ActionPlans = cache2go.CountEntries(utils.ACTION_PLAN_PREFIX)
	cs.SharedGroups = cache2go.CountEntries(utils.SHARED_GROUP_PREFIX)
	cs.DerivedChargers = cache2go.CountEntries(utils.DERIVEDCHARGERS_PREFIX)
	cs.LcrProfiles = cache2go.CountEntries(utils.LCR_PREFIX)
	cs.Aliases = cache2go.CountEntries(utils.ALIASES_PREFIX)
	if self.CdrStatsSrv != nil && self.Config.CDRStatsEnabled {
		var queueIds []string
		if err := self.CdrStatsSrv.GetQueueIds(0, &queueIds); err != nil {
			return utils.NewErrServerError(err)
		}
		cs.CdrStats = len(queueIds)
	}
	if self.Config.RaterUserServer == utils.INTERNAL {
		var ups engine.UserProfiles
		if err := self.Users.GetUsers(engine.UserProfile{}, &ups); err != nil {
			return utils.NewErrServerError(err)
		}
		cs.Users = len(ups)
	}
	if loadHistInsts, err := self.AccountDb.GetLoadHistory(1, false); err != nil || len(loadHistInsts) == 0 {
		if err != nil { // Not really an error here since we only count in cache
			utils.Logger.Err(fmt.Sprintf("ApierV1.GetCacheStats, error on GetLoadHistory: %s", err.Error()))
		}
		cs.LastLoadId = utils.NOT_AVAILABLE
		cs.LastLoadTime = utils.NOT_AVAILABLE
	} else {
		cs.LastLoadId = loadHistInsts[0].LoadId
		cs.LastLoadTime = loadHistInsts[0].LoadTime.Format(time.RFC3339)
	}
	*reply = *cs
	return nil
}