@@ -117,24 +117,25 @@ func (me *OverviewMetric) collect(ch chan<- prometheus.Metric) (errRet error) {
117117
118118 var cacheMetrics = make ([]* prometheus.Metric , 0 , len (me .MetricConfig .Statistics ))
119119
120+ nowts := time .Now ().Unix ()
121+
120122 for _ , instanceId := range instanceIds {
121123 for _ , statistic := range me .MetricConfig .Statistics {
122124 statistic = strings .ToLower (statistic )
123125 cacheMetric := me .caches [instanceId + "#" + statistic ]
124126 if cacheMetric != nil &&
125127 cacheMetric .metric != nil &&
126- cacheMetric .insertTime + metricCacheTime > time . Now (). Unix () {
128+ cacheMetric .insertTime + metricCacheTime > nowts {
127129 cacheMetrics = append (cacheMetrics , cacheMetric .metric )
128130 }
129131 }
130132 }
131133
132- if len (cacheMetrics ) == len ( me . MetricConfig . Statistics ) * len ( instanceIds ) {
134+ if len (cacheMetrics ) > 0 {
133135 for _ , cacheMetric := range cacheMetrics {
134136 ch <- * cacheMetric
135137 log .Debugf ("metric read from cache,%s" , (* cacheMetric ).Desc ().String ())
136138 }
137-
138139 return
139140 }
140141
@@ -151,6 +152,7 @@ func (me *OverviewMetric) collect(ch chan<- prometheus.Metric) (errRet error) {
151152 /*
152153 Have to deal with allDataRet whether it's wrong or not.
153154 */
155+ nowts = time .Now ().Unix ()
154156 for instanceId , datas := range allDataRet {
155157 if instances [instanceId ] == nil {
156158 log .Errorf ("It was a big api bug, because monitor api return a not exist instance id [%s] " , instanceId )
@@ -178,7 +180,7 @@ func (me *OverviewMetric) collect(ch chan<- prometheus.Metric) (errRet error) {
178180 proMetric := prometheus .MustNewConstMetric (promDesc , prometheus .GaugeValue , float64 (statisticRet ), labels ... )
179181 me .caches [instanceId + "#" + statistic ] = & MetricCache {
180182 metric : & proMetric ,
181- insertTime : time . Now (). Unix () ,
183+ insertTime : nowts ,
182184 }
183185 ch <- proMetric
184186 _ = lastTime
0 commit comments