第九讲:企业级监控数据采集方法

  第九讲内容如下

  1)prometheus服务端安装和后台稳定运行

  2)prometheus服务端配置文件写法

  3)node_exporter安装和后台运行

  4)node_exporter观察和采集数据

  5)prometheus查询采集回来的各种数据

  6) 使用我们之前学过的prometheus命令行的形式练习组合各种监控图

  (一)prometheus服务端的安装和后台稳定运行

  下载地址:https://github.com/prometheus/prometheus/releases/tag/v2.10.0

  解压

mv prometheus-2.10.0.linux-amd64.tar.gz /usr/local/
cd /usr/local/
tar -xf prometheus-2.10.0.linux-amd64.tar.gz
mv prometheus-2.10.0.linux-amd64 prometheus

   运行

cd prometheus
./prometheus 

   我们需要让prometheus_server 运⾏在后台 ⽽不是前端

  第一种方法安装screen

yum -y install screen

   使用screen启动

#进入screen
screen
#启动prometheus
./prometheus

   ctrl+a+d退出

  查看放入后台的进程

screen -ls

 

   screen还有另外⼀个好处 就是 可以随时切换进⼊ 程序前台窗 ⼜ 查看各种调试信息

screen -r

   screen 也有不好的地⽅  • 不够正规化 总觉得还是个临时办法

  • screen -l 提供的后台 列表 不够⼈性化,很多时候 你记不 住 到底哪个是哪个
  • 很容易被误关闭  操作的时候 ctrl +ad / ctrl +d 不⼩⼼操作 错了 直接就退出去了
  

  方法二

  使⽤daemonize 放⼊后台⽅式

  编译安装

git clone git://github.com/bmc/daemonize.git && cd daemonize
 ./configure && make && make install
daemonize -v

   指定运行启动脚本

# cat /usr/local/prometheus/up.sh 
/usr/local/prometheus/prometheus  --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9090"  --web.read-timeout=5m  --web.max-connections=10 --storage.tsdb.retention=15d --storage.tsdb.path="/usr/local/prometheus/data" --query.max-concurrency=20 --query.timeout=2m

   参数解释

–config.file=“prometheus.yml” 指定配置文件

–web.read-timeout=5m 请求链接的最大等待时间,防止太多的空闲链接占用资源

–web.max-connections=512 针对prometheus,获取数据源的时候,建立的网络链接数,做一个最大数字的限制,防止链接数过多造成资源过大的消耗

–storage.tsdb.retention=15d 重要参数,prometheus 开始采集监控数据后,会存在内存和硬盘中;对于保存期限的设置。时间过长,硬盘和内存都吃不消;时间太短,要查历史数据就没了。企业15天最为合适。

–storage.tsdb.path="/usr/local/prometheus/data" 存储数据路径,不要随便定义

–query.max-concurrency=20 用户查询最大并发数

–query.timeout=2m 慢查询强制终止

  设置up.sh执行权限

chmod +x /usr/local/prometheus/up.sh

  后台启动

daemonize -c /usr/local/prometheus /usr/local/prometheus/up.sh 

   查看进程是否启动

   放入开机自启动

# cat /etc/rc.local 
touch /var/lock/subsys/local
daemonize -c /usr/local/prometheus /usr/local/prometheus/up.sh 

   重启正常启动即可

猜你喜欢

转载自www.cnblogs.com/minseo/p/13370596.html