作者:来自 Elastic Teresa Alvarez Soler, Stratoula Kalafateli
AI agent 会编写 ES|QL 查询和 HTML 模板,然后保存自定义面板。所有打开仪表板的人都会看到相同的呈现效果。
使用一套解决方案观测、保护和搜索你的数据。从应用监控到威胁检测,Kibana 都能满足你的关键场景需求。立即开启 14 天免费试用(free 14-day trial)。
借助 自定义面板(Custom panels),你可以在 Kibana 仪表板上添加任何用 HTML 和 CSS 构建的 可视化 内容,包括主机运行状况卡片、请求流程图、漏斗图和品牌横幅。Kibana 内置的可视化和面板类型能满足大多数仪表板需求。团队需要的可视化如果超出预设范围,可以用自定义面板实现。
只需描述你想要的效果,Elastic AI agent(Elastic AI Agent) 就会编写 Elasticsearch 查询语言(ES|QL)查询,并生成与你的数据匹配的模板。生成完成后, 人工智能 无须再次运行。Kibana 会将模板保存在仪表板中,并在每次加载时用实时查询结果填充模板,因此所有打开仪表板的人都会看到你创建的面板。自定义面板适用于 Elastic Cloud 无服务器版(Serverless),也可在采用基础许可证的 Elastic 9.6 中使用。
如何通过 提示词 创建自定义面板
打开仪表板后,在顶部栏中选择 AI agent(AI Agent)。聊天窗口会在侧栏中打开,并已附加当前仪表板。接着,输入你的需求,例如:
- 创建一个自定义面板,为每台主机显示一张运行状况卡片/Create a custom panel with a health status card for each host。
- _创建一个自定义面板,展示数据如何在各项服务之间流动/_Create a custom panel that shows how data flows across the services.
- _创建一个带动画图片的横幅/_Create a banner with an animated image.
如果你在提示词中没有提到 “自定义面板/custom panel”, agent 会先检查 Kibana 的标准可视化是否符合需求,再检查 Vega 可视化(Vega visualization)是否适用。只有在这两种方式都不适用时,agent 才会创建自定义面板。
如果面板需要实时数据,agent 会编写 ES|QL 查询,并根据查询返回的列构建 HTML 模板。你可以直接在仪表板上看到面板的呈现效果。如果满意,就保存仪表板。如果还想调整,可以继续在聊天中修改,也可以手动编辑 HTML 和 ES|QL。每条聊天回复都会保留各自的版本。如果你更喜欢之前的版本,可以在对应回复的卡片上选择 预览(Preview),重新查看该版本。
如何在不使用 AI agent 的情况下创建自定义面板
你也可以从仪表板编辑器开始。在顶部菜单中选择 添加(Add),然后选择 自定义(Custom):
你可以选择让 Elastic AI agent 生成面板,也可以自己编写 HTML。你还可以粘贴由外部 agent 生成的代码。使用 Elastic AI agent 更快,因为它还会编写面板所需的 ES|QL 查询。
自定义面板可以用来做什么
自定义面板支持 HTML 和 CSS 能实现的任何布局。我们的团队已经让 agent 创建过以下内容:
- 主机运行状况看板(Host health status boards)。每台主机对应一张卡片,显示错误率、请求数,以及用颜色区分的“正常”或“警告”标记,让需要关注的服务一目了然。
- 流程图和桑基图(Flowcharts and Sankey diagrams)。追踪流量如何从目标区域经过你的边缘网络和数据中心,到达笔记本电脑、手机和台式电脑,并显示每一跳的请求数。
- 漏斗图(Funnels)。追踪用户从首次访问到结账的过程,显示用户在哪一步流失。
- 仪表板横幅(Dashboard banners)。展示你的徽标、品牌配色和动画图片。自定义面板中的徽标或图片需要以内联 SVG 代码、CSS 形状或 Unicode 字符的形式嵌入,这样当你将仪表板导出到其他空间或部署时,它们也会一并导出。
- 计分卡和摘要卡片(Scorecards and summary cards)。在同一个区块中展示多项指标,并添加阈值或标记,还可以通过选项卡切换视图。
- 带条件格式的表格(Tables with conditional formatting)。根据每行的值调整颜色、图标和突出显示效果。
仪表板上显示两个自定义面板:上方是主机运行状况卡片,下方是动态数据流图。
在仪表板上添加可视化内容有四种方式,自定义面板是其中一种。下表比较了这四种方式:
你还可以使用自定义面板,直接在聊天中将调查结果转换为更丰富的可视化内容。将这些内容保存为仪表板后,就可以与你的团队共享:
或者创建清晰的演示文稿,汇总上周的数据,便于汇报:
你甚至可以做个带动画的一级方程式赛车仪表板,自娱自乐:
自定义面板如何响应筛选条件、时间范围和主题
与仪表板上的其他面板一样,包含 ES|QL 查询的自定义面板会响应时间选择器、Kibana 查询语言(Kibana Query Language,KQL)查询栏、筛选标签和控件。
自定义面板也会沿用你的 Kibana 主题。除非你另有指定,否则它们会使用与 Kibana 其他部分相同的颜色、间距和字体,并适应浅色和深色模式。
自定义面板的实现原理
自定义面板由两部分组成:用于获取数据的 ES|QL 查询,以及决定呈现效果的 HTML 和 CSS 模板。查询返回行和列,模板再将这些数据呈现为卡片、标记、流程图或横幅。
第一个技术难题是让 agent 生成与数据匹配的模板。如果让 模型 猜测有哪些字段,它就可能编造不存在的列名。因此,在模型编写模板之前,Kibana 会先执行查询,将列名、列类型和几行示例数据提供给模型,让它根据实际查询结果编写模板。如果你之后只修改面板的外观,Kibana 会跳过这一步,直接调整现有模板。如果你修改查询,Kibana 会重新对数据采样。
为什么自定义面板无须在每次加载仪表板时重新生成
最初,我们把提示词和面板一起保存,让人工智能在每次加载仪表板时生成面板。为了让结果保持一致,人工智能会先把简短的提示词扩写成一段长得多的说明,涵盖布局、颜色以及每个字段的用法。这样做仍然无法保证一致性。模型很少连续两次给出相同的答案,因此你与同事共享仪表板后,对方看到的面板可能和你创建的不同。 微调 时也有同样的问题:你只要求改一个小地方,面板的其他部分也会跟着变化。
我们试过用缓存解决这个问题,让每个面板只生成一次,之后重复使用。缓存方案很快变得复杂,仍然无法保证两个人看到同一个面板。于是我们调整了设计。现在,人工智能只在你聊天时运行,生成的结果会作为模板保存在仪表板中。
自定义面板如何在沙箱中呈现 HTML
从设计之初,我们就考虑了如何安全地呈现不受信任的 HTML。自定义面板可以包含任意 HTML,因此无论由谁或什么工具生成,我们都将每个面板视为不受信任的内容。这样就可以安全地让 agent 编写面板。每个面板都在沙箱中呈现。沙箱会阻止脚本和外部资源,并移除指向 Kibana 仪表板和发现(Discover)页面以外的链接。内容在显示前会经过净化处理。面板仅能呈现内容,无法执行代码、访问网络或接触浏览器会话中的其他内容。因此,生成的面板的权限范围与 Markdown 面板相同。
创建你的第一个自定义面板
自定义面板现已在 Elastic Cloud 无服务器版和采用基础许可证的 Elastic 9.6 中提供。要通过聊天生成面板,请在你的部署或项目中设置 Elastic AI agent。详情请参阅 自定义面板文档(custom panels documentation)或观看这段 视频教程(video tutorial)。我们想看看你做出了什么,欢迎向我们反馈。
原文:Kibana custom panels: Any dashboard visual from a prompt | Elasticsearch Labs
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
By Teresa Alvarez Soler and Stratoula Kalafateli from Elastic
The AI agent writes ES|QL queries and HTML templates, then saves custom panels. Everyone who opens the dashboard sees the same rendered output.
Observe, protect, and search your data with one unified solution. From app monitoring to threat detection, Kibana has you covered for your critical scenarios. Start your free 14-day trial now.
With Custom panels, you can add any visual content built with HTML and CSS to your Kibana dashboards, including host health cards, request flow diagrams, funnels, and branded banners. Kibana's built-in visualizations and panel types cover most dashboard needs. When a team requires visuals beyond what's predefined, custom panels can fill the gap.
Simply describe the effect you want, and the Elastic AI Agent will write an Elasticsearch Query Language (ES|QL) query and generate a template that matches your data. Once generated, the AI doesn't need to run again. Kibana saves the template in the dashboard and populates it with live query results every time it loads, so everyone who opens the dashboard sees the panel you created. Custom panels are supported on Elastic Cloud Serverless and in Elastic 9.6 with a Basic license.
How to Create a Custom Panel with a Prompt
After opening a dashboard, select the AI Agent in the top bar. A chat window opens in the sidebar and is already attached to the current dashboard. Then enter your request, such as:
- Create a custom panel with a health status card for each host.
- Create a custom panel that shows how data flows across the services.
- Create a banner with an animated image.
If you don't mention "custom panel" in the prompt, the agent first checks whether standard Kibana visualizations meet your needs, then checks whether Vega visualizations are suitable. Only when neither approach works does the agent create a custom panel.
If the panel requires live data, the agent writes an ES|QL query and builds an HTML template based on the columns returned by the query. You can see the panel render directly on the dashboard. If you're satisfied, save the dashboard. If you'd like to refine further, you can continue modifying in the chat or manually edit the HTML and ES|QL. Each chat reply preserves its own version. If you prefer an earlier version, you can select Preview on that reply's card to review it again.
How to Create a Custom Panel Without Using the AI Agent
You can also start from the dashboard editor. Select Add from the top menu, then select Custom:
You can choose to have the Elastic AI Agent generate the panel, write the HTML yourself, or paste code generated by an external agent. Using the Elastic AI Agent is faster because it also writes the ES|QL query needed for the panel.
What Can Custom Panels Do?
Custom panels support any layout that HTML and CSS can achieve. Our team has had the agent create the following:
- Host health status boards. Each host gets a card showing error rates, request counts, and "OK" or "Warning" indicators color-coded so at-a-glance issues stand out.
- Flowcharts and Sankey diagrams. Track traffic as it moves from target regions through your edge network and data centers to laptops, phones, and desktops, showing request counts at each hop.
- Funnels. Track users from first visit through to checkout, revealing where users drop off at each step.
- Dashboard banners. Display your logo, brand colors, and animated images. Logos or images customized within panels must be embedded as inline SVG code, CSS shapes, or Unicode characters so they export along with your dashboard when you share it with other spaces or deploy it.
- Scorecards and summary cards. Display multiple metrics in the same block, add thresholds or annotations, and switch views using tabs.
- Tables with conditional formatting. Adjust colors, icons, and highlighting based on the values in each row.
Two custom panels are shown on the dashboard: a host health card on top and a dynamic data flow diagram below.
There are four ways to add visual content to your dashboard, and custom panels are one of them. The table below compares the four approaches:
You can also use custom panels to transform search results into richer visualizations directly in chat. Once saved as a dashboard, you can share them with your team:
Or create clear presentations summarizing last week's data for reporting:
You can even build an animated Formula 1 dashboard for fun:
How custom panels respond to filters, time ranges, and themes
Like other panels on a dashboard, custom panels containing ES|QL queries respond to the time picker, Kibana Query Language (KQL) query bar, filter tags, and controls.
Custom panels also follow your Kibana theme. Unless specified otherwise, they use the same colors, spacing, and fonts as the rest of Kibana, and adapt to light and dark mode.
How custom panels work under the hood
Custom panels consist of two parts: an ES|QL query that retrieves data, and an HTML and CSS template that determines how it is rendered. The query returns rows and columns, and the template presents that data as cards, badges, flow diagrams, or banners.
The first technical challenge was getting the agent to generate templates that match the data. If we let the model guess what fields exist, it might fabricate column names that don't exist. So before writing the template, Kibana executes the query first and provides the model with column names, column types, and several rows of sample data so it can write the template based on actual query results. If you later modify only the panel's appearance, Kibana skips this step and adjusts the existing template directly. If you modify the query, Kibana re-samples the data.
Why custom panels do not need to be regenerated every time a dashboard loads
Initially, we saved prompts alongside panels and had the AI generate panels every time a dashboard loaded. To maintain consistency, the AI would first expand a short prompt into a much longer description covering layout, colors, and the usage of each field. This still did not guarantee consistency. Models rarely give the exact same answer twice, so after you share a dashboard with a colleague, the panels they see may differ from what you created. The same issue occurs during fine-tuning: if you ask for a small change, other parts of the panel also shift.
We tried solving this with caching, generating each panel once and then reusing it. The caching approach quickly became complex and still could not guarantee two people see the same panel. We adjusted our design. Now, the AI runs only while you are chatting, and the generated result is saved as a template in the dashboard.
How custom panels render HTML in a sandbox
From the start, we considered how to safely render untrusted HTML. Custom panels can contain arbitrary HTML, so regardless of who or what tool generates them, we treat each panel as untrusted content. This allows the agent to author panels safely. Each panel is rendered in a sandbox. The sandbox blocks scripts and external resources, and removes links pointing anywhere outside of Kibana dashboards and Discover pages. Content is sanitized before display. Panels can render content but cannot execute code, access the network, or interact with other content in the browser session. Therefore, generated panels have the same permission scope as Markdown panels.
Create your first custom panel
Custom panels are now available in Elastic Cloud Serverless and Elastic 9.6 with a basic license. To generate panels via chat, set up the Elastic AI agent in your deployment or project. For details, refer to the custom panels documentation or watch this video tutorial. We want to see what you build—feel free to share your feedback.
Original: Kibana custom panels: Any dashboard visual from a prompt | Elasticsearch Labs
Auto-fetched and translated by AI Atlas. All rights belong to the original author.