前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >基于prometheus+grafana的监控报警教程(一)安装prometheus和exporter

基于prometheus+grafana的监控报警教程(一)安装prometheus和exporter

作者头像
huolong
发布2024-03-20 17:29:57
1200
发布2024-03-20 17:29:57
举报
文章被收录于专栏:技术指北技术指北

随着现代组织日益复杂的技术堆栈和庞大的数据掌握需要,如何科学有效地监控和管理部署环境中的各种组件变得越来越重要。在这个背景下,Prometheus 出现了。

Prometheus 是一个开源的,具有丰富功能的监控与警报工具包,它于2012年由SoundCloud发起,其设计目标是实现一套在多维数据世界且可靠的监控系统,现在已经成为了云原生计算基金会的重要项目之一。Prometheus的设计理念非常符合今天分布式计算,微服务和云基础设施的需求,可以说是当下最主流的监控与警告系统之一。

今天我们就来介绍如何安装与使用 prometheus,在这之前还需要你对exporter有一个了解,如果你去访问 prometheus官网,就会发现很多exporter的字样。简单来说exporter就是采集监控数据的东西,它可以通过prometheus对外提供数据,并有一个统一的规范格式。官方实现了很多exporter,比如mysql exporter,node exporter等等。还有很多第三方实现的exporter,若感兴趣可以访问官网去了解。

简单来说,exporter就是一个给prometheus提供数据的组件

今天的教学内容都将基于docker搭建的方式,来监控本机的性能,若你不想采用docker部署,而是使用二进制文件在机器安装,可以参考我以前写的文章,地址如下:https://short.vwo50.club/og993 写的也是很详细的 ,接下来,正文开始

  1. 因为们要监控本机的性能数据,所以我们先试用docker安装好 node_exporter,这个exporter就是用来采集本机资源的exporter。执行命令 docker run -d -p 9100:9100 prom/node-exporter
  2. 将9100端口放开,然后前台访问 http://ip:9100/metrics 。当访问这个url时候,展示一堆以下格式的数据,则证明安装exporter成功。
代码语言:javascript
复制
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.21.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.553448e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 2.553448e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.445367e+06
# HELP go_memstats_frees_total Total number of frees.

接下来,部署prometheus,先创建一个prometheus的目录,执行命令 vim prometheus.yml 新建这个配置文件,配置文件里的内容可以填入以下信息:

代码语言:javascript
复制
global:
  scrape_interval:     60s
  evaluation_interval: 60s


scrape_configs:
  - job_name: prometheus   #这个用来监控本机的prometheus服务
 static_configs:
   - targets: ['localhost:9090']
     labels:
       instance: prometheus
 
  - job_name: linux     #这个用来监控本机的机器性能,填写你的node_exporter部署的机器的ip即可
 static_configs:
   - targets: ['你的ip:9100']
     labels:
       instance: localhost

我当前的路径是 /hustudy/prometheus/prometheus.yml 执行docker命令 docker run -d -p 9090:9090 -v /hustudy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus 来启动容器, 注意要将-v参数后的prometheus.yml文件路径替换成你自己的。

容器启动后prometheus会暴露在9090端口,然后我们前台访问 http://ip:9090 以及 前台访问http://ip:9090/targets 当页面出现以下内容时,则证明部署成功。

现在我们已经都部署好了,但是prometheus展示的数据并不友好,并不方便我们直观的查看,以及使用prometheus提供的Alertmanager告警组件有点复杂,所以在下一篇,我们将介绍数据可视化神器 grafana 以及它的告警。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024年03月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档