要将 Prometheus API 中的 node_systemd_unit_state 监控数据导出到 Excel,您可以使用以下步骤:
- 首先,使用 curl 或其他工具从 Prometheus API 获取数据。例如,以下命令将返回 node_systemd_unit_state 的所有指标值:
curl 'http://<prometheus-server>:9090/api/v1/query?query=node_systemd_unit_state'
- 将返回的 JSON 数据转换为 Excel 格式。这可以通过编写脚本或使用在线转换工具来完成。以下是一个示例 Python 脚本,它使用 pandas 库将 JSON 数据转换为 Excel 文件:
import pandas as pd
import requests
# Get data from Prometheus API
url = 'http://<prometheus-server>:9090/api/v1/query?query=node_systemd_unit_state'
response = requests.get(url).json()
# Convert to pandas DataFrame
data = response['data']['result']
df = pd.DataFrame([{'name': d['metric']['unit'], 'state': d['value'][1]} for d in data])
# Export to Excel file
df.to_excel('node_systemd_unit_state.xlsx', index=False)
- 运行脚本并查看生成的 Excel 文件。该文件应包含两列:名称和状态。
请注意,上述示例仅适用于 node_systemd_unit_state 指标,并且需要安装 pandas 库才能运行。如果您想导出其他指标或不想使用 Python,请尝试寻找适合您需求的库或工具。




