示例#1
0
// StatsJSON returns an object formatted as expected to be serialized to JSON and served.
func (dsStats Stats) JSON(filter dsdata.Filter, params url.Values) dsdata.StatsOld {
	now := time.Now().Unix()
	jsonObj := &dsdata.StatsOld{
		DeliveryService: map[enum.DeliveryServiceName]map[dsdata.StatName][]dsdata.StatOld{},
		QueryParams:     http_server.ParametersStr(params),
		DateStr:         http_server.DateStr(time.Now()),
	}

	for deliveryService, stat := range dsStats.DeliveryService {
		if !filter.UseDeliveryService(deliveryService) {
			continue
		}
		jsonObj.DeliveryService[deliveryService] = map[dsdata.StatName][]dsdata.StatOld{}
		jsonObj = addCommonData(jsonObj, &stat.CommonStats, deliveryService, now, filter)
		for cacheGroup, cacheGroupStats := range stat.CacheGroups {
			jsonObj = addStatCacheStats(jsonObj, cacheGroupStats, deliveryService, "location."+string(cacheGroup)+".", now, filter)
		}
		for cacheType, typeStats := range stat.Types {
			jsonObj = addStatCacheStats(jsonObj, typeStats, deliveryService, "type."+cacheType.String()+".", now, filter)
		}
		jsonObj = addStatCacheStats(jsonObj, stat.TotalStats, deliveryService, "total.", now, filter)
	}
	return *jsonObj
}