Prometheus+Consul服务自动发现监控

木木2年前技术文章1250

为什么使用consul

prometheus作为新一代的监控利器,有很多优点,部署起来也十分方便。部署prometheus后自然会需要使用prometheus去监控物理机或者虚拟机的资源,这里就需要使用到node_exporter。同时根据prometheus的架构来看,server会主动从node上拉取数据。而我们每增加一个node,就要告诉prometheus需要到新的node上去拉去数据(更改prometheus配置),这个明显是不合理的,而且维护难度较高。所以这里引入consul来进行自动发现,降低维护难度。

prometheus-server部署

prometheus的部署很简单,二进制文件下载后直接执行即可。这里我们不使用二进制文件进行部署,改用docker进行部署。

sudo docker run -d --net=host -v /opt/prometheus/config:/etc/prometheus --name=prometheus prom/prometheus

这里net指定host是为了方便我们后续和consul进行配合使用。

访问地址

http://localhost:9090

consul部署

简介

Consul 是基于 GO 语言开发的开源工具,主要面向分布式,服务化的系统提供服务注册、服务发现和配置管理的功能。Consul 提供服务注册/发现、健康检查、Key/Value存储、多数据中心和分布式一致性保证等功能。之前我们通过 Prometheus 实现监控,当新增一个 Target 时,需要变更服务器上的配置文件,即使使用 file_sd_configs 配置,也需要登录服务器修改对应 Json 文件,会非常麻烦。不过 Prometheus 官方支持多种自动服务发现的类型,其中就支持 Consul。

部署

sudo docker run -d --name=consul --net=host -v /opt/consul/data:/consul/data -v /opt/consul/config:/consul/config consul

访问地址

http://172.16.0.2:8500

API 注册服务到 Consul

接下来,我们要注册服务到 Consul 中,可以通过其提供的 API 标准接口来添加。

注册服务

这里我们添加本机的node-exporter看下。api请求如下:

curl -X PUT -d '{
  "id": "prometheus",
  "name": "node-exporter",
  "address": "172.16.0.2",
  "port": 9100,
  "tags": ["prometheus"],
  "checks": [{"http": "http://172.16.0.2:9100/metrics", "interval": "30s"}]
}' http://localhost:8500/v1/agent/service/register

刷新页面后可以看到我们的node-exporter已经注册到consul了

删除服务

curl -X PUT http://localhost:8500/v1/agent/service/deregister/node-exporter


相关文章

PG的统计信息(三)

1.3 数据分布类统计信息1.3.1 pg_stats通过对pg_stats的查询,可以查看每个字段的数据分析统计信息,类似SQL Server的直方图,为优化器选择最佳执行计划提供依据,pg_sta...

LINUX 安全运维-用户

Linux提供了各种不同的用户和角色,而有些用户和角色,系统根本不需要,应该删除他们,因为帐号越多,系统就越不安全!黑客可能利用他们,威胁服务器的安全。删除不需要的用户:for i in {adm,l...

开源大数据集群部署(十一)Ranger 集成Hadoop集群

开源大数据集群部署(十一)Ranger 集成Hadoop集群

1、节点选择部署在两个namenode节点cd /opt/bigdatatar -xzvf ranger-2.3.0-hdfs-plugin.tar.gz -C /opt/cd /opt/ranger...

 大数据集群监控配置操作指导(三)Flink监控开启jmx

大数据集群监控配置操作指导(三)Flink监控开启jmx

官网的关于 flnk+prometheus的文章https://flink.apache.org/features/2019/03/11/prometheus-monitoring.htmlprome...

在K8S上使用Clickhouse

介绍clickhouse是一款开源的分析型数据库,性能强大。本文介绍如何在K8S环境中部署和使用clickhouse。我们使用开源的clickhouse operator: https://githu...

从Docker拉取镜像一直失败超时?这些解决方案帮你解决烦恼

设置国内源:提示:常规方案(作用不大)阿里云提供了镜像源:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 登录后你会获得一个专属...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。