Fluent-Plugin-Google-Cloud 项目教程
1. 项目目录结构及介绍
fluent-plugin-google-cloud/
├── CONTRIBUTING
├── Gemfile
├── LICENSE
├── README.rdoc
├── Rakefile
├── fluent-plugin-google-cloud.gemspec
├── github/
│ └── workflows/
├── lib/
│ └── fluent/
│ └── plugin/
├── test/
└── .gitignore
└── .rubocop.yml
└── .rubocop_todo.yml
目录结构介绍
- CONTRIBUTING: 贡献指南文件,包含如何为项目贡献代码的说明。
- Gemfile: Ruby 项目的依赖文件,定义了项目所需的 gem 包。
- LICENSE: 项目的开源许可证文件,本项目使用 Apache-2.0 许可证。
- README.rdoc: 项目的主文档文件,包含项目的概述、安装和使用说明。
- Rakefile: Ruby 项目的构建文件,用于定义项目的构建任务。
- fluent-plugin-google-cloud.gemspec: 项目的 gem 规范文件,定义了 gem 的元数据和依赖。
- github/workflows/: 包含 GitHub Actions 的工作流配置文件,用于自动化 CI/CD。
- lib/fluent/plugin/: 包含项目的核心代码,主要是 Fluentd 插件的实现。
- test/: 包含项目的测试代码,用于测试插件的功能。
- .gitignore: Git 忽略文件,定义了哪些文件和目录不应该被 Git 跟踪。
- .rubocop.yml 和 .rubocop_todo.yml: RuboCop 配置文件,用于代码风格检查。
2. 项目启动文件介绍
项目的启动文件主要是 lib/fluent/plugin/
目录下的插件实现文件。这些文件定义了 Fluentd 插件的具体功能。
主要启动文件
- lib/fluent/plugin/out_google_cloud.rb: 这是 Fluentd 的输出插件,负责将日志发送到 Google Cloud Platform 的日志摄取 API。
- lib/fluent/plugin/filter_add_insert_ids.rb: 这是一个过滤器插件,用于在日志条目中嵌入
insertIds
,以保证日志的顺序和唯一性。
3. 项目配置文件介绍
项目的配置文件主要是 Fluentd 的配置文件,用于定义如何使用 fluent-plugin-google-cloud
插件。
配置文件示例
<filter **>
@type add_insert_ids
insert_id_key my_insert_id_field_name # 可选
</filter>
<match **>
@type google_cloud
</match>
配置文件说明
- filter: 定义了一个过滤器,使用
add_insert_ids
插件,将insertIds
嵌入到日志条目中。insert_id_key
是可选的,用于自定义insertId
字段的名称。 - match: 定义了一个匹配规则,使用
google_cloud
插件将日志发送到 Google Cloud Platform 的日志摄取 API。
通过以上配置,Fluentd 可以将日志发送到 Google Cloud Platform,并在日志查看器中查看这些日志。