https://blog.51cto.com/lee90/2062252node
联邦有不一样的用例。它一般用于实现可扩展的prometheus,或者将metrics从一个服务的prometheus拉到另外一个Prometheus上用于展现。mysql
分层联邦:web
分层联邦容许普罗米修斯扩展到数十个数据中心和数百万个节点的环境。在这种用例中,联邦拓扑相似于一棵树,更高级别的普罗米修斯服务器从大量的从属服务器收集汇总的时间序列数据。sql
跨服务联邦:json
In cross-service federation, a Prometheus server of one service is configured to scrape selected data from another service's Prometheus server to enable alerting and queries against both datasets within a single server.后端
在跨服务联合中,一个服务的普罗米修斯服务器被配置为从另外一个服务的普罗米修斯服务器中刮取选定的数据,以使得可以针对单个服务器内的两个数据集进行警报和查询。api
For example, a cluster scheduler running multiple services might expose resource usage information (like memory and CPU usage) about service instances running on the cluster. On the other hand, a service running on that cluster will only expose application-specific service metrics. Often, these two sets of metrics are scraped by separate Prometheus servers. Using federation, the Prometheus server containing service-level metrics may pull in the cluster resource usage metrics about its specific service from the cluster Prometheus, so that both sets of metrics can be used within that server.浏览器
例如,运行多个服务的集群调度程序可能会暴露有关在集群上运行的服务实例的资源使用状况信息(如内存和CPU使用状况)。另外一方面,在该群集上运行的服务将仅公开特定于应用程序的服务度量标准。一般,这两套指标是由单独的普罗米修斯服务器来抓取的。使用联邦,包含服务级别度量的普罗米修斯服务器能够从集群普罗米修斯拉入有关其特定服务的集群资源使用度量,以便这两组度量能够在该服务器内使用。bash
【举个例子:咱们要监控mysqld的运行状态,可使用1个主Prometheus+2个分片Prometheus(一个用来采集node_exporter的metrics、一个用来采集mysql_exporter的metrics),而后在主Prometheus上作汇总】服务器
安装prometheus和mysqld_exporter、postgres_exporter的步骤也不写了,很简单的,exporter的部署咱们一般用ansible或saltstack之类的工具批量分发。
我这里实验起见,在一台机器上跑了3个shard节点,1个global节点。
Node1: 10.0.20.25 (跑了老版本的prometheus1.七、mysql_exporter、postgres_exporter,这是以前作实验搭建的环境)
Node2: 10.0.20.26 (跑了prometheus2.0、mysql_exporter、postgres_exporter)
下面开始在Node2上开始咱们的联邦的配置吧。
注意: 我这里作实验的时候,跨服务联邦的配置还不太规范,照官方的说法是 采用多个独立的Prometheus节点分别采集node_exporter、mysql_exporter、postgres_exporter 这些metrics,而后再在GLOBAL节点作汇总。
cd /usr/local/prometheus
编写存放要采集主机的文件:
cat mysqld.json
cat pgsql.json
3个Shard节点配置文件以下:
节点1,搜集的是mysql的信息
cat prometheus1.yml
global:
节点2,搜集的是pgsql的信息
cat prometheus2.yml
节点3,搜集的是prometheus节点的信息
cat prometheus3.yml
而后,启动3个分片节点:
再来配置GLOBAL节点:
cat prometheus.yml 内容以下:
启动GLOBAL节点:
配好后,整个目录 以下图:
而后,在浏览器访问http://10.0.20.26:9090/targets 这个GLOBAL节点,效果以下图:
能够访问原先的3个shard节点,获取到对应的mysql、pgsql、prometheus的采集信息:
咱们能够自测下,在http://10.0.20.26:9090/graph 这里能够采集到后端3个shard节点的所有数据的。
这样,咱们就配好了prometheus的联邦啦。是否是很简单??
注意: 有些时候 ,咱们要求告警信息实时性特别高,这种状况下,告警的采集(以granfana为例)不建议使用链接到联邦GLOBAL节点的方式,建议直连后端对应的Shard节点,以避免由于GLOBAL采集数据延迟,而致使发送告警的延迟状况出现。
结合grafana:
而后,能够在grafana里面作展现了,直接上图:
这里填instance 的时候,我用了个通配符,一次性列出符合条件的所有主机,可是惟一的缺点是,这样就不能用grafana自带的告警啦,由于目前grafana的告警还不支持动态写法,除非咱们写死了node_load5{instance=~'10.0.20.26:9100'} 这样才行。
下面是我配好的部分截图: