@@ -62,13 +62,13 @@ var logVarRegex = regexp.MustCompile(`\$([a-zA-Z]+[_[a-zA-Z]+]*)`)
6262// This metrics source is used to tail the NGINX access logs to retrieve metrics.
6363
6464type NginxAccessLog struct {
65- baseDimensions * metrics.CommonDim
66- * namedMetric
65+ baseDimensions * metrics.CommonDim
6766 mu * sync.Mutex
6867 logFormats map [string ]string
6968 logs map [string ]context.CancelFunc
7069 binary core.NginxBinary
7170 nginxType string
71+ namespace string
7272 collectionInterval time.Duration
7373 buf []* metrics.StatsEntityWrapper
7474 logger * MetricSourceLogger
@@ -85,12 +85,12 @@ func NewNginxAccessLog(
8585
8686 nginxAccessLog := & NginxAccessLog {
8787 baseDimensions ,
88- & namedMetric {namespace : namespace },
8988 & sync.Mutex {},
9089 make (map [string ]string ),
9190 make (map [string ]context.CancelFunc ),
9291 binary ,
9392 nginxType ,
93+ namespace ,
9494 collectionInterval ,
9595 []* metrics.StatsEntityWrapper {},
9696 NewMetricSourceLogger (),
@@ -203,8 +203,8 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
203203
204204 logPattern = replaceCustomLogVars (logPattern )
205205
206- log .Debugf ("Collecting from: %s using format: %s" , logFile , logFormat )
207- log .Debugf ("Pattern used for tailing logs: %s" , logPattern )
206+ log .Debugf ("Collecting from %s using format %s" , logFile , logFormat )
207+ log .Debugf ("Pattern used for tailing logs, %s" , logPattern )
208208
209209 httpCounters , upstreamCounters , upstreamCacheCounters := map [string ]float64 {}, map [string ]float64 {}, map [string ]float64 {}
210210 gzipRatios , requestLengths , requestTimes , upstreamResponseLength , upstreamResponseTimes , upstreamConnectTimes , upstreamHeaderTimes := []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}
@@ -214,19 +214,21 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
214214 if logPattern == "ltsv" {
215215 t , err := tailer .NewLTSVTailer (logFile )
216216 if err != nil {
217- log .Errorf ("unable to tail %q: %v" , logFile , err )
217+ log .Errorf ("Unable to tail %q: %v" , logFile , err )
218218 return
219219 }
220220 go t .Tail (ctx , data )
221221 } else {
222222 t , err := tailer .NewPatternTailer (logFile , map [string ]string {"DEFAULT" : logPattern })
223223 if err != nil {
224- log .Errorf ("unable to tail %q: %v" , logFile , err )
224+ log .Errorf ("Unable to tail %q: %v" , logFile , err )
225225 return
226226 }
227227 go t .Tail (ctx , data )
228228 }
229229
230+ accessLogNamedMetric := namedMetric {namespace : c .namespace }
231+
230232 tick := time .NewTicker (c .collectionInterval )
231233 defer tick .Stop ()
232234 for {
@@ -295,7 +297,7 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
295297 upstreamCounters [n ] = 1
296298 }
297299 } else {
298- log .Debugf ("Error getting upstream status value from access logs , %v" , err )
300+ log .Debugf ("Error getting upstream status value from access log %s , %v" , logFile , err )
299301 }
300302 }
301303
@@ -330,6 +332,8 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
330332 case <- tick .C :
331333 mu .Lock ()
332334
335+ log .Tracef ("Collecting metrics from access log: %s" , logFile )
336+
333337 c .baseDimensions .NginxType = c .nginxType
334338 c .baseDimensions .PublishedAPI = logFile
335339
@@ -361,22 +365,23 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
361365 upstreamCounters ["upstream.response.length" ] = getAverageMetricValue (upstreamResponseLength )
362366 }
363367
364- c .group = "http"
365- simpleMetrics := c .convertSamplesToSimpleMetrics (httpCounters )
366-
367- c .group = ""
368- simpleMetrics = append (simpleMetrics , c .convertSamplesToSimpleMetrics (upstreamCounters )... )
368+ accessLogNamedMetric .group = "http"
369+ log .Tracef ("Converting httpCounters for %s access log file, httpCounters=%v" , logFile , httpCounters )
370+ simpleMetrics := accessLogNamedMetric .convertSamplesToSimpleMetrics (httpCounters )
369371
370- c .group = ""
371- simpleMetrics = append (simpleMetrics , c .convertSamplesToSimpleMetrics (upstreamCacheCounters )... )
372+ accessLogNamedMetric .group = ""
373+ log .Tracef ("Converting upstreamCounters for %s access log file, upstreamCounters=%v" , logFile , upstreamCounters )
374+ simpleMetrics = append (simpleMetrics , accessLogNamedMetric .convertSamplesToSimpleMetrics (upstreamCounters )... )
375+ log .Tracef ("Converting upstreamCacheCounters for %s access log file, upstreamCacheCounters=%v" , logFile , upstreamCacheCounters )
376+ simpleMetrics = append (simpleMetrics , accessLogNamedMetric .convertSamplesToSimpleMetrics (upstreamCacheCounters )... )
372377
373- log .Tracef ("Access log metrics collected: %v" , simpleMetrics )
378+ log .Tracef ("Access log %s metrics collected: %v" , logFile , simpleMetrics )
374379
375380 // reset the counters
376381 httpCounters , upstreamCounters , upstreamCacheCounters = map [string ]float64 {}, map [string ]float64 {}, map [string ]float64 {}
377382 gzipRatios , requestLengths , requestTimes , upstreamResponseLength , upstreamResponseTimes , upstreamConnectTimes , upstreamHeaderTimes = []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}, []float64 {}
378383
379- log .Debugf ("access log stats count: %d" , len (simpleMetrics ))
384+ log .Debugf ("Access log %s stats count: %d" , logFile , len (simpleMetrics ))
380385
381386 c .buf = append (c .buf , metrics .NewStatsEntityWrapper (c .baseDimensions .ToDimensions (), simpleMetrics , proto .MetricsReport_INSTANCE ))
382387
0 commit comments