基于Prometheus+Grafana的应用监控系统建设(二)

本文涉及的产品
可观测监控 Prometheus 版,每月50GB免费额度
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 基于Prometheus+Grafana的应用监控系统建设安装与初始化第一个Dashboard

Prometheus + Grafana 应用级监控方案(2)-安装及初始化


概述

在监控系统建设过程中,建议能使用Docker部署的服务,尽量用Docker部署,包括监控系统本身(Prometheus/Grafana/InfluxDB)及众多的采集器(export)。其带来的好处:

  • 便利性:无需复杂的编译、安装过程,即下即用,支持离线安装
  • 安全性:虚拟化后与宿主机及其它容器隔离
  • 移植性:不同的Linux发行版、Windows跨系统基本无影响
  • 持续集成: 为后续的持续集成、自动化部署带来较多的方便之处

注:本文以CentOS 7 为基础环境安装

Docker安装参考

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum install docker-ce -y
sudo systemctl start docker
sudo docker info

Prometheus 安装参考

docker pull prom/prometheus
mkdir -p /data/docker-lv/prometheus/etc
mkdir -p /data/docker-lv/prometheus/data
docker run --name tmp-prometheus --rm  prom/prometheus 
#开一个新窗口,提取文件,其中配置与数据为宿主机映射
docker cp tmp-prometheus:/etc/prometheus/prometheus.yml /data/docker-lv/prometheus/etc/.
#中止tmp-prometheus(ctrl+C)
docker run -d --name prometheus \
       -p 9090:9090 \
       -v /data/docker-lv/prometheus/etc:/etc/prometheus/ \
       -v /data/docker-lv/prometheus/data:/prometheus-data \
       prom/prometheus
#查看启动日志
docker logs prometheus     

#浏览器打开
 http://host:9090

Grafana 安装参考

docker pull grafana/grafana
mkdir -p /data/docker-lv/grafana/data
mkdir -p /data/docker-lv/grafana/etc
#chmod 777 /data/docker-lv/grafana/data
chown 472:472 /data/docker-lv/grafana/*
docker run --name tmp-grafana --rm  grafana/grafana
#开一个新窗口,提取文件,其中配置与数据为宿主机映射
docker cp tmp-grafana:/etc/grafana/grafana.ini /data/docker-lv/grafana/etc/.
chown 472:472 -R /data/docker-lv/grafana/*
#中止tmp-prometheus(ctrl+C)
docker run -d --name=grafana \
           -p 3000:3000 \
           -v /data/docker-lv/grafana/etc/grafana.ini:/etc/grafana/grafana.ini \
           -v /data/docker-lv/grafana/data:/var/lib/grafana \
           grafana/grafana
#查看启动日志
docker logs grafana   
#浏览器打开
 http://host:3000
 admin/admin

Grafana 第一个Dashboard

  • 新建数据源,类型为 Prometheus, 地址为 http://xxx.xxx.x.xx:9090
  • 新建Dashboard,Prometheus已有数据,可用其制作图表
  • 以下为样例Dashboard, 菜单 --> + --> Import --> JSON 粘贴以下JSON字符串
{"annotations":{"list":[{"builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","type":"dashboard"}]},"editable":true,"gnetId":null,"graphTooltip":0,"id":1,"links":[],"panels":[{"cacheTimeout":null,"colorBackground":false,"colorValue":false,"colors":["#299c46","rgba(237, 129, 40, 0.89)","#d44a3a"],"datasource":"Prometheus","decimals":2,"format":"s","gauge":{"maxValue":100,"minValue":0,"show":false,"thresholdLabels":false,"thresholdMarkers":true},"gridPos":{"h":2,"w":6,"x":0,"y":0},"id":4,"interval":null,"links":[],"mappingType":1,"mappingTypes":[{"name":"value to text","value":1},{"name":"range to text","value":2}],"maxDataPoints":100,"nullPointMode":"connected","nullText":null,"options":{},"postfix":"","postfixFontSize":"50%","prefix":"","prefixFontSize":"50%","rangeMaps":[{"from":"null","text":"N/A","to":"null"}],"sparkline":{"fillColor":"rgba(31, 118, 189, 0.18)","full":false,"lineColor":"rgb(31, 120, 193)","show":false,"ymax":null,"ymin":null},"tableColumn":"","targets":[{"expr":"time() - process_start_time_seconds","refId":"A"}],"thresholds":"","timeFrom":null,"timeShift":null,"title":"运行时间","type":"singlestat","valueFontSize":"80%","valueMaps":[{"op":"=","text":"N/A","value":"null"}],"valueName":"avg"},{"cacheTimeout":null,"colorBackground":false,"colorPostfix":false,"colorValue":false,"colors":["#299c46","rgba(237, 129, 40, 0.89)","#d44a3a"],"datasource":"Prometheus","format":"decbytes","gauge":{"maxValue":100,"minValue":0,"show":false,"thresholdLabels":false,"thresholdMarkers":true},"gridPos":{"h":2,"w":5,"x":6,"y":0},"id":6,"interval":null,"links":[],"mappingType":1,"mappingTypes":[{"name":"value to text","value":1},{"name":"range to text","value":2}],"maxDataPoints":100,"nullPointMode":"connected","nullText":null,"options":{},"postfix":"","postfixFontSize":"50%","prefix":"","prefixFontSize":"50%","rangeMaps":[{"from":"null","text":"N/A","to":"null"}],"sparkline":{"fillColor":"rgba(31, 118, 189, 0.18)","full":false,"lineColor":"rgb(31, 120, 193)","show":true,"ymax":null,"ymin":null},"tableColumn":"","targets":[{"expr":"process_resident_memory_bytes","refId":"A"}],"thresholds":"","timeFrom":null,"timeShift":null,"title":"内存使用","type":"singlestat","valueFontSize":"80%","valueMaps":[{"op":"=","text":"N/A","value":"null"}],"valueName":"avg"},{"aliasColors":{},"bars":false,"dashLength":10,"dashes":false,"datasource":"Prometheus","decimals":0,"fill":1,"fillGradient":0,"gridPos":{"h":7,"w":24,"x":0,"y":2},"hiddenSeries":false,"id":2,"legend":{"alignAsTable":true,"avg":false,"current":true,"max":true,"min":false,"rightSide":true,"show":true,"total":false,"values":true},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"dataLinks":[]},"percentage":false,"pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"go_goroutines","legendFormat":"{{instance}}","refId":"A"}],"thresholds":[],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"协程数","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true},{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null}}],"schemaVersion":21,"style":"dark","tags":[],"templating":{"list":[]},"time":{"from":"now-6h","to":"now"},"timepicker":{},"timezone":"","title":"prometheus-view","uid":"HbfbwzBWk","version":5}
  • 显示效果如下图所示

小结

  • Prometheus + Grafana 安装&使用都比较方便,很快可以搭建一个看上去还不错的运行界面
  • 上手很快,无需编码
  • 下一节介绍一个典型的应用监控实现过程- Prometheus+Grafana+Redis监控
相关实践学习
通过可观测可视化Grafana版进行数据可视化展示与分析
使用可观测可视化Grafana版进行数据可视化展示与分析。
相关文章
|
20天前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
108 3
|
21天前
|
Prometheus 监控 Cloud Native
基于Docker安装Grafana和Prometheus
Grafana 是一款用 Go 语言开发的开源数据可视化工具,支持数据监控和统计,并具备告警功能。通过 Docker 部署 Grafana 和 Prometheus,可实现系统数据的采集、展示和告警。默认登录用户名和密码均为 admin。配置 Prometheus 数据源后,可导入主机监控模板(ID 8919)进行数据展示。
59 2
|
19天前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第27天】在智能运维中,Prometheus和Grafana的组合已成为监控和告警体系的事实标准。Prometheus负责数据收集和存储,支持灵活的查询语言PromQL;Grafana提供数据的可视化展示和告警功能。本文介绍如何配置Prometheus监控目标、Grafana数据源及告警规则,帮助运维团队实时监控系统状态,确保稳定性和可靠性。
93 0
|
2月前
|
存储 Prometheus 监控
在Ubuntu系统上安装与配置Prometheus的步骤
通过以上步骤,您应该已经成功在Ubuntu系统上安装并配置了Prometheus。您现在可以开始使用Prometheus收集和分析您的系统和应用程序的指标数据了。
178 1
|
3月前
|
Prometheus 监控 Cloud Native
自定义grafana_table(数据源Prometheus)
综上所述,自定义 Grafana 表格并将 Prometheus 作为数据源的关键是理解 PromQL 的查询机制、熟悉 Grafana 面板的配置选项,并利用 Grafana 强大的转换和自定义功能使数据展示更为直观和有洞见性。随着对这些工具更深入的了解,您将可以创建出更高级的监控仪表盘,以支持复杂的业务监控需求。
285 1
|
5月前
|
Prometheus 监控 Cloud Native
基于Prometheus和Grafana的监控平台 - 环境搭建
基于Prometheus和Grafana的监控平台 - 环境搭建
|
3月前
|
Prometheus 监控 Cloud Native
prometheus学习笔记之Grafana安装与配置
prometheus学习笔记之Grafana安装与配置
|
3月前
|
存储 Prometheus 监控
Grafana 与 Prometheus 集成:打造高效监控系统
【8月更文第29天】在现代软件开发和运维领域,监控系统已成为不可或缺的一部分。Prometheus 和 Grafana 作为两个非常流行且互补的开源工具,可以协同工作来构建强大的实时监控解决方案。Prometheus 负责收集和存储时间序列数据,而 Grafana 则提供直观的数据可视化功能。本文将详细介绍如何集成这两个工具,构建一个高效、灵活的监控系统。
410 1
|
3月前
|
Prometheus 监控 Cloud Native
Spring Boot 性能护航!Prometheus、Grafana、ELK 组合拳,点燃数字化时代应用稳定之火
【8月更文挑战第29天】在现代软件开发中,保证应用性能与稳定至关重要。Spring Boot 作为流行的 Java 框架,结合 Prometheus、Grafana 和 ELK 可显著提升监控与分析能力。Prometheus 负责收集时间序列数据,Grafana 将数据可视化,而 ELK (Elasticsearch、Logstash、Kibana)则管理并分析应用日志。通过具体实例演示了如何在 Spring Boot 应用中集成这些工具:配置 Prometheus 获取度量信息、Grafana 显示结果及 ELK 分析日志,从而帮助开发者快速定位问题,确保应用稳定高效运行。
108 1
|
3月前
|
Prometheus Kubernetes 监控
Kubernetes(K8S) 监控 Prometheus + Grafana
Kubernetes(K8S) 监控 Prometheus + Grafana
259 2
下一篇
无影云桌面