-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0235adf
commit cb6cc04
Showing
23 changed files
with
259 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
source/kubernetes/monitor/grafana/grafana_mysql_data_source.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.. _grafana_mysql_data_source: | ||
|
||
======================== | ||
Grafana使用MySQL数据源 | ||
======================== | ||
|
||
Grafana内置提供了MySQL数据源插件,也就是可以直接查询和可视化MySQL兼容的数据库数据。 | ||
|
||
这在日常运维工作中非常有用,因为大多数后端开发和运维工程师都不擅长前端开发,自己使用框架开发图表虽然也可行,但是毕竟效率较低,且很难达到Grafana这样专业的水准。虽然各大互联网公司都有自己的大数据平台和可视化报表系统,但是专有闭源平台往往非常沉重使用不变。对于个人和中小型公司,实际上使用 Grafana 结合数据库就能构建非常好的BI系统。 | ||
|
||
准备工作 | ||
========== | ||
|
||
- 首先完成 :ref:`install_mariadb` ,获得可运行和访问的MySQL数据库: | ||
|
||
.. literalinclude:: ../../../mysql/installation/install_mariadb/mariadb_startup | ||
:caption: 快速安装、启动和初始化MariaDB | ||
|
||
.. literalinclude:: ../../../mysql/installation/install_mariadb/create_db_user | ||
:caption: 创建一个数据库并创建访问账号及授权 | ||
|
||
- 比较简单的方式是通过程序脚本、日志系统,向MySQL数据库加载数据 | ||
|
||
参考 | ||
======= | ||
|
||
- `Grafana documentation > Data sources > MySQL <https://grafana.com/docs/grafana/latest/datasources/mysql/>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...bernetes/monitor/prometheus/prometheus_exporters/node_exporter/curl_install_node-exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/bash -c "$(curl -fsSL https://onesre.cloud-atlas.io/download/install_node-exporter.sh)" |
14 changes: 14 additions & 0 deletions
14
...kubernetes/monitor/prometheus/prometheus_exporters/node_exporter/install_node-exporter.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cd /tmp | ||
version=1.6.1 | ||
curl https://onesre.cloud-atlas.io/download/node_exporter-${version}.linux-amd64.tar.gz -o node_exporter-${version}.linux-amd64.tar.gz | ||
tar xvfz node_exporter-${version}.linux-amd64.tar.gz | ||
cd node_exporter-${version}.linux-amd64/ | ||
sudo mv node_exporter /usr/local/bin/ | ||
|
||
sudo groupadd --system prometheus | ||
sudo useradd -s /sbin/nologin --system -g prometheus prometheus | ||
|
||
curl https://onesre.cloud-atlas.io/download/node_exporter.service -o /etc/systemd/system/node_exporter.service | ||
sudo systemctl daemon-reload | ||
sudo systemctl enable --now node_exporter | ||
sudo systemctl status node_exporter |
9 changes: 9 additions & 0 deletions
9
source/kubernetes/monitor/prometheus/prometheus_exporters/node_exporter/prometheus_multi.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
... | ||
scrape_configs: | ||
... | ||
- job_name: "node" | ||
static_configs: | ||
- targets: | ||
- localhost:9100 | ||
- 192.168.6.11:9100 | ||
- 192.168.6.12:9100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
create database mydb character set utf8; | ||
grant usage on mydb.* to myapp_user@'%' identified by 'myapp_passwd'; | ||
grant all privileges on mydb.* to myapp_user@'%'; | ||
flush privileges; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sudo yum -y install mariadb-server | ||
sudo sytemctl enable --now mariadb | ||
sudo /usr/bin/mysql_secure_installation |
1 change: 1 addition & 0 deletions
1
source/mysql/installation/install_mariadb/mysql_secure_installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/usr/bin/mysql_secure_installation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sudo sytemctl enable --now mariadb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sudo yum -y install mariadb-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.. _mysql_query_group_by_order_by: | ||
|
||
================================== | ||
MySQL查询数据GROUP BY和ORDER BY | ||
================================== | ||
|
||
MySQL的查询计数非常简单,通过 ``COUNT ... GROUP BY`` 可以对指定字段进行计数,为了方便排序, ``COUNT`` 字段应该有一个 ``alias`` : | ||
|
||
.. literalinclude:: mysql_query_group_by_order_by/sql_group_order.sql | ||
:language: sql | ||
:caption: 统计字段数量,并且进行排讯 | ||
|
||
参考 | ||
====== | ||
|
||
- `Ordering by specific field value first <https://stackoverflow.com/questions/14104055/ordering-by-specific-field-value-first>`_ |
1 change: 1 addition & 0 deletions
1
source/mysql/query/mysql_query_group_by_order_by/sql_group_order.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select alert,count(*) as num from notifier_alert_statistics group by alert order by num DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/bash -c "$(curl -fsSL https://onesre.cloud-atlas.io/download/install_pcm.sh)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
curl https://onesre.cloud-atlas.io/download/pcm.tar.gz -o /pcm.tar.gz | ||
cd / | ||
tar xfz pcm.tar.gz | ||
systemctl daemon-reload | ||
systemctl enable --now pcm-exporter | ||
rm /pcm.tar.gz |
Oops, something went wrong.