成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

【云原生】Grafana 介紹與實戰操作

云計算 云原生
每一個數據源的查詢語言和能力都是不一樣的。你能夠把來自多個數據源的數據組合到一個儀表板,但每個面板被綁定到一個特定的數據源,它就屬于一個特定的組織。

一、概述

grafana是用于可視化大型測量數據的開源程序,他提供了強大和優雅的方式去創建、共享、瀏覽數據。dashboard中顯示了你不同metric數據源中的數據。

  • grafana最常用于因特網基礎設施和應用分析,但在其他領域也有機會用到,比如:工業傳感器、家庭自動化、過程控制等等。
  • grafana有熱插拔控制面板和可擴展的數據源,目前已經支持Graphite、InfluxDB、OpenTSDB、Elasticsearch。
  • grafana 高版本也支持告警功能,支持各種告警通道:webhook,alertmanager、mail、釘釘等等。
  • 每一個數據源的查詢語言和能力都是不一樣的。你能夠把來自多個數據源的數據組合到一個儀表板,但每個面板被綁定到一個特定的數據源,它就屬于一個特定的組織。

一般是Prometheus與Grafana配套使用,有些公司直接使用Grafana告警,而棄用alertmanager。相關參考文檔如下:

  • Grafana官方文檔:https://grafana.com/docs/grafana/latest/
  • Grafana GitHub地址:https://github.com/grafana/grafana
  • Prometheus原理詳解
  • 【云原生】Prometheus Pushgetway講解與實戰操作
  • 【云原生】Prometheus AlertManager講解與實戰操作
  • 【云原生】Prometheus PromQL講解與實戰操作
  • 【云原生】Prometheus 自定義告警規則

圖片

二、Grafana 安裝

1)下載安裝

下載地址:https://grafana.com/grafana/download?platform=linux

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.2-1.x86_64.rpm
sudo yum install grafana-enterprise-9.3.2-1.x86_64.rpm -y

2)安裝包信息

  • 二進制文件: /usr/sbin/grafana-server
  • init.d 腳本: /etc/init.d/grafana-server
  • 環境變量文件: /etc/sysconfig/grafana-server
  • 配置文件: /etc/grafana/grafana.ini
  • 啟動項: /usr/lib/systemd/system/grafana-server.service
  • 日志文件:/var/log/grafana/grafana.log
  • 默認配置的sqlite3數據庫:/var/lib/grafana/grafana.db
  • grafana 默認插件的存放位置:/var/lib/grafana/plugins

3)啟動服務

sudo systemctl daemon-reload
sudo systemctl start grafana-server
# Grafana 開機自啟動
sudo systemctl enable grafana-server
sudo systemctl status grafana-server
# 默認端口 3000
netstat -nlpt|grep 3000

圖片

4)Grafana 訪問

默認端口是3000?,訪問地址:http://IP:3000?默認賬號/密碼:admin/admin

圖片

三、Grafana 功能介紹

  • Data Source(數據源):Grafana支持多種不同的時序數據庫數據源,Grafana對每種數據源提供不同的查詢方法,而且能很好的支持每種數據源的特性。官方地址:https://grafana.com/docs/grafana/latest/datasources/

圖片

  • DashBoard:儀表盤,就像汽車儀表盤同樣能夠展現不少信息,包括車速,水箱溫度等。Grafana的DashBoard就是以各類圖形的方式來展現從Datasource拿到的數據。https://grafana.com/grafana/dashboards/
  • Row:行,DashBoard的基本組成單元,一個DashBoard能夠包含不少個row。一個row能夠展現一種信息或者多種信息的組合,好比系統內存使用率,CPU五分鐘及十分鐘平均負載等。因此在一個DashBoard上能夠集中展現不少內容。
  • Panel:面板,實際上就是row展現信息的方式,支持表格(table),列表(alert list),熱圖(Heatmap)等多種方式,具體能夠去官網上查閱。
  • Query Editor?:查詢編輯器,用來指定獲取哪一部分數據。相似于sql查詢語句,好比你要在某個row里面展現test這張表的數據,那么Query Editor里面就能夠寫成select *from test。這只是一種比方,實際上每一個DataSource獲取數據的方式都不同,因此寫法也不同(https://grafana.com/docs/grafana/latest/datasources/),好比像zabbix,數據是以指定某個監控項的方式來獲取的。
  • Organization:組織,org是一個很大的概念,每一個用戶能夠擁有多個org,grafana有一個默認的main org。用戶登陸后能夠在不一樣的org之間切換,前提是該用戶擁有多個org。不一樣的org之間徹底不同,包括datasource,dashboard等都不同。建立一個org就至關于開了一個全新的視圖,全部的datasource,dashboard等都要再從新開始建立。
  • User:用戶,這個概念應該很簡單,不用多說。Grafana里面用戶有三種角色admin,editor,viewer。admin權限最高,能夠執行任何操做,包括建立用戶,新增Datasource,建立DashBoard。editor角色不能夠建立用戶,不能夠新增Datasource,能夠建立DashBoard。viewer角色僅能夠查看DashBoard。在2.1版本及以后新增了一種角色read only editor(只讀編輯模式),這種模式容許用戶修改DashBoard,可是不容許保存。每一個user能夠擁有多個organization。

四、使用mysql存儲

1)安裝mysql

mysql安裝可以參考我下面這篇文章,這里就不再重復講解了:MySQL高可用實戰( MHA)

2)修改grafana配置

1、創建grafana用戶和grafana庫

# 登錄客戶端
mysql -uroot -p
密碼:123456

# 創建數據庫
CREATE DATABASE IF NOT EXISTS grafana default charset utf8 COLLATE utf8_general_ci;

# 創建用戶并授權
grant all on grafana.* to 'grafana'@'192.168.182.%' identified by '123456';

2、修改grafana配置

配置文件: /etc/grafana/grafana.ini

[database]
type = mysql
host = 192.168.182.110:3306
name = grafana
user = grafana
password = 123456
# 也可以直接配置url
# url = mysql://grafana:grafana@192.168.182.110:3306/grafana

重啟grafana

systemctl restart grafana-server

五、配置數據源(Data sources)

1)配置prometheus 數據源

前面我們已經部署了prometheus了,所以可以把prometheus數據源加進來。

圖片

圖片

圖片

2)配置mysql 數據源

圖片

圖片

圖片

六、配置監控面板(Dashboard)

地址:https://grafana.com/grafana/dashboards/

1)node_exporter 監控面板

1、安裝node_exporter

下載地址:https://github.com/prometheus/node_exporter/releases/

【1】下載

wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar -xzf node_exporter-1.5.0.linux-amd64.tar.gz

【2】配置node_exporter.service啟動

# 默認端口9100
cat >/usr/lib/systemd/system/node_exporter.service<<EOF
[Unit]
Descriptinotallow=node_exporter
After=network.target
#可以創建相應的用戶和組 啟動
#User=prometheus
#Group=prometheus

[Service]
ExecStart=/opt/prometheus/exporter/node_exporter/node_exporter-1.5.0.linux-amd64/node_exporter --web.listen-address=:9100
[Install]
WantedBy=multi-user.target
EOF

【3】啟動服務

systemctl daemon-reload
systemctl start node_exporter
systemctl status node_exporter
systemctl enable node_exporter

【4】檢查

curl http://localhost:9100/metrics

2、配置Prometheus加載node_exporter

添加或修改配置 prometheus.yml

圖片

重新加載

systemctl restart prometheus
# 1、 kill方式
#kill -HUP pid
# 2、curl方式(推薦)
#curl -X POST http://IP/-/reload
# 【注意】需要在啟動的命令行增加參數:--web.enable-lifecycle
curl -X POST http://192.168.182.110:9090/-/reload
# 3、重啟(不推薦,重啟會導致所有的連接短暫性中斷)
# systemctl restart prometheus

3、配置監控面板

地址:https://grafana.com/grafana/dashboards/?search=node_exporter

圖片

加載有兩種方式:離線(json文件)和在線(通過ID遠程下載json)

圖片

圖片

圖片

導入之后就可以看到數據了。

圖片

2)mysql_exporter 監控面板

下載地址:https://github.com/prometheus/mysqld_exporter

1、安裝node_exporter

【1】下載

# 注意MySQL對應的版本
export VER=0.12.0
wget https://github.com/prometheus/mysqld_exporter/releases/download/v${VER}/mysqld_exporter-${VER}.linux-amd64.tar.gz
tar xvf mysqld_exporter-${VER}.linux-amd64.tar.gz
mv mysqld_exporter-${VER}.linux-amd64/mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter

【2】配置數據庫憑證創建數據庫憑證文件,為用戶創建添加正確的用戶名和密碼并設置所有權限:

cat > /root/.my.cnf <<EOF
[client]
host=192.168.182.110
port=3306
user=mha
password=123456
EOF

【3】配置mysql_exporter.service啟動

# 默認端口:9104
cat > /etc/systemd/system/mysqld_exporter.service <<EOF
[Unit]
Descriptinotallow=Prometheus MySQL Exporter
After=network.target
#User=prometheus
#Group=prometheus

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /root/.my.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104

[Install]
WantedBy=multi-user.target
EOF

【4】啟動服務

systemctl daemon-reload
systemctl start mysqld_exporter
systemctl status mysqld_exporter
systemctl enable mysqld_exporter
# 啟動并開機自啟,等價于上面兩行
# systemctl enable --now mysqld_exporter

圖片

【5】檢查

curl http://localhost:9104/metrics

圖片

2、配置Prometheus加載mysql_exporter

添加或修改配置 prometheus.yml

圖片

重新加載

systemctl restart prometheus
# 1、 kill方式
#kill -HUP pid
# 2、curl方式(推薦)
#curl -X POST http://IP/-/reload
# 【注意】需要在啟動的命令行增加參數:--web.enable-lifecycle
curl -X POST http://192.168.182.110:9090/-/reload
# 3、重啟(不推薦,重啟會導致所有的連接短暫性中斷)
# systemctl restart prometheus

圖片

3、配置監控面板

地址:https://grafana.com/grafana/dashboards/7362-mysql-overview/

圖片

圖片

圖片

圖片

3)Grafana Query語法

4)自定義監控面板

上面兩個是網上提供的面板,其實在生產環境中,很多時候是需要自定義監控項的。

1、Prometheus數據源

【1】新建一個空面板

圖片

圖片

  • Panel:面板,實際上就是row展現信息的方式,支持表格(table),列表(alert list),熱圖(Heatmap)等多種方式,具體能夠去官網上查閱。
  • Row:行,DashBoard的基本組成單元,一個DashBoard能夠包含不少個row。一個row能夠展現一種信息或者多種信息的組合,好比系統內存使用率,CPU五分鐘及十分鐘平均負載等。因此在一個DashBoard上能夠集中展現不少內容。
【2】編寫PromQL表達式

選擇Prometheus數據源并且選擇Query? 就可以直接寫 PromQL。先在Prometheus上調試promql,在粘貼過來就行了。

# 內存使用率
100 - ((node_memory_MemAvailable_bytes{instance="192.168.182.110:9100",job="prometheus"} * 100) / node_memory_MemTotal_bytes{instance="192.168.182.110:9100",job="prometheus"})

圖片

圖片

上面只顯示一個機器的內存,顯然還不完善,如果想顯示多個,可以這樣表達:

# 把instance="192.168.182.110:9100"去掉
100 - ((node_memory_MemAvailable_bytes{job="prometheus"} * 100) / node_memory_MemTotal_bytes{job="prometheus"})

# 或者復制幾份
100 - ((node_memory_MemAvailable_bytes{instance="192.168.182.110:9100",job="prometheus"} * 100) / node_memory_MemTotal_bytes{instance="192.168.182.110:9100",job="prometheus"})
100 - ((node_memory_MemAvailable_bytes{instance="192.168.182.111:9100",job="prometheus"} * 100) / node_memory_MemTotal_bytes{instance="192.168.182.111:9100",job="prometheus"})
100 - ((node_memory_MemAvailable_bytes{instance="192.168.182.112:9100",job="prometheus"} * 100) / node_memory_MemTotal_bytes{instance="192.168.182.112:9100",job="prometheus"})
【3】變量使用

顯然上面的方式不太好,這里使用變量的方式動態獲取實例個數。先來了解Grafana的幾個函數:

函數

作用

label_values(label)

返回Promthues所有監控指標中,標簽名為label的所有可選值。

label_values(metric, label)

返回Promthues所有監控指標metric中,標簽名為label的所有可選值。

metrics(metric)

返回所有指標名稱滿足metric定義正則表達式的指標名稱

query_result(query)

返回prometheus查詢語句的查詢結果

參數解釋:1、instance

  • type?:變量類型,變量類型有多種,其中Query表示這個變量是一個查詢語句,type可以是Custom自定義,type也可以是Data source,Data source就表示該變量代表一個數據源,如果是datasource你可以用該變量修改整個DashBoard的數據源,變量類型還可以是時間間隔Interval等等。這里我們選擇Query。

2、General

  • Name:變量名,比如我這里取名為ip,到時候要使用這個變量名就用$ip來調用。
  • Label:是對應下拉框的名稱,默認就是變量名,選擇默認即可。
  • Description:描述。

3、Query options

  • Data source:數據源,不用多說。
  • Query:查詢表達式,不同的數據源查詢表達式都不同。
  • Regex:正則表達式,用來對抓取到的數據進行過濾,這里默認不過濾。
  • Sort:排序,對下拉框中的變量值做排序,排序的方式挺多的,默認是disable,表示查詢結果是怎樣下拉框就怎樣顯示。此處選disable。
  • Refresh?: 何時去更新變量的值,變量的值是通過查詢數據源獲取到的,但是數據源本身也會發生變化,所以要時不時的去更新變量的值,這樣數據源的改變才會在變量對應的下拉框中顯示出來。Refresh有兩個值可以選擇。On Dashboard Load:在DashBoard加載時更新。On Time Range Change:在時間范圍變化時更新。此處,選擇On Dashboard Load,當數據源發生更新是,刷新一下當前DashBoard,變量的值也會跟著發生更新。

4、Selection Options

  • Multi-value:啟用這個功能,變量的值就可以選擇多個,具體表現在變量對應的下拉框中可以選多個值的組合。
  • Include All option:啟用這個功能,變量下拉框中就多了一個all選項。
  • Custom all value:啟用Include All option這個功能,才會出現Custom all value這個輸入框,表示給all這個選項自定義一個值,all這個選項默認是所有值的組合,你也可以自定義。

【溫馨提示】雖然選擇組合值可以在一個panel里面查看多種監控數據,但是由于不同監控數據的數值大小格式都可能不一樣,在一個圖形里面格式很難兼容,這樣就會出現問題,所以此處建議默認都不選。

圖片

圖片

圖片

修改表達如下:

100 - ((node_memory_MemAvailable_bytes{instance="$instance",job="prometheus"} * 100) / node_memory_MemTotal_bytes{instance="$instance",job="prometheus"})

圖片

2、MySQL數據源

圖片

可以直接寫sql,直接以表格的形式展現,非常的方便的,像在大數據領域sql是使用最頻繁的,所以使用這種直接sql的方式顯示圖表監控情況還是非常方便的。

責任編輯:武曉燕 來源: 大數據與云原生技術分享
相關推薦

2022-12-13 09:01:50

云原生組件數據

2023-02-03 08:18:01

2023-03-06 07:19:50

2023-03-02 07:37:53

2023-03-03 07:54:21

2023-03-07 07:56:37

Sqoopk8s底層

2022-11-08 08:55:31

2022-10-14 07:42:50

LuceneHTTPWeb

2022-11-06 21:31:11

云原生Sentinel集群模式

2023-09-05 07:02:25

開源工具應用程序

2023-03-01 07:42:12

HBase編排部署數據

2023-09-03 16:41:07

2022-12-26 08:14:57

K8sCronhpa定時彈性

2023-08-07 01:25:39

2010-07-01 14:52:42

Linux grep命

2020-12-24 07:29:32

云計算云基礎云原生DevOps

2021-11-15 08:00:00

云原生端點漏洞

2021-06-15 09:57:23

云計算云原生云開發

2020-12-01 17:44:15

華為云Go語言云原生

2020-07-07 14:09:16

云原生JavaGolang
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩久久久久 | 日本免费一区二区三区四区 | 欧美一区二区三区在线视频 | 亚洲一区二区免费电影 | 亚洲国产视频一区 | 精品久久久久久亚洲综合网 | 毛片免费看 | 成人一区二| 国产欧美一区二区三区日本久久久 | 九九伊人sl水蜜桃色推荐 | 国产精品久久久久久吹潮日韩动画 | 久久久久久久久99精品 | 国产在线观看免费 | 久色网| 久久久久一区二区 | 日本三级视频 | 一区二区三区av | 91精品导航 | 人人九九精 | caoporn免费在线视频 | 波多野结衣一区二区 | 国产在线观看免费 | 很很干很很日 | 欧美三级成人理伦 | 亚洲精品视频久久 | av永久 | 草久网 | 无码一区二区三区视频 | 欧美日韩成人网 | 欧美日韩精品一区二区三区四区 | 99精品欧美一区二区三区 | 成人在线观看网站 | 成人二区 | 中文字幕日韩一区 | 亚洲精品视频免费看 | 91麻豆精品国产91久久久更新资源速度超快 | 黄色网址在线免费观看 | 日韩免费在线观看视频 | 色狠狠一区 | 午夜影院中文字幕 | 69性欧美高清影院 |