记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率

个人博客:记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率-风屿岛 (biliwind.com)

如果您使用1Panel,Grafana和Prometheus都是有1Panel的一键版本的,但使用1Panel应用的方法未经测试

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第1张图片

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第2张图片

如果你希望使用1Panel,可以在购买服务器时选择预装

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第3张图片

上图为雨云的预装示例,某些服务商可能不支持预装,请看 在线安装 – 1Panel 文档

本文以家里云+centos做演示

准备工作

首先准备好软件环境

    1. node_exporter

    1. prometheus

    1. grafana

这些是必备的

安装工作

首先我们安装node_exporter
node_exporter的作用是用于机器系统数据收集。

官网下载包
 

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第4张图片


官网包下载

利用Linux命令下载安装


wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.0/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz #下载node_exporter包

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第5张图片


tar xvf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz #解压下载来的包

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第6张图片


mv node_exporter-1.0.0-rc.0.linux-amd64 node_exporter #把解压的目录改成node_exporter

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第7张图片


cd node_exporter #进入node_exporter目录

进入node_exporter目录


./node_exporter #运行node_exporter

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第8张图片

看到这图片代码安装运行成功了

访问 http://localhost:9100/metrics

接下来安装prometheus
Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。

官网下载包
 

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第9张图片


官网包下载

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第10张图片

利用Linux命令下载安装


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

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第11张图片


tar xvf prometheus-2.16.0.linux-amd64.tar.gz #解压下载来的包

解压包


mv prometheus-2.16.0.linux-amd64.tar.gz prometheus#把解压的目录改成prometheus

目录改成prometheus


cd prometheus #进入prometheus目录

进入prometheus目录

这里我们要注意修改prometheus的配置文件

利用vim在prometheus.yml文件scrape_configs下添加


- job_name: 'node'

static_configs:

- targets: ['localhost:9100']

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第12张图片

这里监听node_exporter的数据
最后我们启动prometheus服务


./prometheus #启动prometheus服务

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第13张图片

访问 http://47.103.87.205:9090/graph
搜索up出现以下图片代表运行成功数据监听成功
如果


up{instance="localhost:9090",job="prometheus"} 0

up{instance="localhost:9100",job="node"} 0

代表数据没监听到

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第14张图片

最后我们安装grafana


wget https://dl.grafana.com/oss/release/grafana-6.6.2-1.x86_64.rpm

sudo yum localinstall grafana-6.6.2-1.x86_64.rpm

其他服务器看官网
地址 https://grafana.com/grafana/download?platform=linux


sudo systemctl start grafana-server #启动grafana

启动grafana

访问 http://localhost:3000/login
默认账号密码是 admin

添加prometheus数据源

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第15张图片

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第16张图片

添加Dashboards

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第17张图片

这里我们点Import 导入Dashboards

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第18张图片

输入官方下载的Dashboards json文件或者Dashboards的ID获取

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第19张图片

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第20张图片

查看一下效果

记录一次Linux利用grafana+prometheus搭建可视化展示资源使用率_第21张图片

完工

你可能感兴趣的:(linux,grafana,prometheus)