コード例 #1
0
//Checks if the files are old enough, if so they will be added in the queue
func (nfc NagfluxFileCollector) run() {
	for {
		select {
		case <-nfc.quit:
			nfc.quit <- true
			return
		case <-time.After(spoolfile.IntervalToCheckDirectory):
			for _, currentFile := range spoolfile.FilesInDirectoryOlderThanX(nfc.folder, spoolfile.MinFileAgeInSeconds) {
				data, err := ioutil.ReadFile(currentFile)
				if err != nil {
					break
				}
				for _, line := range strings.SplitAfter(string(data), "\n") {
					line = strings.TrimSpace(line)
					if line == "" {
						continue
					}
					select {
					case <-nfc.quit:
						nfc.quit <- true
						return
					case nfc.results <- line:
					case <-time.After(time.Duration(1) * time.Minute):
						nfc.log.Warn("NagfluxFileCollector: Could not write to buffer")
					}
				}
				err = os.Remove(currentFile)
				if err != nil {
					logging.GetLogger().Warn(err)
				}
			}
		}
	}
}
コード例 #2
0
//Checks if the files are old enough, if so they will be added in the queue
func (nfc FileCollector) run() {
	for {
		select {
		case <-nfc.quit:
			nfc.quit <- true
			return
		case <-time.After(spoolfile.IntervalToCheckDirectory):
			pause := config.PauseNagflux.Load().(bool)
			if pause {
				logging.GetLogger().Debugln("NagfluxFileCollector in pause")
				continue
			}
			for _, currentFile := range spoolfile.FilesInDirectoryOlderThanX(nfc.folder, spoolfile.MinFileAge) {
				for _, p := range nfc.parseFile(currentFile) {
					for _, r := range nfc.results {
						select {
						case <-nfc.quit:
							nfc.quit <- true
							return
						case r <- p:
						case <-time.After(time.Duration(1) * time.Minute):
							nfc.log.Warn("NagfluxFileCollector: Could not write to buffer")
						}
					}
				}
				err := os.Remove(currentFile)
				if err != nil {
					logging.GetLogger().Warn(err)
				}
			}
		}
	}
}