disable collector correctly

This commit is contained in:
Hector 2021-10-11 21:59:56 +01:00
parent 3384cc92e7
commit 52468bb63e
2 changed files with 4 additions and 3 deletions

View File

@ -46,9 +46,6 @@ func (settings *AppSettings) validateFlags() {
minServerPort, maxServerPort, settings.MetricsPort) minServerPort, maxServerPort, settings.MetricsPort)
flagsValid = false flagsValid = false
} }
if settings.FileCollectorPath != "" {
settings.FileCollectorEnabled = true
}
if settings.FileCollectorEnabled && settings.FileCollectorPath == "" { if settings.FileCollectorEnabled && settings.FileCollectorPath == "" {
fmt.Printf("file collector directory path must not be empty if collector enabled\n") fmt.Printf("file collector directory path must not be empty if collector enabled\n")
flagsValid = false flagsValid = false

View File

@ -9,6 +9,10 @@ import (
) )
func (c *Collector) WriteTextFileMetrics(w http.ResponseWriter, r *http.Request) { func (c *Collector) WriteTextFileMetrics(w http.ResponseWriter, r *http.Request) {
if !c.enabled {
return
}
files, err := ioutil.ReadDir(c.folderPath) files, err := ioutil.ReadDir(c.folderPath)
if err != nil { if err != nil {
c.appendErrorForPath(c.folderPath) c.appendErrorForPath(c.folderPath)