Agent Skillsccfos/nightingale › query-datasource

query-datasource

GitHub

在夜莺监控环境中查询各类数据源(Prometheus、ES、Loki、SQL等)的指标和日志。通过登录获取Token,列出可用数据源,根据类型执行查询并格式化输出结果。

aiagent/skill/embedded/builtin/query-datasource/SKILL.md ccfos/nightingale

Trigger Scenarios

查询监控指标 搜索日志 运行PromQL或SQL查询

Install

npx skills add ccfos/nightingale --skill query-datasource -g -y
More Options

Non-standard path

npx skills add https://github.com/ccfos/nightingale/tree/main/aiagent/skill/embedded/builtin/query-datasource -g -y

Use without installing

npx skills use ccfos/nightingale@query-datasource

指定 Agent (Claude Code)

npx skills add ccfos/nightingale --skill query-datasource -a claude-code -g -y

安装 repo 全部 skill

npx skills add ccfos/nightingale --all -g -y

预览 repo 内 skill

npx skills add ccfos/nightingale --list

SKILL.md

Frontmatter
{
    "name": "query-datasource",
    "tags": [
        "internal"
    ],
    "description": "Query data from various datasources in a Nightingale (n9e) environment. Supports Prometheus metric queries, Elasticsearch\/Loki log queries, and SQL datasource queries such as ClickHouse\/MySQL\/PostgreSQL\/TDengine\/Doris. Use when the user asks to query metrics, view monitoring data, search logs, or run PromQL or SQL queries."
}

Nightingale (n9e) Query Datasource Data

Query monitoring metrics, logs, and time-series data from various datasources on the Nightingale monitoring platform.

Based on the datasource type the user needs, read the corresponding file under the datasources/ directory to get the query method and parameter format:


Prerequisites

The user needs to provide:

  • n9e address: e.g. http://<n9e-host>:<port>
  • Username/password: e.g. <username>/<password>
  • Query requirement description: e.g. "query CPU usage over the last hour", "search logs containing error"

If the user has not provided the above information, use the AskUserQuestion tool to ask.


Execution Steps

Step 1: Log in to obtain a Token

POST /api/n9e/auth/login
Content-Type: application/json
Body: {"username":"<username>","password":"<password>"}

Extract dat.access_token from the response, and include Authorization: Bearer <token> in all subsequent requests.

Step 2: Query available datasources

Retrieve the datasource list to determine the datasource ID and type to query:

POST /api/n9e/datasource/list
Authorization: Bearer <token>
Content-Type: application/json
Body: {}

Each datasource in the response contains id, name, and plugin_type.

If the user has not specified a datasource, use the AskUserQuestion tool to display the available datasources and let the user choose.

Step 3: Run the query based on the datasource type

Based on the datasource's plugin_type, read the corresponding datasources/*.md file to get the query API and parameter format.

Step 4: Format the output

Present the query result to the user as a readable Markdown table or list.


Datasource Type Quick Reference

plugin_type Datasource Query Language Use Case Reference File
prometheus Prometheus / VictoriaMetrics PromQL Metric/time-series query prometheus.md
elasticsearch Elasticsearch ES DSL / Lucene Log query elasticsearch.md
opensearch OpenSearch ES DSL / Lucene Log query opensearch.md
loki Loki LogQL Log query loki.md
ck ClickHouse SQL Metric/log query clickhouse.md
mysql MySQL SQL Metric query mysql.md
pgsql PostgreSQL SQL Metric query pgsql.md
tdengine TDengine SQL Time-series query tdengine.md
doris Doris SQL Log query doris.md
victorialogs VictoriaLogs LogsQL Log query victorialogs.md

Generic Proxy API

All datasources can access their native APIs through the generic proxy:

<ANY_METHOD> /api/n9e/proxy/<datasource_id>/<native API path>
Authorization: Bearer <token>

For example:

  • Prometheus: /api/n9e/proxy/1/api/v1/query?query=up
  • Elasticsearch: /api/n9e/proxy/2/_cat/health
  • Loki: /api/n9e/proxy/3/loki/api/v1/labels

Generic Time-Series Query API

All datasources (except Prometheus) can use the unified time-series query endpoint:

POST /api/n9e/ds-query
Authorization: Bearer <token>
Content-Type: application/json
{
  "cate": "<plugin_type>",
  "datasource_id": 1,
  "query": [<query object>]
}

Generic log query endpoint:

POST /api/n9e/logs-query
Authorization: Bearer <token>
Content-Type: application/json
{
  "cate": "<plugin_type>",
  "datasource_id": 1,
  "query": [<query object>]
}

The exact structure of the query object varies by datasource type; see each datasource file for details.


Generic Metadata API for SQL-type Datasources

ClickHouse, MySQL, PostgreSQL, and Doris share the following metadata query endpoints:

POST /api/n9e/db-databases     // List databases
POST /api/n9e/db-tables        // List tables
POST /api/n9e/db-desc-table    // View table structure

TDengine uses dedicated endpoints:

POST /api/n9e/tdengine-databases
POST /api/n9e/tdengine-tables
POST /api/n9e/tdengine-columns

Key Considerations

  1. Query the datasource list first to get the ID: All queries require a datasource_id; obtain it first via POST /api/n9e/datasource/list
  2. SQL queries are read-only: SQL-type datasources prohibit write operations such as CREATE, INSERT, UPDATE, DELETE, ALTER, DROP
  3. Time variables: In SQL queries, use $from and $to to represent the time range; the system replaces them automatically
  4. keys field: Time-series queries must specify valueKey (numeric column) and labelKey (grouping column); separate multiple columns with spaces
  5. Unified response format: All API responses are wrapped in a {"dat": <data>} structure

Version History

  • 0594cf9 Current 2026-08-20 19:44

Same Skill Collection

aiagent/skill/embedded/builtin/analyze-dashboard/SKILL.md
aiagent/skill/embedded/builtin/create-dashboard/SKILL.md
aiagent/skill/embedded/builtin/generate-message-template/SKILL.md
aiagent/skill/embedded/builtin/host-health-diagnose/SKILL.md
aiagent/skill/embedded/builtin/modify-dashboard/SKILL.md
aiagent/skill/embedded/builtin/ops-troubleshooting/SKILL.md
aiagent/skill/embedded/builtin/query-alert-events/SKILL.md
aiagent/skill/embedded/builtin/skill-creator/SKILL.md
aiagent/skill/embedded/builtin/sql-generator/SKILL.md
aiagent/skill/embedded/builtin/alert-mute-copilot/SKILL.md
aiagent/skill/embedded/builtin/alert-rule-troubleshoot/SKILL.md
aiagent/skill/embedded/builtin/alert-subscribe-copilot/SKILL.md
aiagent/skill/embedded/builtin/categraf-deploy-guide/SKILL.md
aiagent/skill/embedded/builtin/create-alert-rule/SKILL.md
aiagent/skill/embedded/builtin/doc-qa/SKILL.md
aiagent/skill/embedded/builtin/host-onboard-diagnose/SKILL.md
aiagent/skill/embedded/builtin/import-prom-rule/SKILL.md
aiagent/skill/embedded/builtin/modify-task-tpl/SKILL.md
aiagent/skill/embedded/builtin/notify-channel-copilot/SKILL.md
aiagent/skill/embedded/builtin/notify-rule-copilot/SKILL.md
aiagent/skill/embedded/builtin/promql-generator/SKILL.md

Metadata

Files
0
Version
8362cbe
Hash
6fc83033
Indexed
2026-08-20 19:44

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-01 20:01
浙ICP备14020137号-1 $bản đồ khách truy cập$