资讯详情

资讯详情

VictoriaMetrics vmctl 数据迁移工具实战指南:从 Prometheus、InfluxDB、OpenTSDB、Thanos 等迁移到 VictoriaMetrics

VictoriaMetrics vmctl 数据迁移工具实战指南从 Prometheus、InfluxDB、OpenTSDB、Thanos 等迁移到 VictoriaMetrics【免费下载链接】VictoriaMetricsVictoriaMetrics: fast, cost-effective monitoring solution and time series database项目地址: https://gitcode.com/GitHub_Trending/vi/VictoriaMetricsvmctlVictoriaMetrics command-line tool是 VictoriaMetrics 官方提供的数据迁移命令行工具作为source数据源与destinationVictoriaMetrics 目标端之间的代理将历史时序数据从 Prometheus、InfluxDB、OpenTSDB、Thanos、Cortex、Mimir、Promscale 等系统迁移到单机版或集群版 VictoriaMetrics。本文以仓库文档 docs/victoriametrics/vmctl/vmctl.md 为主体结合 app/vmctl 源码与各迁移模式子文档完整讲解 vmctl 的全部迁移模式、目标端配置、性能调优、迁移过程监控、数据验证以及源码实现细节帮助读者掌握一套可落地的历史数据迁移方案。vmctl 支持的迁移模式总览vmctl 以子命令COMMANDS的方式组织不同的迁移模式。运行./vmctl-prod --help可以看到完整命令列表$ ./vmctl-prod --help NAME: vmctl - VictoriaMetrics command-line tool USAGE: vmctl [global options] command [command options] [arguments...] COMMANDS: opentsdb Migrate time series from OpenTSDB influx Migrate time series from InfluxDB remote-read Migrate time series via Prometheus remote-read protocol prometheus Migrate time series from Prometheus mimir Migrate time series from Mimir object storage or local filesystem thanos Migrate time series from Thanos blocks (supports raw and downsampled data) vm-native Migrate time series between VictoriaMetrics installations verify-block Verifies exported block with VictoriaMetrics Native format各迁移模式的适用场景与迁移路径可归纳如下模式数据源目标端迁移路径prometheusPrometheus 快照Snapshot API 生成VictoriaMetrics 单机/集群docs/victoriametrics/vmctl/prometheus.mdinfluxInfluxDB v1VictoriaMetrics 单机/集群docs/victoriametrics/vmctl/influxdb.mdopentsdbOpenTSDBVictoriaMetrics 单机/集群docs/victoriametrics/vmctl/opentsdb.mdvm-nativeVictoriaMetrics 单机/集群VictoriaMetrics 单机/集群含集群到集群docs/victoriametrics/vmctl/victoriametrics.mdremote-read支持 Prometheus remote read 协议的系统Thanos、Cortex、Mimir、PromscaleVictoriaMetrics 单机/集群docs/victoriametrics/vmctl/remoteread.mdthanosThanos 存储块支持原始数据与降采样数据VictoriaMetrics 单机/集群docs/victoriametrics/vmctl/thanos.mdmimirMimir 对象存储或本地文件系统VictoriaMetrics 单机/集群docs/victoriametrics/vmctl/mimir.mdverify-block本地导出的 native 格式数据块—纯校验见下文验证导出数据块说明thanos、mimir在最新版本中已作为独立子命令出现见 vmctl_flags.mdremote-read模式则面向所有支持 Prometheus remote read 协议的远端数据源。快速开始获取与运行 vmctl获取二进制vmctl 以两种形式发布Docker 镜像二进制发布包随vmutils压缩包一起发布。下载并解压以 v1.151.0 的 darwin/arm64 为例wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.151.0/vmutils-darwin-arm64-v1.151.0.tar.gz tar xzf vmutils-darwin-arm64-v1.151.0.tar.gz解压后即可运行./vmctl-prod查看全部支持的模式见上文命令列表。vmctl 的工作模型vmctl 本质上是 source 与 destination 之间的代理proxy它从 source 拉取数据再写入 destination。source通过子命令指定例如prometheus、influx、opentsdb等。每个子命令拥有自己独立的 flag 集合前缀为influx-、prom-、opentsdb-等。destination所有模式共享一组以vm-为前缀的通用 flag。以influx子命令为例其帮助信息可以同时看到两类 flag$ ./vmctl-prod influx --help OPTIONS: --influx-addr value InfluxDB server addr (default: http://localhost:8086) --influx-user value InfluxDB user [$INFLUX_USERNAME] ... --vm-addr value VictoriaMetrics address to perform import requests. --vm-user value VictoriaMetrics username for basic auth [$VM_USERNAME] --vm-password value VictoriaMetrics password for basic auth [$VM_PASSWORD]每个迁移模式的详细文档均可在vmctl菜单下的对应章节找到各模式的完整 flag 列表可通过./vmctl mode --help查看。配置 VictoriaMetrics 目标端对于所有迁移模式都需要通过--vm-addr指定 VictoriaMetrics 目标端地址。单机版示例./vmctl prometheus \ --vm-addrvictoriametrics-addr:8428 \ --prom-snapshot/path/to/snapshot将victoriametrics-addr替换为 VictoriaMetrics 的主机名或 IP 地址。集群版则需要额外指定--vm-account-id租户 ID并使用vminsert的地址http://vminsert-addr:8480将vminsert-addr替换为 vminsert 服务的主机名或 IP。如果集群部署了多个 vminsert建议在其前配置负载均衡。从源码 app/vmctl/main.go 的initConfigVM可以看出--vm-addr在导入开始前会被校验httputil.CheckURL随后由vm.NewImporter创建导入器其中会先对目标端执行一次 Ping 就绪检查对应 flag 帮助中提到的/health端点检查确认目标端可用后才会启动导入 worker。迁移模式详解Prometheus → VictoriaMetrics快照迁移vmctl通过读取 Prometheus Snapshot API 生成的快照目录来迁移历史数据。迁移前需要先通过 Prometheus 的管理接口创建快照可参考官方文档中Taking snapshots of Prometheus data一节并将快照目录放到 vmctl 可访问的同一文件系统上然后执行./vmctl prometheus \ --vm-addrvictoriametrics-addr:8428 \ --prom-snapshot/path/to/snapshot启动后 vmctl 会先探测快照中的所有 block、读取元数据并打印发现的数据统计随后询问是否继续./vmctl prometheus --prom-snapshot/path/to/snapshot \ --vm-addrhttp://localhost:8428 Prometheus import mode Prometheus snapshot stats: blocks found: 14; blocks skipped: 0; min time: 1581288163058 (2020-02-09T22:42:43Z); max time: 1582409128139 (2020-02-22T22:05:28Z); samples: 32549106; series: 27289. Found 14 blocks to import. Continue? [Y/n] y 14 / 14 [---------------------------] 100.00% 0 p/s 2020/02/23 15:50:03 Import finished! 2020/02/23 15:50:03 VictoriaMetrics importer stats: idle duration: 6.152953029s; time spent while importing: 44.908522491s; total samples: 32549106; samples/s: 724786.84; total bytes: 669.1 MB; bytes/s: 14.9 MB; import requests: 323; import requests retries: 0; 2020/02/23 15:50:03 Total time: 51.077451066s以上输出为示例实际数字取决于源数据规模与运行环境。Prometheus 迁移的过滤按时间过滤使用--prom-filter-time-start与--prom-filter-time-end格式为 RFC3339。该过滤器会被应用两次一是在探测阶段用于丢弃不相关的 block二是在 block 内部进一步过滤时序。下面的例子将迁移范围缩小到两个 block./vmctl prometheus --prom-snapshot/path/to/snapshot \ --prom-filter-time-start2020-02-07T00:07:01Z \ --prom-filter-time-end2020-02-11T00:07:01Z按标签过滤--prom-filter-label标签名例如__name__或instance--prom-filter-label-value匹配标签值的正则表达式默认.*匹配全部。组合示例./vmctl prometheus --prom-snapshot/path/to/snapshot \ --prom-filter-label__name__ \ --prom-filter-label-valuepromhttp.* \ --prom-filter-time-start2020-02-07T00:07:01Z \ --prom-filter-time-end2020-02-11T00:07:01ZPrometheus 模式性能配置Prometheus 模式使用 Prometheus 库读取快照数据读取性能受库本身、磁盘 IO 以及--prom-concurrency并发读快照的 reader 数量影响。建议将--prom-concurrency设置为 vmctl 可用的 CPU 核数。Prometheus 模式的完整 flag 列表见 vmctl_prometheus_flags.md。InfluxDB v1 → VictoriaMetricsvmctl支持从 InfluxDB v1 迁移数据。指定 InfluxDB 地址--influx-addr、数据库--influx-database以及目标端--vm-addr./vmctl influx --influx-addrhttp://influx-addr:8086 \ --influx-databasebenchmark \ --vm-addrhttp://victoriametrics-addr:8428 InfluxDB import mode 2020/01/18 20:47:11 Exploring scheme for database benchmark 2020/01/18 20:47:11 fetching fields: command: show field keys; database: benchmark; retention: autogen 2020/01/18 20:47:11 found 10 fields 2020/01/18 20:47:11 fetching series: command: show series ; database: benchmark; retention: autogen Found 40000 timeseries to import. Continue? [Y/n] yInfluxDB 数据模型映射规则vmctl 在迁移 InfluxDB 数据时遵循以下映射规则Field 值映射为时序的指标值Tag按原样映射为 VictoriaMetrics 的 标签labels--influx-database会映射为db标签的值除非 InfluxDB 行中已存在db标签。可通过--influx-skip-database-label跳过该映射Field 名映射为时序名格式为{measurement}{separator}{field}其中{separator}默认为_可通过--influx-measurement-field-separator修改。例如InfluxDB 行foo,tag1value1,tag2value2 field112,field240在 VictoriaMetrics 中会被转换为foo_field1{tag1value1, tag2value2} 12 foo_field2{tag1value1, tag2value2} 40InfluxDB 迁移的过滤通过--influx-filter-series过滤时序例如./vmctl influx --influx-database benchmark \ --influx-filter-series on benchmark from cpu where hostnamehost_1703此时 vmctl 实际执行的系列发现查询为show series on benchmark from cpu where hostnamehost_1703按时间过滤使用--influx-filter-time-start--influx-filter-time-end例如只迁移某一天的数据./vmctl influx --influx-database benchmark \ --influx-filter-time-start 2020-01-01T10:07:00Z \ --influx-filter-time-end 2020-01-01T15:07:00ZInfluxDB 模式性能配置Influx 模式通过执行读查询来拉取数据迁移速度主要受限于 InfluxDB 响应查询的能力。默认每次只执行一个读请求可通过--influx-concurrency增加并发读请求数但要注意不要压垮 InfluxDB。--influx-chunk-size控制单个 fetch 请求返回的最大数据点数量用于控制 InfluxDB 内存占用避免处理包含数十亿数据点的大型时序时 OOM。关于 InfluxDB v2.x官方说明中 v2.x 的数据迁移尚未支持可关注相关第三方方案。InfluxDB 模式的完整 flag 列表见 vmctl_influx_flags.md。OpenTSDB → VictoriaMetricsopentsdb子命令从 OpenTSDB 拉取时序并写入 VictoriaMetrics支持通过--opentsdb-query-limit、--opentsdb-offset-days、--opentsdb-retentions、--opentsdb-filters等 flag 控制查询范围与过滤条件。从源码 app/vmctl/main.go 可以看到OpenTSDB 模式支持通过--opentsdb-cert-file、--opentsdb-key-file、--opentsdb-ca-file等配置 mTLS 传输并使用promauth.NewTLSTransport创建带 TLS 的 HTTP 客户端。详细说明见 docs/victoriametrics/vmctl/opentsdb.md。VictoriaMetrics → VictoriaMetrics原生模式 vm-native当简单的数据拷贝不可行例如单机版与集群版之间互迁、重新分片或数据需要修改时使用vmctl vm-native迁移。vmctl 通过 native 二进制协议 在 VictoriaMetrics 实例之间迁移数据支持以下路径单机版 → 单机版集群版 → 集群版单机版 → 集群版、集群版 → 单机版vm-native模式的迁移分为两步通过api/v1/label/__name__/valuesAPI 探索待迁移的指标列表按--vm-concurrency指定的并发度逐个迁移这些指标。基础示例./vmctl vm-native \ --vm-native-src-addrhttp://127.0.0.1:8481/select/0/prometheus \ # 从哪迁移 --vm-native-dst-addrhttp://localhost:8428 \ # 迁到哪 --vm-native-filter-time-start2022-11-20T00:00:00Z \ # 起始时间 --vm-native-filter-match{__name__!~vm_.*} # 只匹配不带 vm_ 前缀的指标 VictoriaMetrics Native import mode 2023/03/02 09:22:02 Initing import process from http://127.0.0.1:8481/select/0/prometheus/api/v1/export/native to http://localhost:8428/api/v1/import/native with filter filter: match[]{__name__!~vm_.*} start: 2022-11-20T00:00:00Z 2023/03/02 09:22:02 Exploring metrics... Found 9 metrics to import. Continue? [Y/n] 2023/03/02 09:22:04 Requests to make: 9 Requests to make: 9 / 9 [█████████████████████████████████████████████████████████████████████████████] 100.00% 2023/03/02 09:22:06 Import finished! 2023/03/02 09:22:06 VictoriaMetrics importer stats: time spent while importing: 3.632638875s; total bytes: 7.8 MB; bytes/s: 2.1 MB; requests: 9; requests retries: 0; 2023/03/02 09:22:06 Total time: 3.633127625s时间分片迁移通过--vm-native-step-interval可将迁移按时间拆分为多个步骤从而减少每个请求匹配的系列数量显著降低高基数high churn rate场景下源端的负载。支持的值month、week、day、hour、minute。例如迁移 1 年数据且--vm-native-step-intervalmonthvmctl 会从时间范围起点到终点执行 12 个独立请求要倒序迁移从最新到最旧则设置--vm-native-filter-time-reverse。使用--vm-native-step-interval时必须同时设置--vm-native-filter-time-start。官方建议迁移长周期数据时优先使用默认的month步长如果在--vm-native-src-addr侧命中查询限制且不便调整可尝试降低为week、day或hour。集群到集群迁移--vm-intercluster集群到集群模式可以在一次 vmctl 运行中迁移所有租户的数据。它通过/admin/tenants端点从源集群发现租户列表。使用方式./vmctl vm-native --vm-native-src-addrhttp://127.0.0.1:8481/ \ --vm-native-dst-addrhttp://127.0.0.1:8480/ \ --vm-native-filter-match{__name__vm_app_uptime_seconds} \ --vm-native-filter-time-start2023-02-01T00:00:00Z \ --vm-native-step-intervalday \ --vm-intercluster此时--vm-native-src-addr的格式为http://vmselect:8481/--vm-native-dst-addr的格式为http://vminsert:8480/。vmctl 会自动发现租户并逐个追加租户 ID 执行迁移日志中会依次出现tenant 0:0、tenant 1:0等。vm-native 模式的其他配置要点命中安全限制迁移大数据量时可能触发源端限制请确认源端-search.maxExportDuration、-search.maxExportSeries已设置合适值若报the number of matching timeseries exceeds...错误应调整过滤条件匹配更少的时序或在 vmselect/vmsingle 上调大-search.maxSeries。避免与应用指标混淆迁移全部指标时源端的进程指标vm_前缀可能与目标端自身指标冲突建议通过--vm-native-filter-match{__name__!~vm_.*}过滤掉 VM 进程指标。去重时间范围重叠或网络不稳定会产生重复序列可在目标端设置-dedup.minScrapeInterval1ms让 vmselect/vmstorage 忽略时间戳完全相同的重复数据。集群→单机从集群迁往单机时/api/v1/export/nativeAPI 会给每条时序附加vm_account_id、vm_project_id标签若不需要区分租户可设置--vm-native-disable-binary-protocol改用/api/v1/export的 JSON 导出/导入该模式支持去重但效率低于二进制协议。复制因子源集群若开启了复制-replicationFactor 1迁移到目标端并不会复制相同份数而只会产生重复数据此时需要在目标端开启-dedup.minScrapeInterval1ms去重并通过目标 vminsert 的-replicationFactor恢复复制因子。自定义请求头支持--vm-native-src-headers与--vm-native-dst-headers为源/目标端请求附加自定义 HTTP 头。长连接--vm-native-disable-http-keep-alive可让 vmctl 使用非持久化 HTTP 连接避免重型导出请求时的use of closed network connection错误。vm-native 模式的完整 flag 列表见 vmctl_vm-native_flags.md。通过 Prometheus remote read 协议迁移remote-read子命令面向所有支持 Prometheus remote read 协议的数据源包括 Thanos、Cortex、Mimir、Promscale 等。使用方式./vmctl remote-read \ --remote-read-src-addrsource-remote-read-url \ --vm-addrvictoriametrics-addr:8428从源码 app/vmctl/main.go 可以看到该模式的关键行为支持--remote-read-filter-time-start、--remote-read-filter-time-end时间过滤以及--remote-read-step-interval分块步长与--remote-read-filter-time-reverse倒序迁移支持标签过滤--remote-read-filter-label/--remote-read-filter-label-value默认过滤条件为__name__匹配.*全部指标支持--remote-read-use-stream流式读取、--remote-read-http-timeout超时与自定义--remote-read-headers支持对数据源配置 mTLS--remote-read-cert-file等与 basic auth。Thanos 除了 remote read 方式外还支持直接通过thanos子命令从 Thanos 存储块迁移支持原始数据与降采样数据见 thanos.mdCortex、Mimir、Promscale 的迁移文档分别见 cortex.md、mimir.md、promscale.md。验证 VictoriaMetrics 导出的数据块verify-blockverify-block模式用于校验从 VictoriaMetrics 以 native 格式 导出的数据块的正确性与完整性可在上传磁盘前先行校验。# 从 VictoriaMetrics 导出数据块 curl localhost:8428/api/v1/export/native -g -d match[]{__name__!} -o exported_data_block # 校验数据块内容 ./vmctl verify-block exported_data_block 2022/03/30 18:04:50 verifying block at pathexported_data_block 2022/03/30 18:04:50 successfully verified block at pathexported_data_block, blockCount123786 2022/03/30 18:04:50 Total time: 100.108ms从源码实现看app/vmctl/main.go 的verify-block命令该命令打开指定路径的文件通过lib/protoparser/native/stream包逐块解析 native 格式数据并统计 block 数量若解析失败会返回包含已解析块数量的错误信息。另外支持--gunzipflag 对 gzip 压缩的导出文件先解压再校验。文件路径参数缺失时会直接报错退出。迁移调优Importer stats、静默模式与数据压缩影响迁移速度的因素迁移速度主要取决于三个因素网络带宽vmctl 作为代理需要通过网络从 source 拉取数据并转发给 destinationsource 的性能source 返回请求数据的快慢destination 的性能destination 接收并存储数据的能力。导入速度可通过--vm-concurrency调整该 flag 控制并发处理数据的 worker 数量。注意每个 worker 在 VictoriaMetrics 侧最多可占满一个 vCPU 核心因此建议根据目标 VictoriaMetrics 实例分配的 CPU 资源来设置该值。迁移本质上是回填backfilling过程建议阅读仓库中关于 Backfilling 的建议同时 vmctl 本身不提供 relabeling 或其他标签管理能力这类需求应使用 VictoriaMetrics 自身的 relabeling 能力完成。Importer stats 关键指标解读导入完成后 vmctl 会打印统计信息重点关注的数字有idle durationimporter 等待 InfluxDB/Prometheus 数据填满--vm-batch-size批次所花费的时间值为所有--vm-concurrencyworker 的总和。该值过高可能说明 source 拉取太慢或--vm-concurrency设置过高可通过提高--mode-concurrency或降低--vm-concurrency来改善。import requests向 VictoriaMetrics 发起的导入请求数量。当批次大小--vm-batch-size填满后即发起一次导入请求建议使用较大的批次5 万50 万样本以提升性能。import requests retries失败的导入请求数量。非零值可能表示网络问题或 VictoriaMetrics 过载应结合导入期间的日志排查错误。从源码 app/vmctl/vm/stats.go 可以看到统计输出的完整字段idle duration、time spent while importing、total samples、samples/s、total bytes、bytes/s、import requests、import requests retries。其中idle duration的计算逻辑位于 app/vmctl/vm/vm.go 的startWorker中每个 worker 在收到第一条时序时记录起始时间直到批次攒满batchSize时把等待时间累加到idleDuration。静默模式与进度条默认情况下vmctl 在开始导入前会等待用户确认。若不需要交互可传-sflag 开启静默silence模式-disable-progress-barflag 可关闭导入期间的进度条。显著数字significant figures提升压缩率vmctl 允许在导入前限制数值的显著位数以提升数据压缩效果--vm-round-digits将处理后的值四舍五入到指定的小数位数。例如--vm-round-digits2会把1.2345变为1.23。默认关闭。--vm-significant-figures限制处理值的有效数字位数。默认 0保留所有有效数字设置为 5 时102.342305会被舍入为102.34。这两个 flag 最常见的用途是提升存储average、rate等聚合结果的时序数据的磁盘压缩率。从源码看舍入逻辑在 app/vmctl/vm/timeseries.go 的roundTimeseriesValue中实现会在 worker 攒批startWorker时对每条时序应用。为所有导入序列附加标签--vm-extra-label labelvalue可为所有导入的序列附加标签。需要多个标签时重复设置该 flag 即可--vm-extra-label label1value1 --vm-extra-label label2value2注意如果时序中已存在同名标签flag 具有更高优先级会覆盖时序中原有的标签值。速率限制通过--vm-rate-limit单位字节/秒限制数据传输速率有助于减轻目标磁盘或目标数据库的压力。注意速率限制是按 worker 生效的结合--vm-concurrency理解总吞吐。此外也可以使用 vmagent 作为 vmctl 与目标端之间的代理并在 vmagent 上启用-remoteWrite.rateLimit。从源码 app/vmctl/vm/vm.go 可以看到导入器通过limiter.NewLimiter(cfg.RateLimit)创建速率限制器数据发送前会经过该限制器控制流量。监控迁移过程vmctl 可以将内部指标推送push到远程存储用于监控迁移进度与性能该能力自 v1.135.0 起可用对长时间运行的迁移尤其有用可以跟踪进度、发现问题或构建仪表盘可视化迁移状态。以 VictoriaMetrics 作为指标接收端的示例./vmctl influx \ --influx-addrhttp://localhost:8086 \ --influx-databasemydb \ --vm-addrhttp://localhost:8428 \ --pushmetrics.urlhttp://localhost:8428/api/v1/import/prometheus \ --pushmetrics.extraLabeljobvmctl \ --pushmetrics.extraLabelinstancemigration-1推送间隔默认 10 秒可通过--pushmetrics.interval调整--pushmetrics.header可附加自定义 HTTP 头--pushmetrics.disableCompression可关闭推送时的压缩。可用指标通用指标所有迁移模式可用Metric说明vmctl_backoff_retries_total所有操作的重试总次数vmctl_limiter_bytes_processed_total经速率限制器处理的总字节数设置了--vm-rate-limit时vmctl_limiter_throttle_events_total速率限制导致暂停的次数模式专属指标模式名嵌入在指标名中模式指标influxvmctl_influx_migration_series_total、vmctl_influx_migration_series_processed、vmctl_influx_migration_errors_totalprometheusvmctl_prometheus_migration_blocks_total、vmctl_prometheus_migration_blocks_processed、vmctl_prometheus_migration_errors_totalopentsdbvmctl_opentsdb_migration_series_total、vmctl_opentsdb_migration_series_processed、vmctl_opentsdb_migration_errors_totalremote-readvmctl_remote_read_migration_ranges_total、vmctl_remote_read_migration_ranges_processed、vmctl_remote_read_migration_errors_totalvm-nativevmctl_vm_native_migration_metrics_total、vmctl_vm_native_migration_metrics_processed、vmctl_vm_native_migration_requests_planned、vmctl_vm_native_migration_requests_completed、vmctl_vm_native_migration_tenants_total、vmctl_vm_native_migration_tenants_processed、vmctl_vm_native_migration_bytes_transferred_total、vmctl_vm_native_migration_errors_total这些指标的定义可以在源码中找到对应位置例如 app/vmctl/backoff/backoff.go 中的vmctl_backoff_retries_total、app/vmctl/limiter/limiter.go 中的vmctl_limiter_bytes_processed_total与vmctl_limiter_throttle_events_total、app/vmctl/influx.go 中的vmctl_influx_migration_series_total等均通过metrics.NewCounter注册并由pushmetrics统一推送。示例 PromQL 查询# influx 模式迁移完成百分比 vmctl_influx_migration_series_processed / vmctl_influx_migration_series_total * 100 # vm-native 模式迁移完成百分比 vmctl_vm_native_migration_metrics_processed / vmctl_vm_native_migration_metrics_total * 100 # 重试速率 rate(vmctl_backoff_retries_total[5m]) # 速率限制导致的暂停事件每秒 rate(vmctl_limiter_throttle_events_total[5m]) # 数据传输速率字节/秒启用速率限制时 rate(vmctl_limiter_bytes_processed_total[5m]) # vm-native 模式数据传输速率MiB/秒 rate(vmctl_vm_native_migration_bytes_transferred_total[5m]) / 1Mi从源码理解 vmctl 的导入内核深入 app/vmctl/vm/vm.go 可以看到 vmctl 导入内核的关键设计批量导入vm.Config.BatchSize决定每个 worker 攒多少样本后发起一次导入请求默认值为1e510 万flag--vm-batch-size可覆盖默认 200000。并发与缓冲导入器按--vm-concurrency启动 worker输入通道缓冲为Concurrency*4错误通道缓冲为Concurrency见 app/vmctl/vm/vm.go 的NewImporter。指数退避重试导入请求失败时按--vm-backoff-retries默认 10、--vm-backoff-factor默认 1.8、--vm-backoff-min-duration默认 2s执行指数退避重试对应 app/vmctl/backoff/backoff.go 中的backoff.New。优雅关闭vmctl 监听 SIGINT/SIGTERM 信号收到后关闭导入器importer.Close()并取消上下文保证批量数据不丢失。指标自监控除迁移模式专属指标外导入器自身还暴露vmctl_importer_requests_total、vmctl_importer_request_errors_total、vmctl_importer_samples_total、vmctl_importer_bytes_total、vmctl_importer_request_duration_seconds等指标见 app/vmctl/vm/vm.go。如何构建 vmctl官方推荐直接使用二进制发布包vmctl位于vmutils-*压缩包中需要自行构建时可按如下方式操作。开发构建安装 Go在仓库根目录执行make vmctl构建vmctl二进制并放入bin目录。生产构建安装 Docker在仓库根目录执行make vmctl-prod构建vmctl-prod二进制并放入bin目录。构建 Docker 镜像在仓库根目录执行make package-vmctl构建victoriametrics/vmctl:PKG_TAG镜像。PKG_TAG为自动生成的镜像标签取决于仓库源码也可手动指定PKG_TAGfoobar make package-vmctl默认基础镜像为 alpine也可通过ROOT_IMAGE环境变量更换任意基础镜像例如基于 scratch 构建ROOT_IMAGEscratch make package-vmctlARM 构建ARM 构建适用于树莓派或低功耗 ARM 服务器开发构建make vmctl-linux-arm或make vmctl-linux-arm64产物分别为vmctl-linux-arm、vmctl-linux-arm64放入bin目录生产构建make vmctl-linux-arm-prod或make vmctl-linux-arm64-prod。仓库根目录的 Makefile 中定义了vmctl、vmctl-prod、vmctl-pure、package-vmctl以及各平台交叉编译目标linux-amd64/arm64/arm/386/ppc64le/s390x、darwin-amd64/arm64、freebsd-amd64、openbsd-amd64 等。命令行 flags 速查运行./vmctl mode --help可查看每个命令的完整 flag。全局 flag 与目标端通用 flag 如下节选自 vmctl_prometheus_flags.md各模式通用Flag默认值说明-sfalse静默模式不出现确认提示--verbosefalse日志输出是否详细--disable-progress-barfalse导入期间是否禁用进度条--pushmetrics.url—推送指标的 URL可多次设置--pushmetrics.interval10s指标推送间隔--pushmetrics.extraLabel—附加到推送指标的标签可多次设置--pushmetrics.header—推送时的附加 HTTP 头可多次设置--pushmetrics.disableCompressionfalse推送指标时是否禁用压缩--vm-addrhttp://localhost:8428VictoriaMetrics 导入地址单机为--httpListenAddr集群为 vminsert 地址导入前会检查/health端点--vm-user/--vm-password—目标端 basic auth环境变量$VM_USERNAME/$VM_PASSWORD--vm-headers—每次请求附加的 HTTP 头多个用^^分隔--vm-bearer-token—目标端 bearer token--vm-account-id—集群版必填的租户 ID32 位整数可写为accountID:projectID缺省 projectID 为 0--vm-concurrency2并发执行导入请求的 worker 数--vm-compresstrue导入请求是否启用 gzip 压缩--vm-batch-size200000攒够多少样本后发起一次导入请求--vm-significant-figures0保留的有效数字位数0 表示全部保留--vm-round-digits100小数点后保留位数用于舍入配合显著数字使用--vm-extra-label—附加到导入时序的标签可多次设置--vm-rate-limit0按 worker 的字节/秒速率限制0 表示不限制--vm-cert-file/--vm-key-file/--vm-CA-file/--vm-server-name/--vm-insecure-skip-verify—连接目标端的 TLS 配置--vm-backoff-retries10导入失败的最大重试次数--vm-backoff-factor1.8每次重试的基础等待时长倍增因子需大于 1.0--vm-backoff-min-duration2s首次重试前的最小等待时长总结vmctl 以子命令方式覆盖了当前主流监控系统到 VictoriaMetrics 的全部常见迁移路径Prometheus 快照迁移、InfluxDB v1 迁移、OpenTSDB 迁移、Thanos/Cortex/Mimir/Promscale 的 remote read 迁移、VictoriaMetrics 实例间的 native 二进制协议迁移以及 native 数据块的完整性校验。配合--vm-concurrency、--vm-batch-size、显著数字压缩、速率限制、pushmetrics 指标监控等调优手段可以针对不同规模的存量数据设计出可控、可观测、可断点续传的迁移方案。各模式的详细 flag 与边界场景如集群间租户迁移、高基数分片、去重与复制建议按需查阅仓库 docs/victoriametrics/vmctl 目录下的对应文档。【免费下载链接】VictoriaMetricsVictoriaMetrics: fast, cost-effective monitoring solution and time series database项目地址: https://gitcode.com/GitHub_Trending/vi/VictoriaMetrics创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →