使用HTTP API地址对接Grafana或自建应用中接入Prometheus数据 步骤四:接入自建Grafana(AccessKey接入) 1. 配置Grafana数据源。 1. 以管理员账号登录本地Grafana系统。 2. 点击页面左上角的图标。 3. 在左侧导航栏中选择Configuration > Data Sources。说明:仅管理员可以看到此菜单。 4. 在Data Sources页签上单击+ Add new data source。 5. 在Add data source页面上单击Prometheus。 6. 在Settings页签的Name字段中输入自定义的名称,在Prometheus server URL字段中粘贴上文【步骤一:获取HTTP API地址】中获得的HTTP API地址。 7. 选中Auth中的Basic auth,User和Password输入在【步骤一】中获取的AccessKey和AccessKey Secret。 8. 单击页签底部的Save & Test。 2. 验证结果。 参考【步骤三】中的验证。 步骤五:获取Prometheus监控数据(token接入示例) 调用Prometheus监控数据的请求示例如下。更多使用HTTP API获取Prometheus监控数据的操作,请参见开源版Prometheus HTTP API。 plaintext GET {HTTP API}/api/v1/query Accept: application/json ContentType: application/json Authorization: {Token} { "query":"armsprometheustargetintervallengthsecondssum", "time":"1635302655", "timeout":"1000" } 说明 {HTTP API}和{Token}请替换为上文【步骤一:获取HTTP API地址】中获取的HTTP API和鉴权Token。 返回示例: plaintext { "status": "success", "data": { "resultType": "vector", "result": [ { "metric": { "name": "armsprometheustargetintervallengthsecondssum", "instance": "localhost:9335", "interval": "15s", "job": "armsprom/kubelet/1" }, "value": [ 1635302655, "146655.24420603" ] }, { "metric": { "name": "armsprometheustargetintervallengthsecondssum", "instance": "localhost:9335", "interval": "30s", "job": "armsprom/kubelet/1" }, "value": [ 1635302655, "879810.747346" ] }, { "metric": { "name": "armsprometheustargetintervallengthsecondssum", "instance": "localhost:9335", "interval": "20s", "job": "armsprom/kubelet/1" }, "value": [ 1635302655, "73320.13578499" ] } ] } }