[Official Events] #MCP 探索家# 通过大模型操作Grafana等探索
Tofloor
poster avatar
周维
deepin
2025-08-07 10:11
Author

背景:日常作为一位运维工程师,经常在思考AI怎么结合到日常工作中来,最近随着各类中间件MCP server的推出感觉可以实现很多有意思的操作。

本文简单介绍下如何使用大模型通过mcp服务进行Grafana的相关操作。

环境介绍:

  • 操作系统:macOS15.6
  • agent:chatbox
  • 模型:deepseek
  • mcp:mcp-grafana

当前mcp-server版本服务支持的能力如下

Tools

datasources:query
Tool Category Description Required RBAC Permissions Required Scopes
list_teams Admin List all teams teams:read teams:* or teams:id:1
list_users_by_org Admin List all users in an organization users:read global.users:* or global.users:id:123
search_dashboards Search Search for dashboards dashboards:read dashboards:* or dashboards:uid:abc123
get_dashboard_by_uid Dashboard Get a dashboard by uid dashboards:read dashboards:uid:abc123
update_dashboard Dashboard Update or create a new dashboard dashboards:create, dashboards:write dashboards:*, folders:* or folders:uid:xyz789
get_dashboard_panel_queries Dashboard Get panel title, queries, datasource UID and type from a dashboard dashboards:read dashboards:uid:abc123
list_datasources Datasources List datasources datasources:read datasources:*
get_datasource_by_uid Datasources Get a datasource by uid datasources:read datasources:uid:prometheus-uid
get_datasource_by_name Datasources Get a datasource by name datasources:read datasources:* or datasources:uid:loki-uid
query_prometheus Prometheus Execute a query against a Prometheus datasource datasources:query datasources:uid:prometheus-uid
Prometheus datasources:uid:prometheus-uid
list_prometheus_metric_names Prometheus List available metric names datasources:query datasources:uid:prometheus-uid
list_prometheus_label_names Prometheus List label names matching a selector datasources:query datasources:uid:prometheus-uid
list_prometheus_label_values Prometheus List values for a specific label datasources:query datasources:uid:prometheus-uid
list_incidents Incident List incidents in Grafana Incident Viewer role N/A
create_incident Incident Create an incident in Grafana Incident Editor role N/A
add_activity_to_incident Incident Add an activity item to an incident in Grafana Incident Editor role N/A
get_incident Incident Get a single incident by ID Viewer role N/A
query_loki_logs Loki Query and retrieve logs using LogQL (either log or metric queries) datasources:query datasources:uid:loki-uid
list_loki_label_names Loki List all available label names in logs datasources:query datasources:uid:loki-uid
list_loki_label_values Loki List values for a specific log label datasources:query datasources:uid:loki-uid
query_loki_stats Loki Get statistics about log streams datasources:query datasources:uid:loki-uid
list_alert_rules Alerting List alert rules alert.rules:read folders:* or folders:uid:alerts-folder
get_alert_rule_by_uid Alerting Get alert rule by UID alert.rules:read folders:uid:alerts-folder
list_contact_points Alerting List notification contact points alert.notifications:read Global scope
list_oncall_schedules OnCall List schedules from Grafana OnCall grafana-oncall-app.schedules:read Plugin-specific scopes
get_oncall_shift OnCall Get details for a specific OnCall shift grafana-oncall-app.schedules:read Plugin-specific scopes
get_current_oncall_users OnCall Get users currently on-call for a specific schedule grafana-oncall-app.schedules:read Plugin-specific scopes
list_oncall_teams OnCall List teams from Grafana OnCall grafana-oncall-app.user-settings:read Plugin-specific scopes
list_oncall_users OnCall List users from Grafana OnCall grafana-oncall-app.user-settings:read Plugin-specific scopes
get_sift_investigation Sift Retrieve an existing Sift investigation by its UUID Viewer role N/A
get_sift_analysis Sift Retrieve a specific analysis from a Sift investigation Viewer role N/A
list_sift_investigations Sift Retrieve a list of Sift investigations with an optional limit Viewer role N/A
find_error_pattern_logs Sift Finds elevated error patterns in Loki logs. Editor role N/A
find_slow_requests Sift Finds slow requests from the relevant tempo datasources. Editor role N/A
list_pyroscope_label_names Pyroscope List label names matching a selector datasources:query datasources:uid:pyroscope-uid
list_pyroscope_label_values Pyroscope List label values matching a selector for a label name datasources:query datasources:uid:pyroscope-uid
list_pyroscope_profile_types Pyroscope List available profile types datasources:query datasources:uid:pyroscope-uid
fetch_pyroscope_profile Pyroscope Fetches a profile in DOT format for analysis datasources:query datasources:uid:pyroscope-uid
get_assertions Asserts Get assertion summary for a given entity Plugin-specific permissions Plugin-specific scopes
generate_deeplink Navigation Generate accurate deeplink URLs for Grafana resources None (read-only URL generation) N/A

更多的介绍和细节可以去看官方的git地址:MCP server for Grafana

整体的部署操作相对简单:

  1. 官方地址下载系统需要的软件包:

image.png

我用的macOS m4的芯片所以下载了darwin的 arm的包,其他平台的同理

  1. 在Grafana中创建需要的api key,我用的版本是v10.4.2位置在 menu -> administrator -> users and access -> service accounts中

    image.png

    创建用户后,生成 account token

image.png

注意该token只会显示一次,记得保存下来

  1. 配置mcp服务

我使用的是chatbox,这个比较简单,如图添加mcp服务

image.png

image.png

其中类型选择本地:信息就是刚才下载的mcp-grafana的可执行文件的地址

环境变量中要配置两个参数:

  • GRAFANA_URL:是你的grafana的地址
  • GRAFANA_API_KEY:是刚才生成的 account token的值

然后测试,保存

  1. 配置模型

image.png

chatbox本身支持市面上绝大多数的模型提供商,也支持自建的ollama服务,这里我用的deepseek,配置比较简单, 填写上key直接使用即可

现在就可以通过对话进行一些grafana的查询操作等:

image.png

image.png

image.png

通过图片可以看到我其实也添加了gitlab iterm的mcp用来进行一些项目代码,等测试操作

不过iterm这个与终端交互让我感觉蠢蠢的,着实感觉就是可以,但是没必要中间来这么一道,不过也在思考比如通过终端,或者jenkins类的结合,是否可以通过与模型对话,完成项目部署,程序发布等操作,还在探索

有任何不对或不妥之处 欢迎大家讨论

Reply Favorite View the author
All Replies
芝士堡
deepin
2025-08-07 10:41
#1

这个离生产力很近了

Reply View the author