MySQL, Oracle, Linux, 软件架构及大数据技术知识分享平台

网站首页 > 精选文章 / 正文

Prometheus+Grafana 安装配置_prometheus+grafana构建应用监控(三)

2025-02-19 12:15 huorong 精选文章 3 ℃ 0 评论

一、Prometheus与Grafana

1、Prometheus简介

Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus纳入旗下第二大开源项目。Prometheus目前在开源社区相当活跃。Prometheus和Heapster(Heapster是K8S的一个子项目,用于获取集群的性能数据。)相比功能更完善、更全面。Prometheus性能也足够支撑上万台规模的集群。其架构图如下:



Prometheus Server, 负责从 Exporter 拉取和存储监控数据,并提供一套灵活的查询语言(PromQL)供用户使用。

Exporter, 负责收集目标对象(host, container…)的性能数据,并通过 HTTP 接口供 Prometheus Server 获取。

可视化组件,监控数据的可视化展现对于监控方案至关重要。以前 Prometheus 自己开发了一套工具,不过后来废弃了,因为开源社区出现了更为优秀的产品 Grafana。Grafana 能够与 Prometheus 无缝集成,提供完美的数据展示能力。

Alertmanager,用户可以定义基于监控数据的告警规则,规则会触发告警。一旦 Alermanager 收到告警,会通过预定义的方式发出告警通知。支持的方式包括 Email、PagerDuty、Webhook 等.


2、Grafana简介

Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下六大特点:


1、展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;

2、数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;

3、通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;

4、混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;

5、注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;

6、过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。


3、安装环境

接下来,讲述在CentOS7操作系统下,各个模块的安装过程。


二、服务端prometheus安装

1、下载解压

mkdir /usr/local/prometheus

cd /usr/local/prometheus

wget https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz

tar -xvf prometheus-2.25.0.linux-amd64.tar.gz

mv prometheus-2.25.0.linux-amd64 prometheus


2、创建用户

groupadd prometheus

useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus

chown prometheus.prometheus -R /usr/local/prometheus


3、创建Systemd服务,并修改默认端口

cat > /etc/systemd/system/prometheus.service <

[Unit]

[Unit]

Description=prometheus

After=network.target


[Service]

ExecStart=/usr/local/prometheus/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/prometheus/data--web.enable-admin-api --web.listen-address=:8090

Restart=on-failure


[Install]

WantedBy=multi-user.target

EOF


4、启动Prometheus

systemctl daemon-reload

systemctl enable prometheus

systemctl start prometheus

systemctl status prometheus


5、 浏览器访问

http://IP:8090

# 没有安装node时状态是down,此处是安装node状态后


6、 添加node机器状态监控

我们尝试添加第一个监控exporter——监控当前机器自身的状态,包括硬盘、CPU、流量等。因为Prometheus已经有了很多现成的常用exporter,所以我们直接用其中的node_exporter。注意了,这里名字虽然叫node_exporter,但跟nodejs没有任何关系,在Prometheus看来,一台机器或者说一个节点就是一个node,所以该exporter是在上报当前节点的状态。


node_exporter本身也是一个http服务,可以供prometheus server调用(pull)来获取监控的信息,安装方法同样是下载安装包后解压直接运行:


cd /usr/local/prometheus

wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz


tar -xvf node_exporter-1.1.1.linux-amd64.tar.gz

mv node_exporter-1.1.1.linux-amd64 node_exporter


7、 添加node为系统启动服务并修改端口为8100

cat > /etc/systemd/system/node_exporter.service <

[Unit]

Description=node_exporter

After=network.target


[Service]

ExecStart=/usr/local/prometheus/node_exporter/node_exporter --web.listen-address=:8100

Restart=on-failure


[Install]

WantedBy=multi-user.target

EOF


systemctl daemon-reload

systemctl enable node_exporter

systemctl start node_exporter

systemctl status node_exporter


8、修改prometheus配置文件并重启服务

vim /usr/local/prometheus/prometheus/prometheus.yml


systemctl restart promentheus



三、安装Grafana

因为Prometheus的界面看起来非常简单,所以我们还需要Grafana这个非常强大也是最常用的监控展示框架。


cd /usr/local/prometheus/

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-7.4.3-1.x86_64.rpm

yum localinstall
grafana-7.4.3-1.x86_64.rpm -y # 会把依赖包一起安装


systemctl start grafana-server

systemctl enable grafana-server

systemctl status grafana-server


通过systemctl status grafana-server信息可以看到Grafana默认运行在3000端口,

在Grafana展示监控信息安装并启动Grafana后,浏览器输入 IP:3000 来访问Grafana,管理员账号密码默认是admin/admin。首次登陆会让你修改管理员密码,然后就可以登录查看了。


四、添加数据展示




# 点击save并保存


五、导入dashboard




#页面展示




五、更多节点安装node

ansible all -m shell -a "mkdir -p /usr/local/prometheus"

ansible all -m copy -a "src=/usr/local/prometheus/ dest=/usr/local/prometheus/"

ansible all -m copy -a "src=/etc/systemd/system/node_exporter.service dest=/etc/systemd/system/"

ansible all -m shell -a "chmod +x /usr/local/prometheus/node_exporter/node_exporter"

ansible all -m shell -a "systemctl daemon-reload ;systemctl enable node_exporter ;systemctl start node_exporter;systemctl status node_exporter"


五、添加到服务器展示

vim /usr/local/prometheus/prometheus/prometheus.yml


#展示效果


看完请点个和关注,继续努力发更多信息知识,谢谢

Tags:grafana安装

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言