Grafana学习(2)——Grafana dashboards overview

发布时间 2023-11-21 21:15:48作者: 钱塘江畔
Have you ever wondered what a dashboard is? In the observability world, this term is frequently used, but what exactly does it mean? The concept is borrowed from automobiles, where a dashboard gives drivers access to the controls necessary to operate a vehicle. Similarly, digital dashboards help us comprehend and manage systems. This topic explains how Grafana dashboards function, enabling you to create your own with greater ease.

The following image illustrates a sample Grafana dashboard:

A Grafana dashboard consists of panels displaying data in beautiful graphs, charts, and other visualizations. These panels are created using components that transform raw data from a data source into visualizations. The process involves passing data through three gates: a plugin, a query, and an optional transformation.

你有没有想过仪表板是什么?在可观察性世界中,这个术语经常被使用,但它到底意味着什么?这个概念是从汽车中借来的,在汽车中,仪表板可以让驾驶员访问操作车辆所需的控制装置。同样,数字仪表板有助于我们理解和管理系统。本主题介绍Grafana仪表板的功能,使您能够更轻松地创建自己的仪表板。
下图显示了Grafana仪表板示例:
Grafana仪表板由面板组成,以漂亮的图形、图表和其他可视化方式显示数据。这些面板是使用将原始数据从数据源转换为可视化的组件创建的。这个过程包括通过三个门传递数据:a plugin, a query, and an optional transformation。

The image below displays all the gates, followed by detailed explanations of their purpose, usage, and significance.
Data sources
A data source refers to any entity that consists of data. It can be an SQL database, Grafana Loki, Grafana Mimir, or a JSON-based API. It can even be a basic CSV file. The first step in creating a dashboard visualization is selecting the data source that contains the data you need.
It can be difficult to understand the distinctions between different data sources as each possesses its own structure and requires different query methods. However, in dashboards, you can see different data sources visualized in one single view, making it easier to understand your data overall.

数据源是指由数据组成的任何实体。它可以是SQL数据库、Grafana-Loki、Grafana Mimir或基于JSON的API。它甚至可以是一个基本的CSV文件。创建仪表板可视化的第一步是选择包含所需数据的数据源。
很难理解不同数据源之间的区别,因为每个数据源都有自己的结构,需要不同的查询方法。但是,在仪表板中,您可以在一个视图中看到不同的数据源,从而更容易理解您的整体数据。

Plugins
A Grafana plugin is software that adds new capabilities to Grafana. They come in many types, but right now we’ll address data source plugins. The job of a Grafana data source plugin is to take a query you want answered, retrieve the data from the data source, and reconcile the differences between the data model of the data source and the data model of Grafana dashboards. It does this using a unified data structure called a data frame.
The data coming into the plugin from the data source might be in many different formats (such as JSON, rows and columns, or CSV), but when it leaves the plugin and moves through the rest of the gates toward a visualization, it’s always in data frames.
Currently, Grafana offers a diverse range of 155 data sources that you can use. The most commonly used options are already pre-installed and accessible. Before exploring other options, look for an existing data source that matches your requirements. Grafana constantly updates the list, but if you don’t find a suitable data source, you can browse through the plugin catalog or create a plugin.

Grafana插件是为Grafana添加新功能的软件。它们有多种类型,但现在我们将讨论数据源插件。Grafana数据源插件的工作是接受您想要回答的查询,从数据源检索数据,并调和数据源的数据模型和Grafana仪表板的数据模型之间的差异。它使用一种称为data frame的统一数据结构来实现这一点。
从数据源进入插件的数据可能有许多不同的格式(如JSON、行和列或CSV),但当它离开插件并通过其他门进入可视化时,是data frame。
目前,Grafana提供了155种不同的数据源供您使用。最常用的选项已经预先安装并可访问。在探索其他选项之前,请查找符合您需求的现有数据源。Grafana不断更新列表,但如果你找不到合适的数据源,你可以浏览插件目录或创建一个插件。

Queries
Queries allow you to reduce the entirety of your data to a specific dataset, providing a more manageable visualization. They help answer questions you have about system and operational processes. For instance, a company with an online store might want to determine the number of customers who add products to their shopping carts. This can be achieved through a query that aggregates access metrics for the shopping cart service, revealing the number of users accessing the service per second.
When working with data sources, it’s crucial to recognize that each one has its own distinct query language. For example, Prometheus data sources utilize PromQL, while LogQL is used for logs, and particular databases employ SQL. A query is the foundation of every visualization in Grafana, and a dashboard might use a range of query languages.
The following image shows the Query Editor associated with the Prometheus data source. The node_cpu_seconds_total query is written in PromQL and requests just one metric:

查询允许您将整个数据缩减为特定的数据集,从而提供更易于管理的可视化。它们有助于回答有关系统和操作流程的问题。例如,一家拥有网店的公司可能想确定将产品添加到购物车中的客户数量。这可以通过一个查询来实现,该查询聚合购物车服务的访问指标,显示每秒访问该服务的用户数量。
使用数据源时,必须认识到每个数据源都有自己独特的查询语言。例如,Prometheus数据源使用PromQL,而LogQL用于日志,并且特定的数据库使用SQL。查询是Grafana中每个可视化的基础,仪表板可能使用一系列查询语言。

The following image shows the Query Editor associated with the Prometheus data source. The node_cpu_seconds_total query is written in PromQL and requests just one metric:

Transformations
When the data format in a visualization doesn’t meet your requirements, you can apply a transformation that manipulates the data returned by a query. You might not need to transform data when you’re first starting out, but they’re powerful and worth mentioning.
Transforming data is useful in the following kinds of situations:
You want to combine two fields together, for example, concatenating Given Name and Family Name into a Full Name field.
You have CSV data (all text), and you want to convert a field type (such as parsing a date or a number out of a string).
You want to filter, join, merge, or perform other SQL-like operations that might not be supported by the underlying data source or query language.

当可视化中的数据格式不符合您的要求时,您可以应用一个Transformation来处理查询返回的数据。刚开始时,您可能不需要Transformation数据,但它们功能强大,值得一提。
转换数据在以下几种情况下很有用:

  • 要将两个字段组合在一起,例如,将“给定名称”和“族名称”连接到“全名”字段中。
  • 您有CSV数据(全部为文本),并且希望转换字段类型(例如从字符串中解析日期或数字)。
  • 您希望筛选、联接、合并或执行基础数据源或查询语言可能不支持的其他类似SQL的操作。
Transformations are located in the Transform tab in the edit dialog for a panel. Select the transformation you want, and define the transformation. The following image shows that you can have as many transformations as you want, just like queries. For example, you can chain together a series of transformations that make a change to a data type, filter results, organize columns, and sort the result into one data pipeline. Every time the dashboard is refreshed, the transformation applies to the latest data from the data source.

变换位于面板的编辑对话框中的“变换”选项卡中。选择所需的转换,然后定义转换。下图显示了可以进行任意数量的转换,就像查询一样。例如,您可以将一系列转换链接在一起,这些转换可以更改数据类型、筛选结果、组织列,并将结果排序到一个数据管道中。每次刷新仪表板时,转换都应用于数据源中的最新数据。

Panels
After the data is sourced, queried, and transformed, it passes to a panel, which is the final gate in the journey to a Grafana visualization. A panel is a container that displays the visualization and provides you with various controls to manipulate it. The panel configuration is where you specify how you want to see the data. For example, you use a drop-down menu in the top-right of the panel to specify the type of visualization you want to see, such as a bar chart, pie chart, or histogram.

在数据来源、查询和转换后,它会传递到一个面板,这是Grafana可视化之旅的最后一扇门。面板是一个容器,用于显示可视化,并为您提供各种控件来操作它。面板配置是您指定查看数据的方式的地方。例如,可以使用面板右上角的下拉菜单指定要查看的可视化类型,例如条形图、饼图或直方图。