Docs » Splunk Observability Cloud でサポートされているインテグレーション » Collectorコンポーネント: レシーバー » Filelog レシーバー

Filelog レシーバー 🔗

Filelog レシーバーは、ファイルからのログを追尾し、解析します。サポートされているパイプラインタイプは logs です。詳細は パイプラインでデータを処理する を参照してください。

はじめに 🔗

以下の手順に従って、コンポーネントの設定とアクティベーションを行ってください:

  1. Splunk Distribution of OpenTelemetry Collector をホストまたはコンテナプラットフォームにデプロイします:

  1. 次のセクションで説明するように、Filelog レシーバーを設定します。

  2. Collector を再起動します。

サンプル構成 🔗

Filelogレシーバーを有効にするには、設定ファイルの receivers セクションに filelog を追加します:

receivers:
  filelog:

設定を完了するには、設定ファイルの service セクションの logs パイプラインに、レシーバーを含めます:

service:
  pipelines:
    logs:
      receivers: [filelog]

設定例 🔗

この例では、単純なJSONファイルを追尾する方法を示します:

receivers:
  filelog:
    include: [ /var/log/myservice/*.json ]
    operators:
      - type: json_parser
        timestamp:
          parse_from: attributes.time
          layout: '%Y-%m-%d %H:%M:%S'

この例では、プレーンテキストファイルを追尾する方法を示します:

receivers:
  filelog:
    include: [ /simple.log ]
    operators:
      - type: regex_parser
        regex: '^(?P<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$'
        timestamp:
          parse_from: attributes.time
          layout: '%Y-%m-%d %H:%M:%S'
        severity:
          parse_from: attributes.sev

レシーバーは、simple.logファイルから以下のようなログを読み込みます:

2023-06-19 05:20:50 ERROR This is a test error message

2023-06-20 12:50:00 DEBUG This is a test debug message

演算子を使ってログをフォーマットする 🔗

Filelog レシーバーは、オペレーターを使用してログを希望の形式に処理します。各オペレーターは、ファイルから行を読み込んだり、フィールドから JSON を解析したりといった、単一の責任を果たします。目的の結果を得るには、パイプラインで演算子を連結する必要があります。

例えば、file_input 演算子を使ってファイルから行を読み取ることができます。この操作の結果を regex_parser 演算子に送ると、正規表現パターンに基づいてフィールドが作成されます。次に、file_output 演算子に結果を送って、各行をディスク上のファイルに書き込むことができます。

すべてのオペレーターは、エントリー を作成、変更、または消費します。

  • エントリーは、パイプラインを通過するログデータの基本的な表現です。

  • フィールドは、エントリー内の値を参照するために使用されます。

  • 一般的な式の構文は、いくつかの演算子で使用されます。例えば、式はエントリーのフィルターリングやルーティングに使用できます。

利用可能なオペレーター 🔗

利用可能な演算子の完全なリストについては、GitHubの What operators are available? を参照してください。

以下はオペレーターに適用されます:

  • 各オペレーターは type を持っています。

  • 各オペレーターに一意の ID を与えることができます。

    • パイプライン内で同じタイプの演算子を複数回使用する場合は、Idを指定する必要があります。

    • そうでない場合、Idのデフォルト値は type となります。

  • 演算子は、パイプラインの次の演算子に出力します。

    • パイプラインの最後の演算子は、レシーバーから放出されます。

    • オプションで、outputパラメータを使って別のオペレーターのIdを指定し、そこに直接ログを渡すこともできます。

パーサー演算子 🔗

文字列から値を分離するには、パーサー演算子を使います。パーサーには、単純なものと複雑なものの2つのクラスがあります。

ヘッダーのメタデータを解析する 🔗

ヘッダー・メタデータの解析をオンにするには、filelog.allowHeaderMetadataParsing 機能を設定し、start_at を先頭に設定します。設定すると、ファイル入力演算子はファイルの先頭からヘッダーを読み込もうとします。

以下が該当します:

  • 各ヘッダー行は header.pattern パターンと一致しなければなりません。

  • 各行は header.metadata_operators で定義されたパイプラインに送られます。

  • 埋め込みパイプラインからの結果エントリーの属性は、前の行の属性とマージされます。属性の衝突が発生した場合は、upsert戦略で解決されます。

  • すべてのヘッダー行が読み込まれた後、最終的にマージされたヘッダー属性は、 ファイルに対して出力されるすべてのログ行に存在します。

レシーバーはヘッダーラインを発行しません。

操作を組み込んだパーサー 🔗

タイムスタンプや重要度の解析など、特定のフォローアップ操作を埋め込むために、多くの解析演算子を設定することができます。

詳細については、複雑なパーサーに関する GitHub のエントリー Parsers を参照してください。

マルチライン構成 🔗

設定されている場合、複数行設定ブロックは、file_input オペレーターに、改行以外のパターンでログエントリーを分割するように指示します。

複数行の設定ブロックは、line_start_pattern または line_end_pattern を含んでいなければなりません。これらは、新しいログエントリーの開始またはログエントリーの終了のいずれかにマッチする正規表現パターンです。

サポートされているエンコーディング 🔗

Filelog レシーバーは以下のエンコーディングをサポートしています:

キー

説明

nop

エンコーディングの検証は行いません。ファイルを生のバイトストリームとして扱います。

utf-8

UTF-8エンコーディング。

utf-16le

バイト順がリトルエンディアンのUTF-16エンコーディング。

utf-16be

バイト順がビッグエンディアンのUTF-16エンコーディング。

ascii

ASCIIエンコーディング。

big5

Big5中国語文字エンコーディング。

その他のあまり一般的でないエンコーディングは、ベストエフォートでサポートされています。https://www.iana.org/assignments/character-sets/character-sets.xhtml にある利用可能なエンコーディングのリストを参照してください。

高度なユースケース 🔗

Filelog レシーバーの使用例については、以下のセクションを参照してください。

その他の例は GitHub リポジトリ splunk-otel-collextor/examples にあります。

ログを Splunk Cloud に送信する 🔗

以下の設定を使用して、ログを Splunk Cloud に送信します:

receivers:
  filelog:
    include: [/home/ubuntu/arlogs/*.log]
    logs:
      receivers: [filelog, otlp]
      processors:
      - memory_limiter
      - batch
      - resourcedetection
      #- resource/add_environment
      exporters: [splunk_hec]

exporters:
  # Logs
  splunk_hec:
    token: "${SPLUNK_HEC_TOKEN}"
    endpoint: "${SPLUNK_HEC_URL}"
    source: "otel"
    sourcetype: "otel"

receivers:
  filelog:
    include: [ /output/file.log ]
    operators:
      - type: regex_parser
        regex: '(?P<before>.*)\d\d\d\d-\d\d\d-\d\d\d\d(?P<after>.*)'
        parse_to: body.parsed
        output: before_and_after
      - id: before_and_after
        type: add
        field: body
        value: EXPR(body.parsed.before + "XXX-XXX-XXXX" + body.parsed.after)

切り捨てられたログを Splunk Enterprise に送信する 🔗

ログを切り捨てて Splunk Enterprise に送信するには、以下の設定を使用します:

receivers:
  filelog:
    include: [ /output/file.log ]
    operators:
      - type: regex_parser
        regex: '(?P<before>.*)\d\d\d\d-\d\d\d-\d\d\d\d(?P<after>.*)'
        parse_to: body.parsed
        output: before_and_after
      - id: before_and_after
        type: add
        field: body
        value: EXPR(body.parsed.before + "XXX-XXX-XXXX" + body.parsed.after)


exporters:
  splunk_hec/logs:
    # Splunk HTTP Event Collector token.
    token: "00000000-0000-0000-0000-0000000000000"
    # URL to a Splunk instance to send data to.
    endpoint: "https://splunk:8088/services/collector"
    # Optional Splunk source: https://docs.splunk.com/Splexicon:Source
    source: "output"
    # Splunk index, optional name of the Splunk index targeted.
    index: "logs"
    # Maximum HTTP connections to use simultaneously when sending data. Defaults to 100.
    max_connections: 20
    # Whether to disable gzip compression over HTTP. Defaults to false.
    disable_compression: false
    # HTTP timeout when sending data. Defaults to 10s.
    timeout: 10s
    # Whether to skip checking the certificate of the HEC endpoint when sending data over HTTPS. Defaults to false.
    # For this demo, we use a self-signed certificate on the Splunk docker instance, so this flag is set to true.
    tls:
      insecure_skip_verify: true

processors:
  batch:
  transform:
    log_statements:
      - context: log
        statements:
          - set(body, Substring(body,0, 10))

extensions:
  health_check:
    endpoint: 0.0.0.0:13133
  pprof:
    endpoint: :1888
  zpages:
    endpoint: :55679

service:
  extensions: [ pprof, zpages, health_check ]
  pipelines:
    logs:
      receivers: [ filelog ]
      processors: [ batch, transform ]
      exporters: [ splunk_hec/logs ]

サニタイズされたログを Splunk Enterprise に送信する 🔗

ログをサニタイズして Splunk Enterprise に送信するには、以下の設定を使用します。

receivers:
    filelog:
      include: [ /output/file.log ]
      operators:
        - type: regex_parser
          regex: '(?P<before>.*)\d\d\d\d-\d\d\d-\d\d\d\d(?P<after>.*)'
          parse_to: body.parsed
          output: before_and_after
        - id: before_and_after
          type: add
          field: body
          value: EXPR(body.parsed.before + "XXX-XXX-XXXX" + body.parsed.after)


exporters:
    splunk_hec/logs:
        # Splunk HTTP Event Collector token.
        token: "00000000-0000-0000-0000-0000000000000"
        # URL to a Splunk instance to send data to.
        endpoint: "https://splunk:8088/services/collector"
        # Optional Splunk source: https://docs.splunk.com/Splexicon:Source
        source: "output"
        # Splunk index, optional name of the Splunk index targeted.
        index: "logs"
        # Maximum HTTP connections to use simultaneously when sending data. Defaults to 100.
        max_connections: 20
        # Whether to disable gzip compression over HTTP. Defaults to false.
        disable_compression: false
        # HTTP timeout when sending data. Defaults to 10s.
        timeout: 10s
        # Whether to skip checking the certificate of the HEC endpoint when sending data over HTTPS. Defaults to false.
        # For this demo, we use a self-signed certificate on the Splunk docker instance, so this flag is set to true.
        insecure_skip_verify: true

processors:
    batch:

extensions:
    health_check:
      endpoint: 0.0.0.0:13133
    pprof:
      endpoint: :1888
    zpages:
      endpoint: :55679

service:
    extensions: [pprof, zpages, health_check]
    pipelines:
      logs:
        receivers: [filelog]
        processors: [batch]
        exporters: [splunk_hec/logs]

ログを異なるインデックスにルーティングする 🔗

以下の設定を使用して、ログを異なる Splunk インデックスにルーティングします。

receivers:
    filelog:
      include: [ /output/file*.log ]
      start_at: beginning
      operators:
        - type: regex_parser
          regex: '(?P<logindex>log\d?)'

exporters:
    splunk_hec/logs:
        # Splunk HTTP Event Collector token.
        token: "00000000-0000-0000-0000-0000000000000"
        # URL to a Splunk instance to send data to.
        endpoint: "https://splunk:8088/services/collector"
        # Optional Splunk source: https://docs.splunk.com/Splexicon:Source
        source: "output"
        # Maximum HTTP connections to use simultaneously when sending data. Defaults to 100.
        max_connections: 20
        # Whether to disable gzip compression over HTTP. Defaults to false.
        disable_compression: false
        # HTTP timeout when sending data. Defaults to 10s.
        timeout: 10s
        tls:
          # Whether to skip checking the certificate of the HEC endpoint when sending data over HTTPS. Defaults to false.
          # For this demo, we use a self-signed certificate on the Splunk docker instance, so this flag is set to true.
          insecure_skip_verify: true
processors:
    batch:
    attributes/log:
      include:
        match_type: strict
        attributes:
          - { key: logindex, value: 'log' }
      actions:
        - key: com.splunk.index
          action: upsert
          value: "logs"
        - key: logindex
          action: delete
    attributes/log2:
      include:
        match_type: strict
        attributes:
          - { key: logindex, value: 'log2' }
      actions:
        - key: com.splunk.index
          action: upsert
          value: "logs2"
        - key: logindex
          action: delete
    attributes/log3:
      include:
        match_type: strict
        attributes:
          - { key: logindex, value: 'log3' }
      actions:
        - key: com.splunk.index
          action: upsert
          value: "logs3"
        - key: logindex
          action: delete

extensions:
    health_check:
      endpoint: 0.0.0.0:13133
    pprof:
      endpoint: :1888
    zpages:
      endpoint: :55679

service:
    extensions: [pprof, zpages, health_check]
    pipelines:
      logs:
        receivers: [filelog]
        processors: [batch, attributes/log, attributes/log2, attributes/log3]
        exporters: [splunk_hec/logs]

ログ・ソースをソース・タイプと関連付ける 🔗

この例では、Collector がファイルからデータを収集し、各ソースを異なるソースタイプに関連付けて Splunk Enterprise に送信する方法を紹介します。ソースタイプは、イベントの構造を識別するデフォルトのフィールドで、インデックス作成プロセスで Splunk Enterprise がデータをどのようにフォーマットするかを決定します。

processors:
  batch:
  resource/one:
    attributes:
      # Set the com.splunk.sourcetype log attribute key to sourcetype1.
      # com.splunk.sourcetype is the default key the HEC exporter will use to extract the source type of the record.
      # See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/splunkhecexporter
      # under the configuration key `hec_metadata_to_otel_attrs/sourcetype`
      - key: com.splunk.sourcetype
        value: "sourcetype1"
        action: upsert
  resource/two:
    attributes:
      - key: com.splunk.sourcetype
        value: "sourcetype2"
        action: upsert
  resource/three:
    attributes:
      - key: com.splunk.sourcetype
        value: "sourcetype3"
        action: upsert

receivers:
    filelog/onefile:
      include: [ /output/file.log ]
    filelog/twofile:
      include: [ /output/file2.log ]
    filelog/threefolder:
      include: [ /output3/*.log ]

exporters:
    splunk_hec/logs:
        # Splunk HTTP Event Collector token.
        token: "00000000-0000-0000-0000-0000000000000"
        # URL to a Splunk instance to send data to.
        endpoint: "https://splunk:8088/services/collector"
        # Optional Splunk source: https://docs.splunk.com/Splexicon:Source
        source: "output"
        # Splunk index, optional name of the Splunk index targeted.
        index: "logs"
        # Maximum HTTP connections to use simultaneously when sending data. Defaults to 100.
        max_connections: 20
        # Whether to disable gzip compression over HTTP. Defaults to false.
        disable_compression: false
        # HTTP timeout when sending data. Defaults to 10s.
        timeout: 10s
        tls:
          # Whether to skip checking the certificate of the HEC endpoint when sending data over HTTPS. Defaults to false.
          # For this demo, we use a self-signed certificate on the Splunk docker instance, so this flag is set to true.
          insecure_skip_verify: true



extensions:
    health_check:
      endpoint: 0.0.0.0:13133
    pprof:
      endpoint: :1888
    zpages:
      endpoint: :55679

service:
    extensions: [pprof, zpages, health_check]
    pipelines:
      logs/one:
        receivers: [ filelog/onefile ]
        processors: [ batch, resource/one ]
        exporters: [ splunk_hec/logs ]
      logs/two:
        receivers: [ filelog/twofile ]
        processors: [ batch, resource/two ]
        exporters: [ splunk_hec/logs ]
      logs/three:
        receivers: [ filelog/threefolder ]
        processors: [ batch, resource/three ]
        exporters: [ splunk_hec/logs ]

設定 🔗

注釈

デフォルトでは、start_atend に設定されているため、レシーバーは、アクティブに書き込まれていないファイルからログを読み込むことはない。

次の表に、Filelog レシーバーの設定オプションを示します:

トラブルシューティング 🔗

Splunk Observability Cloudをご利用のお客様で、Splunk Observability Cloudでデータを確認できない場合は、以下の方法でサポートを受けることができます。

Splunk Observability Cloudをご利用のお客様

見込み客および無料トライアルユーザー様

  • Splunk Answers のコミュニティサポートで質問し、回答を得る

  • Splunk #observability ユーザーグループの Slack チャンネルに参加して、世界中の顧客、パートナー、Splunk 社員とのコミュニケーションを図る。参加するには、Get Started with Splunk Community マニュアルの チャットグループ を参照してください。

This page was last updated on 2024年05月29日.