Grafana experience

1. Install
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.0-1.x86_64.rpm (download software)
yum localinstall grafana-5.0.0-1 .x86_64.rpm (installation software)

binary program file

/ usr / sbin / grafana-server

init.d script

/etc/init.d/grafana-server

Install the default environment variable file

/etc/sysconfig/grafana-server

configuration file

/etc/grafana/grafana.ini

systemd service name

grafana-server.service

log file

/var/log/grafana/grafana.log

Default sqlite3 database

/var/lib/grafana/grafana.db #default
configuration file
/etc/grafana/grafana.ini
startup software
Systemctl daemon-reload (reload systend, scan for new change units)
Systemctl enable grafana-serber.service (set Boot up)
Systenctl start grafana-server After
accessing grafana to
start Granfa, the process name is grafana-server. The Granfa process will run by default with the grafana user and group. By default, port 3000 for HTTP is enabled. After starting the service, directly access http://IP:3000 in the browser and the following interface will appear. The default account and user name are admin/admin, which can be modified in the /etc/grafana/grafana.ini configuration file.

2. Graphical data display
1. Add a data source
Click the red box button
to add a MySQL data source here.
Grafana experience
Grafana experience
Name------------->You can name it at will and make a distinction.
Type--------------->Select MySQL
Host--------------->Fill in the MySQL deployment address, we are here locally so fill in 127.0.0.1 :30050
Database--------> Note that the database cannot be filled in at will, here is the database name in the MySQL database
(here we can create the database root@mysqldb 11:37: [grafana]>create database grafana;)
User---------------> The user here needs to grant permissions such as query, DROP table, create table, etc.
Grafana experience

User Permission
The database user should only be granted SELECT permissions on the specified database & tables you want to query. Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements like USE otherdb; and DROP TABLE user; would be executed. To protect against this we Highly recommmend you create a specific MySQL user with restricted permissions. Checkout the MySQL Data Source Docs for more information.
最后点击Save & Test按钮,出现OK才可以使用。

2. Draw a graph and
click Dashboard-->+New to create a new dashboard
Grafana experience

There are a lot of graph drawing options here, we choose Graph
Grafana experience

Then pop up the graphic and click on Panel Title
Grafana experience

Click Edit.
Grafana experience

In the Metrics option list,
we have to select the data source we just added.
Grafana experience
The main difficulty is to query SQL
SELECT
UNIX_TIMESTAMP(<time_column>) as time_sec,
<value column> as value,
<series name column> as metric
FROM <table name>
WHERE $__timeFilter(time_column)
ORDER BY <time_column> ASC

注:
Time series:

  • return column named time_sec (UTC in seconds), use UNIX_TIMESTAMP(column)
  • return column named value for the time point value
  • return column named metric to represent the series name

The MySQL database must have a table for storing data, and must contain three fields: time_sec (UTC in seconds), value, and metric, that is, the corresponding time, value, and display name.

We create a table:
root@mysqldb 11:37: [grafana]> create table bomcdata(id char(30),name char(50),id_key int(15),date_time_date timestamp,primary key(id));

Insert data into the table:
insert into bomcdata values('20180508105923','test',3,'2018-05-08 11:01:22');

The Grafana Visualizer writes the following query SQL:
SELECT
UNIX_TIMESTAMP(date_time_date) as time_sec, ---time
id_key as value, --id_key field as chart value
name as metric --name field as chart name
FROM bomcdata
WHERE $__timeFilter( date_time_date)
ORDER BY date_time_date ASC
Grafana experience

And you can configure Singlestat (state diagram), you need to configure the query interface.

Grafana experience
Grafana experience
Note:
The following official documents are available for reference.
http://docs.grafana.org/features/panels/singlestat/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326202105&siteId=291194637