一、Prometheus是什么?

监控:数据采集,数据存储,数据分析,数据展示,数据告警。

Prometheus本质上是一个度量数据的收集和分析工具,包含3个核心组件:

● 时间序列数据库,用于保存所有度量数据。

● 数据收集器,负责从外部来源拉取指标并将其推入数据库。

● Web服务器,为配置和查询存储的数据提供简单的Web界面。

 

二、Prometheus的优势:

配置灵活;

监控多样性;

高效的存储;

 

三、Prometheus的架构:

 

prometheus的获取当前时间的函数 prometheus数据采集_服务器

  说明:

PromSQL,是用于从Prometheus中检索指标的查询语言。

AlertManager(告警管理),允许我们根据Prometheus采样的指标定义告警(比如内存/ CPU使用率过高或请求时延达到峰值)。

Pushgateway(推送网关),允许应用和服务将指标推送到Prometheus,而非标准的由Prometheus主动拉取。

Service discocery(服务发现),Prometheus在一开始就被设计为只需极少配置即可完成初始安装,以及适于在诸如Kubernetes之类的动态环境中运行。因此它可以对正在运行的服务进行自动发现,并尝试对其应监视的内容作出最佳的猜测。

 

四、prometheus安装

从https://prometheus.io/download/下载相应版本,官网提供的是二进制版,解压就能用,不需要编译。

上传prometheus包,并解压

tar -zxvf prometheus-2.35.0.linux-amd64.tar.gz

mv prometheus-2.35.0.linux-amd64 /usr/local/prometheus

cd /usr/local/prometheus/

#启动

./prometheus &

 

prometheus的获取当前时间的函数 prometheus数据采集_配置文件_02

#查看相关进程及端口

ps -ef |grep prometheus

ss -anltp |grep 9090

netstat -nltp |grep prometheus

浏览器访问验证Prometheus,直接输入服务器IP:9090即可。

 

prometheus的获取当前时间的函数 prometheus数据采集_配置文件_03

 >>>prometheus部署非常简单,无需做任何配置即可轻松部署。

查看监控目标,Status-->Targets,默认只监控本机。

prometheus的获取当前时间的函数 prometheus数据采集_配置文件_04

 

五、监控远程主机

监控远程主机需要下载并安装node_exporter组件服务,安装也特别简单,将node_exporter组件安装包上传至要被监控的服务器上,解压后里面就一个启动程序node_exporter,可以直接启动,node_exporter默认端口9100。

tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz -C /usr/local/

cd /usr/local/

mv node_exporter-1.3.1.linux-amd64/  node_exporter

nohup /usr/local/node_exporter/node_exporter &

#查看进程及端口

ps -ef |grep node_exporter

netstat -nltp |grep 9100

prometheus的获取当前时间的函数 prometheus数据采集_配置文件_05

 

通过浏览器访问 http://被监控端IP:9100/metrics 就可以查看到

 

回到Prometheus服务器的配置文件里添加被监控机器的配置段。在主配置文件最后加上下面三行。

vim /usr/local/prometheus/prometheus.yml

 

- job_name: 'node1'       # 取一个job名称来代表被监控的机器

static_configs:

- targets: ['10.226.1.2:9100']       # 这里改成被监控机器的IP,后面端口接9100

 

prometheus的获取当前时间的函数 prometheus数据采集_数据_06

 

改完配置文件并保存后,重启prometheus服务。

ps -ef |grep prometheus

kill -9 <进程ID>

nohup /usr/local/prometheus/prometheus &

#启动方式还可以追加指定默认配置文件

/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

 

回到prometheus Web管理界面 --》点Status --》点Targets --》可以看到多了一台监 控目标。

prometheus的获取当前时间的函数 prometheus数据采集_配置文件_07

 

 

---