grafana安装部署、自定义主题、dashboard模板导入

介绍

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

官网地址:

它主要有以下六大特点:

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

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

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

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

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

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

安装

grafana官方下载地址:https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1

可以根据自己的服务器的类型选择对应的grafana进行安装,本文介绍Linux CentOS环境v7.5.11版本的安装、部署、配置。

# 下载
[root@localhost ~]# wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.5.11-1.x86_64.rpm
# 安装
[root@localhost ~]# yum install grafana-enterprise-7.5.11-1.x86_64.rpm
# 启动
[root@localhost ~]# systemctl start grafana-server
# 检查grafana是否启动成功,grafana启动时会占用3000端口
[root@localhost ~]# lsof -i:3000
# 重启
[root@localhost ~]# systemctl restart grafana-server

访问

grafana部署成功时,可以http访问,ip就是grafana服务的服务器host

登录地址:http://ip:3000/

账号:admin/admin

如果检查端口3000已经在不能访问,检查服务器防火墙

# centos7查看防火墙状态
[root@localhost ~]# systemctl status firewalld
# 临时关闭防火墙
[root@localhost ~]# systemctl stop firewalld
# 永久关闭防火墙
[root@localhost ~]# systemctl disable firewalld

配置

grafana 安装成功后,会在/etc/grafana目录生成配置文件grafana.ini

[root@localhost ~]# cd /etc/grafana

1.如果需要开启匿名访问,需要修改如下参数

[root@localhost ~]# vim /etc/grafana/grafana.ini
# 开启匿名访问
enabled = true
# 给匿名访问者一个组织
org_name = Main Org.
#给匿名访问者一个访问权限,Viewer表示浏览权限,Editor编辑权限,Admin管理员权限
org_role = Viewer

2.如果需要开放浏览器iframe嵌套grafana页面设置,需修改如下参数

[root@localhost ~]# vim /etc/grafana/grafana.ini
# 允许浏览器渲染grafana到iframe
allow_embedding = true

修改了配置之后需要重启grafana

[root@localhost grafana]# systemctl restart grafana-server

3.隐藏grafana左侧菜单和顶部面包屑

只要在url后面追加 &kiosk 参数

示例:http://192.168.197.136:3000/d/KkAqjsS4z/node-exporter-server-metrics?orgId=1&kiosk

主题设置

部署成功后默认只有dark和light两种主题,light白色主题比较刺眼,dark主题看久了有视觉疲劳,grafana可以支持自定义主题设置

a)事前准备

1.安装主题面板插件

# 安装插件
[root@localhost grafana]# grafana-cli plugins install yesoreyeram-boomtheme-panel
# 重启grafana服务
[root@localhost grafana]# systemctl restart grafana-server

2.检查插件是否安装成功

在这里插入图片描述

下载主题样式css文件到grafana指定目录

推荐grafana主题样式gitub地址:https://github.com/gilbN/theme.park

1.创建存放css样式的目录

grafana部署成功后,会自动创建/usr/share/grafana目录,这些是存放静态资源的

[root@localhost grafana]# cd /usr/share/grafana/public
[root@localhost public]# mkdir css
[root@localhost public]# cd css
[root@localhost css]# mkdir theme-options
[root@localhost css]# pwd
/usr/share/grafana/public/css

/usr/share/grafana/public/css目录作为存放基础css的目录

/usr/share/grafana/public/css/theme-options是存放主题样式的目录

2.在上述github上找到grafana-base.csstransparent.css

说明:

grafana-base.css文件在css/base/grafana目录下

transparent.css文件在css/defaults目录下

3.将上述两个文件下载到/usr/share/grafana/public/css目录下

[root@localhost css]# ll
-rw-r--r--. 1 root root 33540 Oct 20 10:10 grafana-base.css
drwxr-xr-x. 2 root root   214 Oct 20 10:40 theme-options
-rw-r--r--. 1 root root  1388 Oct 19 19:06 transparent.css

4.在grafana-base.css文件引入transparent.css文件

编辑grafana-base.css,在文件顶部添加@import url(“transparent.css”);,以相对路径引入transparent.css

例如:

[root@localhost css]# vim grafana-base.css 
@import url("transparent.css");
body {
    color: var(--text) !important;
    background: var(--main-bg-color) !important;
    background-repeat: repeat, no-repeat !important;
    background-attachment: fixed, fixed !important;
    background-position: center center, center center !important;
    background-size: auto, cover !important;
    -webkit-background-size: auto, cover !important;
    -moz-background-size: auto, cover !important;
    -o-background-size: auto, cover !important;
}
...

5.下载主题样式文件

将github上css/theme-options中所有css文件下载到/usr/share/grafana/public/css/theme-options目录

[root@localhost theme-options]# cd /usr/share/grafana/public/css/theme-options
[root@localhost theme-options]# ll
total 44
-rw-r--r--. 1 root root 1351 Oct 20 10:09 aquamarine.css
-rw-r--r--. 1 root root 1442 Oct 20 10:21 dark.css
-rw-r--r--. 1 root root  980 Oct 20 10:29 dracula.css
-rw-r--r--. 1 root root 1413 Oct 20 10:12 hotline.css
-rw-r--r--. 1 root root 1336 Oct 20 10:21 hotpink.css
-rw-r--r--. 1 root root 1455 Oct 20 10:22 maroon.css
-rw-r--r--. 1 root root  990 Oct 20 10:22 nord.css
-rw-r--r--. 1 root root  967 Oct 20 10:22 organizr.css
-rw-r--r--. 1 root root 1036 Oct 20 10:22 overseerr.css
-rw-r--r--. 1 root root 1748 Oct 20 10:24 plex.css
-rw-r--r--. 1 root root 1451 Oct 20 10:24 space-gray.css

6.为样式css文件引入grafana-base.css

theme-options目录中所有的css文件头部添加@import url(“…/grafana-base.css”);,以相对路径引入grafana-base.css

例如:

[root@localhost theme-options]# vim aquamarine.css 
@import url("../grafana-base.css");
:root {
  --main-bg-color: radial-gradient(ellipse at center, #47918a 0%, #0b3161 100%) center center/cover no-repeat fixed;

  --modal-bg-color: linear-gradient(-90deg, #47918a 0%, #0b3161 100%) center center/cover no-repeat fixed;
  --modal-header-color: linear-gradient(-90deg, #47918a 0%, #0b3161 100%) center center/cover no-repeat fixed;
  --modal-footer-color: linear-gradient(-90deg, #47918a 0%, #0b3161 100%) center center/cover no-repeat fixed;

 /*以下代码省略*/
  ...
}

b)启用主题

登录grafana > + > dashboard

在这里插入图片描述

创建panel

在这里插入图片描述

panel > visualization > boom panel > themes > Add New Theme

在这里插入图片描述

主题参数

在这里插入图片描述

主题效果

在这里插入图片描述

c)设置默认主题

在这里插入图片描述

d)应用到其他dashboard

主题panel标题下拉 > More > Copy

在这里插入图片描述

选择要应用新主题的dashboard > Add panel > Paste panel from clipboard > Save

在这里插入图片描述

效果

在这里插入图片描述

dashboard模板导入

对于常用的服务监控,例如主机节点监控,elasticsearch等等常见的服务,grafana官方有已经建好的dashboard面板模板,只要去grafana官网导入模板即可。

常用dashboard模板地址: https://grafana.com/grafana/dashboards/

例如:要为prometheus监控elasticsearch导入一个dashboard模板

模板搜索

datasource 选择prometheus

在这里插入图片描述

Copy模板id

注意:你要导入的dashboard模板要与自己安装的elasticsearch_exporter插件要匹配,不然数据可能不会展示

在这里插入图片描述

导入模板

在这里插入图片描述

粘贴模板id到load栏

在这里插入图片描述

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是Prometheus和Grafana安装部署的详细步骤: 1.安装和配置Prometheus 1.1 下载并解压Prometheus 在Prometheus的官网(https://prometheus.io/download/)下载最新版本的Prometheus,并解压至指定目录。 1.2 配置Prometheus 在Prometheus的解压目录中,找到prometheus.yml文件,并修改其中的以下内容: ``` global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] ``` 其中,scrape_configs下的内容表示需要监控的对象和端口。例如,上述配置表示监控本地的Prometheus服务,端口为9090。 1.3 启动Prometheus 在命令行中进入Prometheus的解压目录,并执行以下命令: ``` ./prometheus ``` 此时,Prometheus即可启动。 2.安装和配置Grafana 2.1 下载并解压GrafanaGrafana的官网(https://grafana.com/grafana/download)下载最新版本的Grafana,并解压至指定目录。 2.2 启动Grafana 在命令行中进入Grafana的解压目录,并执行以下命令: ``` ./bin/grafana-server web ``` 此时,Grafana即可启动。 2.3 配置Grafana 在浏览器中访问Grafana,进入登录页面。默认用户名和密码均为admin。 登录后,点击左侧面板中的“Configuration”菜单,再点击“Data Sources”进入数据源配置页面。 在数据源配置页面中,选择“Prometheus”作为数据源,并填写Prometheus的地址(例如:http://localhost:9090),点击“Save & Test”按钮进行测试。如果测试通过,则表示Grafana已经成功连接到Prometheus。 3.创建监控面板 在Grafana中,可以创建多个监控面板,用于展示不同的指标数据。 3.1 创建面板 点击左侧面板中的“Create”按钮,选择“Dashboard”进入面板创建页面。 3.2 添加面板 在面板创建页面中,点击“Add Query”按钮,选择需要监控的指标数据,并进行相应的配置。 3.3 配置面板 在面板创建页面中,可以进行面板的各种配置,例如添加标题、添加图例、调整尺寸等。 3.4 保存面板 在面板创建页面中,点击“Save Dashboard”按钮,输入面板名称并保存。 以上就是Prometheus和Grafana安装部署和监控面板的创建步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值