一文看懂开源监控神器--prometheus部署教程,值得收藏

一文看懂开源监控神器--prometheus部署教程,值得收藏

游戏|数码彩彩2024-03-16 7:39:52300A+A-

概述

Prometheus支持多种语言(Go,JAVA,Python,ruby官方提供客户端,其他语言有第三方开源客户端)。我们可以通过客户端方面的对核心业务进行埋点。

Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。不需要任何SDK或者其他的集成过程。这样做非常适合做虚拟化环境监控系统,比如VM、Docker、Kubernetes等。输出被监控组件信息的HTTP接口被叫做exporter 。


部署思路:

1、安装Go语言环境

2、在监控服务器上安装prometheus

3、在被监控环境上安装export

4、安装grafana

5、安装alertmanager

以下基于centos7系统进行演示。


一、安装go语言环境

由于Prometheus 是用golang开发的,所以首先安装一个go环境,Go语言是跨平台,支持windows、linux、mac OS X等系统,还提供有源码,可编译安装。

下载地址:https://studygolang.com/dl

1、解压

# tar -xvf go1.13.linux-amd64.tar.gz -C /usr/local/
一文看懂开源监控神器--prometheus部署教程,值得收藏

 

2、配置环境变量

echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile
一文看懂开源监控神器--prometheus部署教程,值得收藏

 

3、测试

验证一下是否成功,用go version 来验证

# go version
一文看懂开源监控神器--prometheus部署教程,值得收藏

 


二、在监控服务器安装prometheus

1、开始安装prometheus

去官网下载对应系统的版本:https://prometheus.io/download/

下载地址:https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz

一文看懂开源监控神器--prometheus部署教程,值得收藏

 


一文看懂开源监控神器--prometheus部署教程,值得收藏

 

2、上传到监控服务器并解压

# tar -xvf prometheus-2.12.0.linux-amd64.tar.gz -C /usr/local/
# ln -sv /usr/local/prometheus-2.12.0.linux-amd64/ /usr/local/Prometheus
一文看懂开源监控神器--prometheus部署教程,值得收藏

 

3、监控端配置文件

prometheus.yml默认配置如下:

# my global config
global:
 scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
 evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
 # scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
 alertmanagers:
 - static_configs:
 - targets:
 # - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
 # - "first_rules.yml"
 # - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
 # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
 - job_name: 'prometheus'
 # metrics_path defaults to '/metrics'
 # scheme defaults to 'http'.
 static_configs:
 - targets: ['localhost:9090']

prometheus.yml 中的配置详解

  • <boolean>: 布尔值,true 或 false
  • <duration>: 持续时间,格式符合正则表达式 [0-9]+(ms|[smhdwy])
  • <labelname>: 标签名,格式符合正则表达式 [a-zA-Z_][a-zA-Z0-9_]*
  • <labelvalue>: 标签值,可以包含任意 unicode 字符
  • <filename>: 文件名,任意有效的文件路径
  • <host>: 主机,可以是主机名或 IP,后面可跟端口号
  • <path>: URL 路径
  • <scheme>: 协议,http 或 https
  • <string>: 字符串
  • <secret>: 密钥,比如密码
  • <tmpl_string>: 模板字符串,里面包含需要展开的变量

4、启动prometheus

./prometheus
一文看懂开源监控神器--prometheus部署教程,值得收藏

 

5、测试访问

访问地址:服务器IP:9090,点击Status-->targets 跳转到监控目标,红框的表示部署的prometheus

一文看懂开源监控神器--prometheus部署教程,值得收藏

 


一文看懂开源监控神器--prometheus部署教程,值得收藏
点击这里复制本文地址 版权声明:本文内容由网友提供,该文观点仅代表作者本人。本站(https://www.angyang.net.cn)仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

昂扬百科 © All Rights Reserved.  渝ICP备2023000803号-3网赚杂谈