Prometheus源码学习(1) 编译源码

代码里面看不明白的变量或者函数可以通过两种方式观测它的值来了解其含义

  • 一种是把代码片段摘出来,写到一个测试程序里运行一下
  • 另一种时日志里打印它的值来观察

第一种比较简单易行,但是代码片段要比较独立才好做,第二种要修改源码重新编译,可以在整个源码上下文中观测,但是需要编码源码,相对麻烦一些,研究源码早晚也要编译,所以先总结一下编译 Prometheus 源码的步骤。

编译 Prometheus 源码需要 node.js 和 yarn。我是在 WSL2 上编译的。

  1. 安装 node.js
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

$ sudo apt-get install -y nodejs
  1. 安装 gcc
sudo apt-get install gcc g++ make
  1. 安装 yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
  1. 编译源码
# 避免报错 [email protected]: The platform "linux" is incompatible with this module.
yarn config set ignore-engines true
make build

耗时比较长,10分钟以上。

猜你喜欢

转载自blog.csdn.net/qq_35753140/article/details/112852808