2016-04-17 15 views

答えて

0

filebeatはオープンソースですので、あなたがすることができ、常にgo look yourself

ここでファイルが更新されているかどうかをチェックする上でリンクされたファイルから行くのコードです。

...は正確には関係のないコードブロックですが、誰もがこれを読んで、ファイル全体を見てみることをお勧めします。

// 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は設定で指定されているすべてのn -length時間ブロック呼び出されます。 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 { 
     ... 

、これはSTATコールに基づいてstat <file>

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

だろうLinuxの場合、OSの特定の呼び出しを使用してファイルの統計情報を確認し、それがあれば決定されますハーベスタ、ファイルを読み込むこのアプリケーションの部分は、起動する必要があります。

 // 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ファイルは、ファイルを収穫前回更新されているかどうかを確認するためにOSによって報告されたファイルの統計情報を使用していました。

関連する問題