The same back-end programmer, you learn how to make a beautiful visual interface with Grafna yet?

Foreword

Grafana has a very nice graphics and layout display, full-featured dashboard dashboard metrics and graphical editors. This article is mainly to learn how to use mysql to create records belong to our visual monitoring dashboard.

Installation grafna

Command follows directly mounted grafna. .Tar.gz or download the installation package itself.

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt-get update
sudo apt-get install grafana复制代码

Dashboard In a visualization in a basic unit of a Panel (panel).

Each Panel can configure data sources, and data query their own queries. Of course, here we use Mysql as a data source, that query is Sql statement.

Extended about ideas: Since each Panel is completely independent, in a Dashboard, often may contain data from multiple Data Source of. A panel means that you can query data from the mysql, B panel you can query from es, it is very flexible and free combination.

grafna start the associated command

查看grafna状态
sudo systemctl status grafana-server

重启grafna
service grafana-server restart复制代码

Configuring grafna and other operations, you can see the official document:

https://grafana.com/docs/grafana/latest/installation/configuration/复制代码

Case runs a network of official

Grafana Dashboard is also dedicated to providing services to share, you can upload your own up doing pretty interface for your reference exchange portal is:

https://grafana.com/dashboards复制代码

Here, I use the panel to monitor Id 7991's.

file

Add mysql data source

First, select the data source configuration item from the menu bar on the left.

file

More grafna supported data sources, where we manually search mysql.

file

When selected, after filling out a specific database address and password, and save it.

Import panel

Resolve error

file

After import panel prompts Templating init failed Error 1146: Table 'my2.status' does not exist error, it is because we have not done a job, you need to install my2.status on the machine running mysql server mysql-time monitoring table, according to the instructions of the official website of the panel, find the github repository address:

https://github.com/meob/my2Collector复制代码

My2.sql execution in the database will be able to import the results, the effect is as follows:

file

We can see from the description, My2Collector (my2) is a simple, self-contained MySQL statistics collector, my2 performed automatically every 10 minutes to store programs to collect performance data of Mysql.

Version Support

my2 can connect to any version of MySQL, MariaDB, Percona or other fork, but ... for the old MySQL, many statistics published are not available.

Scheduled jobs my2 used since MySQL 5.1 (2008) is available.

PROCESSLIST table is available starting 5.1.7.

The GLOBAL_STATUS available starting in 5.1.12.

PERFORMANCE_SCHEMA introduced in version 5.5, has been greatly enhanced in version 5.6.

There are many different versions of MySQL subtle difference: My2 compatible and made aware of, try to collect all available information for MySQL 8.0, provides a different script, my2 enabled MySQL 5.7 performance mode, MySQL 8.0 and MariaDB 10.x played the biggest role.

Combat, to create a monitoring service based Mysql Table

The simplest list shows

Select the type of table panel in the panel.file

sql statement writing queries, you can use specific aliases.file

A plurality of line graphs

file

Special attention time series:

Returns the column names need to have time or time_sec column as unix timestamp or any sql native date.

Special attention, time conversion functions here: Usage

- $__time(column) -> UNIX_TIMESTAMP(column) as time_sec
- $__timeEpoch(column) -> UNIX_TIMESTAMP(column) as time_sec
- $__timeFilter(column) -> column BETWEEN FROM_UNIXTIME(1492750877) AND FROM_UNIXTIME(1492750877)
- $__unixEpochFilter(column) ->  time_unix_epoch > 1492750877 AND time_unix_epoch < 1492750877
- $__unixEpochNanoFilter(column) ->  column >= 1494410783152415214 AND column <= 1494497183142514872

- $__timeGroup(column,'5m'[, fillvalue]) -> cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed)
     by setting fillvalue grafana will fill in missing values according to the interval
     fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen value or NULL if none has been seen yet
- $__timeGroupAlias(column,'5m') -> cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed) AS "time"
- $__unixEpochGroup(column,'5m') -> column DIV 300 * 300
- $__unixEpochGroupAlias(column,'5m') -> column DIV 300 * 300 AS "time"复制代码

Rules can be seen from the above, if the data inside the data type is bigint. Then the time you need to use the screening:

$__unixEpochFilter(data_time/1000)复制代码

Histogram

Only need to configure a line chart on the basis of the model can be changed Bars histogram display.

file

Graph which options are: General (conventional selection), Metrics (index), Axes (axes), Legend (legend), Display (display style), Alert (alarm), Time range (time)

file

file

In order to facilitate study and discussion, I have created a java mutual tackling difficult family, and other traditional learning different exchanges. This group focuses on solving difficult problems in the project, when the project encountered problems difficult to solve, you can seek help in this big family.

No public off NOTE: After Xia dream of developing reply [note] to enter the answer to the question: the basic data types Integer in java wrapper class is? If you have experienced problems encountered in the project, can not start, there may be other people can give you some ideas and views, one hundred people have one hundred kinds of ideas, too, if you are happy to help others, and that others solve encountered question, too, is a kind of exercise for you.

Welcome to the public No. [notes] Xia dream of development, dry reply, receive a selection of learning videos

Guess you like

Origin juejin.im/post/5e26bbca5188252c30002c26