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系统进行演示。
由于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/
2、配置环境变量
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile source /etc/profile
3、测试
验证一下是否成功,用go version 来验证
# go version
1、开始安装prometheus
去官网下载对应系统的版本:https://prometheus.io/download/
下载地址:https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz
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
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 中的配置详解
4、启动prometheus
./prometheus
5、测试访问
访问地址:服务器IP:9090,点击Status-->targets 跳转到监控目标,红框的表示部署的prometheus