macOS ◆ xterm-256color ◆ zsh 12200 views

# 首先,检查 Prometheus 和 TSDB 是否正常运行
./prometheus --version
curl http://localhost:8242/api/version

# 确认版本是否支持
# Prometheus 只保证 2.9.x 是兼容的
# TSDB 只保证 2.4.x 及以上版本是兼容的

# 配置任务
cd /tmp/datax
cp datax/job/job.json prometheus2tsdb.json

{
  "job": {
    "content": [
      {
        "reader": {
          "name": "prometheusreader",
          "parameter": {
            "endpoint": "http://localhost:9090",
            "column": [
              "up"
            ],
            "beginDateTime": "2019-05-20T16:00:00Z",
            "endDateTime": "2019-05-20T16:00:10Z"
          }
        },
        "writer": {
          "name": "tsdbwriter",
          "parameter": {
            "endpoint": "http://localhost:8242"
          }
        }
      }
    ],
    "setting": {
      "speed": {
        "channel": 1
      }
    }
  }
}

# 启动之前,确认 Prometheus 存在数据,而 TSDB 不存在数据
# Prometheus
curl -s 'http://localhost:9090/api/v1/query_range?query=up&start=2019-05-20T08:00:00.000Z&end=2019-05-20T08:00:10.000Z&step=1ms'

# TSDB
curl -X POST -H "Content-Type: application/json" localhost:8242/api/query -d '{"start":1558339200,"end":1558339210,"queries":[{"aggregator":"count","metric":"up"}]}'


# 通过 datax.py 脚本启动任务
python datax/bin/datax.py prometheus2tsdb.json
# 任务已完成
# 现在,我们来检查是否写入成功
# Prometheus
curl -s 'http://localhost:9090/api/v1/query_range?query=up&start=2019-05-20T07:15:00.000Z&end=2019-05-20T07:15:10.000Z&step=1ms'
# TSDB
curl -X POST -H "Content-Type: application/json" localhost:8242/api/query -d '{"start":1558307700,"end":1558307710,"queries":[{"aggregator":"count","metric":"up"}]}'

# 恭喜!
# 数据已成功迁移!