|
| 1 | +# Cnos-Telegraf |
| 2 | + |
| 3 | +> 提交 PR 至 telegraf 官方仓库时,请一定注意,不要带上本文件。 |
| 4 | +
|
| 5 | +CnosDB-Telegraf 基于 Telegraf 进行开发,增加了一些功能与插件。 |
| 6 | + |
| 7 | +## 原版 Telegraf 文档 |
| 8 | + |
| 9 | +[README.md](../README.md) |
| 10 | + |
| 11 | +## 分支介绍 |
| 12 | + |
| 13 | +### 新增功能 |
| 14 | + |
| 15 | +- `feature/doc` - 文档。 |
| 16 | +- `feature/docker` - 构建 telegraf 为 docker 镜像。 |
| 17 | +- `feature/high_priority_channel` - 使 input 插件能够将 output 插件的处理结果返回给调用者。 |
| 18 | +- `feature/cnosdb_subscription` - 添加 input 插件用于处理 CnosDB 订阅消息的报文。 |
| 19 | +- `feature/opentsdb_json` - 添加 input 插件用于处理 JSON 格式的 OpenTSDB 写请求的报文。 |
| 20 | + |
| 21 | +### cnosdb |
| 22 | + |
| 23 | +## 如何更新版本 |
| 24 | + |
| 25 | +确保 git 记录了官方仓库的信息。 |
| 26 | + |
| 27 | +```shell |
| 28 | +git remote add -t master telegraf [email protected]:influxdata/telegraf.git |
| 29 | +``` |
| 30 | + |
| 31 | +更新 master 分支。 |
| 32 | + |
| 33 | +```shell |
| 34 | +git fetch --all --tags --prune --jobs=10 |
| 35 | +## 按提交时间获得 tag 列表,找到最新的 tag,假设最新的 tag 为 v1.32.2 |
| 36 | +git tag --sort=-committerdate |
| 37 | +## 获得最新的 tag 对应的 commit id |
| 38 | +#git rev-list -n 1 v1.32.2 |
| 39 | +git checkout master |
| 40 | +git reset --hard v1.32.2 |
| 41 | +``` |
| 42 | + |
| 43 | +对所有的 feature 分支执行变基。 |
| 44 | + |
| 45 | +```shell |
| 46 | +git checkout feature/docker |
| 47 | +git rebase master |
| 48 | + |
| 49 | +git checkout feature/opentsdb_json |
| 50 | +git rebase master |
| 51 | + |
| 52 | +git checkout feature/high_priority_channel |
| 53 | +git rebase master |
| 54 | + |
| 55 | +## feature/cnosdb_subscription 依赖 feature/high_priority_channel |
| 56 | +git checkout feature/cnosdb_subscription |
| 57 | +git rebase feature/high_priority_channel |
| 58 | +``` |
| 59 | + |
| 60 | +使用 `git cherry-pick` 将所有的 `feature/` 的功能合并至 `cnosdb/` |
| 61 | + |
| 62 | +```shell |
| 63 | +git checkout master |
| 64 | +git checkout -b cnosdb/main/$(date +"%Y%m%d_%H%M%S") |
| 65 | +git cherry-pick $(git rev-list -n 1 feature/docker) |
| 66 | +git cherry-pick $(git rev-list -n 1 feature/high_priority_channel) |
| 67 | +git cherry-pick $(git rev-list -n 1 feature/opentsdb_json) |
| 68 | +git cherry-pick $(git rev-list -n 1 feature/cnosdb_subscription) |
| 69 | +git cherry-pick $(git rev-list -n 1 feature/doc) |
| 70 | +``` |
| 71 | + |
| 72 | +## Cnos-Telegraf 的改动说明 |
| 73 | + |
| 74 | +### Parser Plugin |
| 75 | + |
| 76 | +增加 Parser 插件 opentsdb_json,用于采集 OpenTSDB 的 JSON 格式的写入请求。 |
| 77 | + |
| 78 | +#### OpenTSDB JSON |
| 79 | + |
| 80 | +通过使用 Input 插件 http_listener_v2 并配置 `data_format` 为 `"opentsdb"`,将能够解析 OpenTSDB 格式的写入请求。 |
| 81 | + |
| 82 | +```toml |
| 83 | +[[inputs.http_listener_v2]] |
| 84 | +service_address = ":8080" |
| 85 | +paths = ["/api/put"] |
| 86 | +methods = ["POST", "PUT"] |
| 87 | +data_format = "opentsdb_json" |
| 88 | +``` |
| 89 | + |
| 90 | +### Input Plugin |
| 91 | + |
| 92 | +#### CnosDB 订阅 |
| 93 | + |
| 94 | +增加 Input 插件 cnosdb_subscription,用于搜集 CnosDB 订阅功能推送的数据,搭配 Output 插件即可实现异构数据同步。 |
| 95 | + |
| 96 | +```toml |
| 97 | +[[inputs.cnosdb_subscription]] |
| 98 | +service_address = ":8803" |
| 99 | +``` |
| 100 | + |
| 101 | +- **配置介绍** |
| 102 | + |
| 103 | +| 参数 | 说明 | |
| 104 | +|-----------------|------| |
| 105 | +| service_address | 监听端口 | |
| 106 | + |
| 107 | +#### 通用参数 |
| 108 | + |
| 109 | +增加配置参数 high_priority_io,用于开启端到端模式。 |
| 110 | + |
| 111 | +当设置为 true 时,写入的数据将立即发送到 Output 插件,并根据 Output 插件的返回参数来决定返回值。 |
| 112 | + |
| 113 | +```toml |
| 114 | +[[inputs.http_listener_v2]] |
| 115 | +service_address = ":8080" |
| 116 | +paths = ["/api/put"] |
| 117 | +methods = ["POST", "PUT"] |
| 118 | +data_format = "opentsdb" |
| 119 | +high_priority_io = true |
| 120 | +``` |
| 121 | + |
| 122 | +## 构建 |
| 123 | + |
| 124 | +1. [安装 Go](https://golang.org/doc/install),版本要求 >=1.22 |
| 125 | +2. 从 Github 克隆仓库: |
| 126 | + |
| 127 | + ```shell |
| 128 | + git clone https://github.com/cnosdb/cnos-telegraf.git |
| 129 | + ``` |
| 130 | + |
| 131 | +3. 检出与 CnosDB 对应的版本,在仓库目录下执行 `make build` |
| 132 | + |
| 133 | + ```shell |
| 134 | + cd cnos-telegraf |
| 135 | + # 如果为了适配 cnosdb/2.4 版本 |
| 136 | + git checkout cnosdb/2.4 |
| 137 | + make build |
| 138 | + ``` |
| 139 | + |
| 140 | +## 启动 |
| 141 | + |
| 142 | +执行以下指令,查看用例: |
| 143 | + |
| 144 | +```shell |
| 145 | +telegraf --help |
| 146 | +``` |
| 147 | + |
| 148 | +### 生成一份标准的 telegraf 配置文件 |
| 149 | + |
| 150 | +```shell |
| 151 | +telegraf config > telegraf.conf |
| 152 | +``` |
| 153 | + |
| 154 | +### 生成一份 telegraf 配置文件,仅包含 cpu 指标采集 & influxdb 输出两个插件 |
| 155 | + |
| 156 | +```shell |
| 157 | +telegraf config --section-filter agent:inputs:outputs --input-filter cpu --output-filter influxdb |
| 158 | +``` |
| 159 | + |
| 160 | +### 运行 telegraf 但是将采集指标输出到标准输出 |
| 161 | + |
| 162 | +```shell |
| 163 | +telegraf --config telegraf.conf --test |
| 164 | +``` |
| 165 | + |
| 166 | +### 运行 telegraf 并通过配置文件来管理加载的插件 |
| 167 | + |
| 168 | +```shell |
| 169 | +telegraf --config telegraf.conf |
| 170 | +``` |
| 171 | + |
| 172 | +### 运行 telegraf,仅加载 cpu & memory 指标采集,和 influxdb 输出插件 |
| 173 | + |
| 174 | +```shell |
| 175 | +telegraf --config telegraf.conf --input-filter cpu:mem --output-filter influxdb |
| 176 | +``` |
0 commit comments