Loading
close

调用方式

time 更新时间:2024-08-20 19:36:26

可观测服务支持 Prometheus 原生的查询语言 PromQL,允许即时查询以及范围查询监控数据。查询后的结果可以显示为各式图表(对接 Grafana 等),也可以通过联邦机制对接给其他监控系统。

产品化接口

前提条件

  • 签名机制使用 Token 认证,需提供项目用户身份验证生成的 Project 级别的 Token;
  • 服务地址: emla.openstack.svc.cluster.local (示例使用默认根域名 openstack.svc.cluster.local)。

指标查询-POST(推荐)

URI

POST /apis/monitoring/v1/projects/<project_id>/series/query

请求参数

名称 输入 类型 是否必选 描述
project_id Path string 项目id
all_tenants Query bool 云管权限下字段,true为获取所有项目信息,false为获取云管项目信息
expr Body string PromQL格式的查询表达式
start Body string 监控数据的开始时间,时间戳格式,例如:1677827400,表示时间点 2023-03-03 15:10:00.000000000+08:00
end Body string 监控数据的结束时间,时间戳格式,例如:1677831000,表示时间点 2023-03-03 16:10:00.000000000+08:00
step Body string 与 start end 同时使用,在开始时间和结束时间范围内以固定的时间间隔检索指标数据,格式 [0-9]+[smhdwy],默认 10m,10分钟
time Body string 检索指定时间点的指标数据,时间戳格式,例如:1677831000,表示时间点 2023-03-03 16:10:00.000000000+08:00,默认 当前时间
# 示例1-查询时间点指标
curl -s -XPOST 'http://emla.openstack.svc.cluster.local/apis/monitoring/v1/projects/1100e312c9df4567a23806000ebee655/series/query?all_tenants=true' -d '{"expr": "kube_namespace_labels", "time": "1710915079"}' -H 'X-Auth-Token: gAAAAABl-n0ncMXi29UwKn_GRYkmuJDiuBDg3vTIG0XI0mv0w05z3jtji2AzLlO3mhBK95krQMdsWlbmaZM6FMOCFVrqktUG8soxa6dgxdkwzYG6NJ82TnXvWwR6C42xaGh2f6ftMJ4QUUbfoT44oE5ullnUnL4fNg' -H 'Content-Type: application/json'

# 示例2-查询时间段指标
curl -s -XPOST 'http://emla.openstack.svc.cluster.local/apis/monitoring/v1/projects/1100e312c9df4567a23806000ebee655/series/query?all_tenants=true' -d '{"expr": "kube_namespace_labels", "start": "1710915079", "end": "1710915139", "step": "60s"}' -H 'X-Auth-Token: gAAAAABl-n0ncMXi29UwKn_GRYkmuJDiuBDg3vTIG0XI0mv0w05z3jtji2AzLlO3mhBK95krQMdsWlbmaZM6FMOCFVrqktUG8soxa6dgxdkwzYG6NJ82TnXvWwR6C42xaGh2f6ftMJ4QUUbfoT44oE5ullnUnL4fNg' -H 'Content-Type: application/json'

响应参数

查询时间点指标

名称 类型 描述
code int 接口状态
error string 当 code 为 4/5 开头,显示error信息
data.resultType string 返回指标数据类型,vector或matrix
data.result list 指标数据列表
data.result[$i].metric dict 指标标签
data.result[$i].value list vector指标类型数据,查询指定时间点时才返回的字段,每个指标数据格式:list[0] 时间戳,list[1] 数值
{
    "code": 200,
    "error": "",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest1",
                    "namespace": "emlatest1",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "value": [
                    1677827400,
                    "1"
                ]
            },
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest2",
                    "namespace": "emlatest2",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "value": [
                    1677827400,
                    "1"
                ]
            }
        ]
    }
}

查询时间段指标

名称 类型 描述
code int 接口状态
error string 当 code 为 4/5 开头,显示error信息
data.resultType string 返回指标数据类型,vector或matrix
data.result list 指标数据列表
data.result[$i].metric dict 指标标签
data.result[$i].value list vector指标类型数据,查询指定时间点时才返回的字段,每个指标数据格式:list[0] 时间戳,list[1] 数值
{
    "code": 200,
    "error": "",
    "data": {
        "resultType": "matrix",
        "result": [
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest1",
                    "namespace": "emlatest1",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "values": [
                    [
                        1677827400,
                        "1"
                    ],
                    [
                        1677828000,
                        "1"
                    ],
                    [
                        1677828600,
                        "1"
                    ],
                    [
                        1677829200,
                        "1"
                    ],
                    [
                        1677829800,
                        "1"
                    ],
                    [
                        1677830400,
                        "1"
                    ],
                    [
                        1677831000,
                        "1"
                    ]
                ]
            },
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest2",
                    "namespace": "emlatest2",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "values": [
                    [
                        1677827400,
                        "1"
                    ],
                    [
                        1677828000,
                        "1"
                    ],
                    [
                        1677828600,
                        "1"
                    ],
                    [
                        1677829200,
                        "1"
                    ],
                    [
                        1677829800,
                        "1"
                    ],
                    [
                        1677830400,
                        "1"
                    ],
                    [
                        1677831000,
                        "1"
                    ]
                ]
            }
        ]
    }
}

指标查询-GET

URI

GET /apis/monitoring/v1/projects/<project_id>/series/query

请求参数

名称 输入 类型 是否必选 描述
project_id Path string 项目id
all_tenants Query bool 云管权限下字段,true为获取所有项目信息,false为获取云管项目信息
expr Query string PromQL格式的查询表达式
start Query string 监控数据的开始时间,时间戳格式,例如:1677827400,表示时间点 2023-03-03 15:10:00.000000000+08:00
end Query string 监控数据的结束时间,时间戳格式,例如:1677831000,表示时间点 2023-03-03 16:10:00.000000000+08:00
step Query string 与 start end 同时使用,在开始时间和结束时间范围内以固定的时间间隔检索指标数据,格式 [0-9]+[smhdwy],默认 10m,10分钟
time Query string 检索指定时间点的指标数据,时间戳格式,例如:1677831000,表示时间点 2023-03-03 16:10:00.000000000+08:00,默认 当前时间
# 示例1-查询时间点指标
curl -s -XGET 'http://emla.openstack.svc.cluster.local/apis/monitoring/v1/projects/1100e312c9df4567a23806000ebee655/series/query?all_tenants=true&expr=kube_namespace_labels&time=1710915079' -H 'X-Auth-Token: gAAAAABl-n0ncMXi29UwKn_GRYkmuJDiuBDg3vTIG0XI0mv0w05z3jtji2AzLlO3mhBK95krQMdsWlbmaZM6FMOCFVrqktUG8soxa6dgxdkwzYG6NJ82TnXvWwR6C42xaGh2f6ftMJ4QUUbfoT44oE5ullnUnL4fNg' -H 'Content-Type: application/json'

# 示例2-查询时间段指标
curl -s -XGET 'http://emla.openstack.svc.cluster.local/apis/monitoring/v1/projects/1100e312c9df4567a23806000ebee655/series/query?all_tenants=true&expr=kube_namespace_labels&start=1710915079&end=1710915139&step=60s' -H 'X-Auth-Token: gAAAAABl-n0ncMXi29UwKn_GRYkmuJDiuBDg3vTIG0XI0mv0w05z3jtji2AzLlO3mhBK95krQMdsWlbmaZM6FMOCFVrqktUG8soxa6dgxdkwzYG6NJ82TnXvWwR6C42xaGh2f6ftMJ4QUUbfoT44oE5ullnUnL4fNg' -H 'Content-Type: application/json'

响应参数

查询时间点指标

名称 类型 描述
code int 接口状态
error string 当 code 为 4/5 开头,显示error信息
data.resultType string 返回指标数据类型,vector或matrix
data.result list 指标数据列表
data.result[$i].metric dict 指标标签
data.result[$i].value list vector指标类型数据,查询指定时间点时才返回的字段,每个指标数据格式:list[0] 时间戳,list[1] 数值
{
    "code": 200,
    "error": "",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest1",
                    "namespace": "emlatest1",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "value": [
                    1677827400,
                    "1"
                ]
            },
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest2",
                    "namespace": "emlatest2",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "value": [
                    1677827400,
                    "1"
                ]
            }
        ]
    }
}

查询时间段指标

名称 类型 描述
code int 接口状态
error string 当 code 为 4/5 开头,显示error信息
data.resultType string 返回指标数据类型,vector或matrix
data.result list 指标数据列表
data.result[$i].metric dict 指标标签
data.result[$i].value list vector指标类型数据,查询指定时间点时才返回的字段,每个指标数据格式:list[0] 时间戳,list[1] 数值
{
    "code": 200,
    "error": "",
    "data": {
        "resultType": "matrix",
        "result": [
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest1",
                    "namespace": "emlatest1",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "values": [
                    [
                        1677827400,
                        "1"
                    ],
                    [
                        1677828000,
                        "1"
                    ],
                    [
                        1677828600,
                        "1"
                    ],
                    [
                        1677829200,
                        "1"
                    ],
                    [
                        1677829800,
                        "1"
                    ],
                    [
                        1677830400,
                        "1"
                    ],
                    [
                        1677831000,
                        "1"
                    ]
                ]
            },
            {
                "metric": {
                    "__name__": "kube_namespace_labels",
                    "application": "kube-state-metrics",
                    "company": "nanjing_3_12",
                    "component": "exporter",
                    "endpoint": "http",
                    "instance": "kube-state-metrics",
                    "job": "kube-state-metrics",
                    "kubernetes_name": "kube-state-metrics",
                    "kubernetes_namespace": "openstack",
                    "label_capsule_clastix_io_tenant": "49e51702c0bd4b6388697aa386ae349f",
                    "label_emla_io_used_by": "custom",
                    "label_managed_es_io_resource": "namespace",
                    "label_name": "emlatest2",
                    "namespace": "emlatest2",
                    "project": "nanjing_3_12",
                    "public_vip": "100.100.4.10",
                    "release_group": "prometheus",
                    "service": "kube-state-metrics"
                },
                "values": [
                    [
                        1677827400,
                        "1"
                    ],
                    [
                        1677828000,
                        "1"
                    ],
                    [
                        1677828600,
                        "1"
                    ],
                    [
                        1677829200,
                        "1"
                    ],
                    [
                        1677829800,
                        "1"
                    ],
                    [
                        1677830400,
                        "1"
                    ],
                    [
                        1677831000,
                        "1"
                    ]
                ]
            }
        ]
    }
}

社区原生接口

前提条件

  • 签名机制使用 Basic Auth 认证,请向云管或者技术支持人员获取可观测接口认证所需的账号和密码,用于替换下面示例中使用的账号 user@example.org 和密码 password

  • 域名机制通过 Kubernetes 的 ingress 实现,请向云管或者在后台执行以下命令获取本集群中可观测服务对接的域名,用以替换下面示例中使用的域名 ecms.company.easystack.io

    kubectl get ingress -n openstack ecms-web -ojsonpath='{.spec.rules[0].host}'

即时查询-POST(推荐)

URI

POST /api/v1/query

请求参数

名称 输入 类型 是否必选 描述
query Body string 查询表达式(PromQL)
time Body rfc3339/unix_timestamp 指定时间
timeout Body duration 超时时间
# 示例
curl -s -XPOST 'http://ecms.company.easystack.io/api/v1/query' --data 'query=kube_node_info' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

响应参数

名称 类型 描述
data dict 数据
data.result list 数据结果
data.result[$i].metric dict 时间序列的标签
data.result[$i].value list 列表中有两个字段,分别为指标的时间戳以及指标在此时间戳下的值
data.resultType string 数据类型
status string 状态
{
    "data": {
        "result": [
            {
                "metric": {
                    "__name__": "kube_node_info",
                    "container_runtime_version": "containerd://1.5.9",
                    "ecms_cluster_id": "OpfyBj54wvGtKqVe",
                    "host_ip": "10.10.1.9",
                    "instance": "kube-state-metrics",
                    "internal_ip": "10.10.1.9",
                    "job": "kube-state-metrics",
                    "kernel_version": "4.18.0-147.5.1.es8_24.x86_64",
                    "kubelet_version": "v1.20.14-es",
                    "kubeproxy_version": "v1.20.14-es",
                    "node": "node-7",
                    "node_name": "node-7",
                    "os_image": "EasyStack Cloud Linux 8.4 (AltArch)",
                    "pod_cidr": "10.232.3.0/24",
                    "system_uuid": "ca6725b6-b57b-446a-84e8-24aeda3877bb"
                },
                "value": [
                    1709867641.295,
                    "1"
                ]
            }
        ],
        "resultType": "vector"
    },
    "status": "success"
}

即时查询-GET

URI

GET /api/v1/query

请求参数

名称 输入 类型 是否必选 描述
query Query string 查询表达式(PromQL)
time Query rfc3339/unix_timestamp 指定时间
timeout Query duration 超时时间
# 示例1
curl -s 'http://ecms.company.easystack.io/api/v1/query?query=up&time=2015-07-01T20:10:51.781Z' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

# 示例2
curl -G 'http://ecms.company.easystack.io/api/v1/query' --data-urlencode 'query=container_memory_usage_bytes{namespace="openstack", pod="alertmanager-ecms-0", container="alertmanager"} / container_spec_memory_limit_bytes{namespace="openstack", pod="alertmanager-ecms-0", container="alertmanager"} * 100' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

响应参数

名称 类型 描述
data dict 数据
data.result list 数据结果
data.result[$i].metric dict 时间序列的标签
data.result[$i].value list 列表中有两个字段,分别为指标的时间戳以及指标在此时间戳下的值
data.resultType string 数据类型
status string 状态
{
    "data": {
        "result": [
            {
                "metric": {
                    "__name__": "kube_node_info",
                    "container_runtime_version": "containerd://1.5.9",
                    "ecms_cluster_id": "OpfyBj54wvGtKqVe",
                    "host_ip": "10.10.1.9",
                    "instance": "kube-state-metrics",
                    "internal_ip": "10.10.1.9",
                    "job": "kube-state-metrics",
                    "kernel_version": "4.18.0-147.5.1.es8_24.x86_64",
                    "kubelet_version": "v1.20.14-es",
                    "kubeproxy_version": "v1.20.14-es",
                    "node": "node-7",
                    "node_name": "node-7",
                    "os_image": "EasyStack Cloud Linux 8.4 (AltArch)",
                    "pod_cidr": "10.232.3.0/24",
                    "system_uuid": "ca6725b6-b57b-446a-84e8-24aeda3877bb"
                },
                "value": [
                    1709867641.295,
                    "1"
                ]
            }
        ],
        "resultType": "vector"
    },
    "status": "success"
}

范围查询-POST(推荐)

URI

POST /api/v1/query_range

请求参数

名称 输入 类型 是否必选 描述
query Body string 查询表达式(PromQL)
start Body rfc3339/unix_timestamp 开始时间
end Body rfc3339/unix_timestamp 结束时间
step Body duration/float 步长
timeout Body duration 超时时间
# 示例
curl -s -XPOST 'http://ecms.company.easystack.io/api/v1/query_range' --data 'query=kube_node_info&start=1709868627&end=1709868727&step=60' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

响应参数

名称 类型 描述
data dict 数据
data.result list 数据结果
data.result[$i].metric dict 时间序列的标签
data.result[$i].values list 每个子列表中有两个字段,分别为指标的时间戳以及指标在此时间戳下的值
data.resultType string 数据类型
status string 状态
{
    "data": {
        "result": [
            {
                "metric": {
                    "__name__": "kube_node_info",
                    "container_runtime_version": "containerd://1.5.9",
                    "ecms_cluster_id": "OpfyBj54wvGtKqVe",
                    "host_ip": "10.10.1.9",
                    "instance": "kube-state-metrics",
                    "internal_ip": "10.10.1.9",
                    "job": "kube-state-metrics",
                    "kernel_version": "4.18.0-147.5.1.es8_24.x86_64",
                    "kubelet_version": "v1.20.14-es",
                    "kubeproxy_version": "v1.20.14-es",
                    "node": "node-7",
                    "node_name": "node-7",
                    "os_image": "EasyStack Cloud Linux 8.4 (AltArch)",
                    "pod_cidr": "10.232.3.0/24",
                    "system_uuid": "ca6725b6-b57b-446a-84e8-24aeda3877bb"
                },
                "values": [
                    [
                        1709868627,
                        "1"
                    ],
                    [
                        1709868687,
                        "1"
                    ]
                ]
            }
        ],
        "resultType": "matrix"
    },
    "status": "success"
}

范围查询-GET

URI

GET /api/v1/query_range

请求参数

名称 输入 类型 是否必选 描述
query Query string 查询表达式(PromQL)
start Query rfc3339/unix_timestamp 开始时间
end Query rfc3339/unix_timestamp 结束时间
step Query duration/float 步长
timeout Query duration 超时时间
# 示例1
curl -s 'http://ecms.company.easystack.io/api/v1/query_range?query=kube_node_info&start=1709868627&end=1709868727&step=60' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

# 示例2
curl -G 'http://ecms.company.easystack.io/api/v1/query_range' --data-urlencode 'query=container_memory_usage_bytes{namespace="openstack", pod="alertmanager-ecms-0", container="alertmanager"} / container_spec_memory_limit_bytes{namespace="openstack", pod="alertmanager-ecms-0", container="alertmanager"} * 100' --data-urlencode 'start=1710204806' --data-urlencode 'end=1710208406' --data-urlencode 'step=60' -H "Authorization: Basic $(echo -n 'user@example.org:password' | base64)"

响应参数

名称 类型 描述
data dict 数据
data.result list 数据结果
data.result[$i].metric dict 时间序列的标签
data.result[$i].values list 每个子列表中有两个字段,分别为指标的时间戳以及指标在此时间戳下的值
data.resultType string 数据类型
status string 状态
{
    "data": {
        "result": [
            {
                "metric": {
                    "__name__": "kube_node_info",
                    "container_runtime_version": "containerd://1.5.9",
                    "ecms_cluster_id": "OpfyBj54wvGtKqVe",
                    "host_ip": "10.10.1.9",
                    "instance": "kube-state-metrics",
                    "internal_ip": "10.10.1.9",
                    "job": "kube-state-metrics",
                    "kernel_version": "4.18.0-147.5.1.es8_24.x86_64",
                    "kubelet_version": "v1.20.14-es",
                    "kubeproxy_version": "v1.20.14-es",
                    "node": "node-7",
                    "node_name": "node-7",
                    "os_image": "EasyStack Cloud Linux 8.4 (AltArch)",
                    "pod_cidr": "10.232.3.0/24",
                    "system_uuid": "ca6725b6-b57b-446a-84e8-24aeda3877bb"
                },
                "values": [
                    [
                        1709868627,
                        "1"
                    ],
                    [
                        1709868687,
                        "1"
                    ]
                ]
            }
        ],
        "resultType": "matrix"
    },
    "status": "success"
}
此篇文章对你是否有帮助?
没帮助
locked-file

您暂无权限访问该产品