推送自定义指标时 NotAuthorizedOrNotFound

NotAuthorizedOrNotFound when pushing custom metric

当我尝试使用 Oracle 云 CLI 将自定义指标推送到 Oracle 云监控服务时,我收到以下错误:

ServiceError:
{
    "code": "NotAuthorizedOrNotFound",
    "message": "Authorization failed or requested resource not found.",
    "opc-request-id": "request id",
    "status": 404
}

使用管理员帐户和使用具有监控权限的实例主体时会出现这种情况。

这是我推送到监控服务的JSON:

[
    {
        "namespace": "myFirstNamespace",
        "compartmentId": "tenant id",
        "resourceGroup": "myFirstResourceGroup",
        "name": "successRate",
        "dimensions": {
            "resourceId": "ocid1.exampleresource.region1.phx.exampleuniqueID",
            "appName": "myAppA"
        },
        "metadata": {
            "unit": "percent",
            "displayName": "MyAppA Success Rate"
        },
        "datapoints": [
            {
                "timestamp": "2021-06-01T22:19:20Z",
                "value": 83.0
            }
        ]
    }
]

我使用的 CLI 命令是:

oci monitoring metric-data post --metric-data file://metric-data.json

看起来像是一些授权问题。请交叉检查实例原则是否分配了所有必需的权限。请查看此文档 Publishing Custom Metrics and Overview of Monitoring

OCI CLI 命令应该是:

oci monitoring metric-data post --metric-data file://metric-data.json --endpoint https://telemetry-ingestion.{{ region }}.oraclecloud.com

{{ region }} 替换为您所在的地区。

需要添加--endpoint https://telemetry-ingestion.{{ region }}.oraclecloud.com参数。