gpt4 book ai didi

elasticsearch - filebeat 如何检查文件中的新内容?

转载 作者:数据小太阳 更新时间:2023-10-29 03:15:24 25 4
gpt4 key购买 nike

filebeat 是否使用 tail -f 检查文件中的新内容,然后将其刷新到所需的输出?或者有没有其他方法检查文件中的新内容?

最佳答案

由于 filebeat 是开源的,您可以随时 go look yourself

这是来自上述链接文件的 go 代码,用于检查文件是否已更新。

我已经大幅删节了这段代码,在任何你看到的地方 ...是一个不完全相关的代码块,我鼓励任何阅读此文件的人也去看看整个文件,它写得很好。

 // Scan starts a scanGlob for each provided path/glob
func (p *ProspectorLog) scan() {

newlastscan := time.Now()

// Now let's do one quick scan to pick up new files
for _, path := range p.config.Paths {
p.scanGlob(path)
}
p.lastscan = newlastscan
}

上面的函数每 n 被调用一次-length 时间 block ,其中 n在配置中指定。 ScanGlob 被调用,如下所示。

// Scans the specific path which can be a glob (/**/**/*.log)
// For all found files it is checked if a harvester should be started
func (p *ProspectorLog) scanGlob(glob string) {

...

// Evaluate the path as a wildcards/shell glob
matches, err := filepath.Glob(glob)
...

// Check any matched files to see if we need to start a harvester
for _, file := range matches {
...

对于匹配 glob 的所有文件,使用操作系统特定调用检查文件的统计信息,对于 linux 这将是 stat <file>

        // Stat the file, following any symlinks.
fileinfo, err := os.Stat(file)
...

根据 stat 调用,决定是否需要启动收割机,即此 go 应用程序中读取文件的部分。

        // Conditions for starting a new harvester:
// - file path hasn't been seen before
// - the file's inode or device changed
if !isKnown {
p.checkNewFile(h)
} else {
h.Stat.Continue(&lastinfo)
p.checkExistingFile(h, &newFile, &oldFile)
}

// Track the stat data for this file for later comparison to check for
// rotation/etc
p.prospectorList[h.Path] = *h.Stat
}
}

TL;DR:Filebeat 使用操作系统报告的文件统计信息来查看自上次收集文件以来文件是否已更新。

关于elasticsearch - filebeat 如何检查文件中的新内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36682714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com