IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 网络协议 -> 运维监控系列(22)-PromQL之HTTP API -> 正文阅读

[网络协议]运维监控系列(22)-PromQL之HTTP API

HTTP API

当前稳定的 HTTP API 可在/api/v1Prometheus 服务器上访问。任何不间断的添加都将添加到该端点下。

格式概览

API 响应格式为 JSON。每个成功的 API 请求都会返回一个2xx 状态代码。

到达 API 处理程序的无效请求会返回 JSON 错误对象和以下 HTTP 响应代码之一:

  • 400 Bad Request 当参数丢失或不正确时。
  • 422 Unprocessable Entity当表达式无法执行时 ( RFC4918 )。
  • 503 Service Unavailable 当查询超时或中止时。
  • 2xx对于在到达 API 端点之前发生的错误,可能会返回其他非代码。

如果存在不禁止请求执行的错误,则可能会返回一系列警告。成功收集的所有数据都将在数据字段中返回。

JSON 响应信封格式如下:

{
  "status": "success" | "error",
  "data": <data>,

  // Only set if status is "error". The data field may still hold
  // additional data.
  "errorType": "<string>",
  "error": "<string>",

  // Only if there were warnings while executing the request.
  // There will still be data in the data field.
  "warnings": ["<string>"]
}

通用占位符定义如下:

  • <rfc3339 | unix_timestamp>:输入时间戳可以以 RFC3339格式或以秒为单位的 Unix 时间戳提供,可选小数位以实现亚秒级精度。输出时间戳始终表示为以秒为单位的 Unix 时间戳。
  • < series_selector>:Prometheus时间序列选择器,例如http_requests_total或 http_requests_total{method=~"(GET|POST)"}并且需要进行 URL 编码。
  • < duration>:普罗米修斯持续时间字符串。例如,5m指的是持续时间为 5 分钟。
  • < bool>:布尔值(字符串true和false)。

注意:可能重复的查询参数名称以[].

表达式查询

查询语言表达式可以在单个时刻或在一段时间内进行评估。以下部分描述了每种类型的表达式查询的 API 端点。

即时查询

以下端点在单个时间点评估即时查询:

GET /api/v1/query
POST /api/v1/query

URL查询参数:

  • query=< string>: Prometheus 表达式查询字符串。
  • time=<rfc3339 | unix_timestamp>:评估时间戳。可选的。
  • timeout=< duration>: 评估超时。可选的。默认为并且受-query.timeout标志值的限制。
    如果time省略该参数,则使用当前服务器时间。

您可以使用POST方法和 Content-Type: application/x-www-form-urlencoded标头直接在请求正文中对这些参数进行 URL 编码。这在指定可能违反服务器端 URL 字符限制的大型查询时很有用。

该data查询结果的部分具有以下格式:

{
  "resultType": "matrix" | "vector" | "scalar" | "string",
  "result": <value>
}

< value>是指查询结果数据,根据resultType. 请参阅表达式查询结果格式。

下面的示例计算的表达up在时间 2015-07-01T20:10:51.781Z:

$ curl 'http://localhost:9090/api/v1/query?query=up&time=2015-07-01T20:10:51.781Z'
{
   "status" : "success",
   "data" : {
      "resultType" : "vector",
      "result" : [
         {
            "metric" : {
               "__name__" : "up",
               "job" : "prometheus",
               "instance" : "localhost:9090"
            },
            "value": [ 1435781451.781, "1" ]
         },
         {
            "metric" : {
               "__name__" : "up",
               "job" : "node",
               "instance" : "localhost:9100"
            },
            "value" : [ 1435781451.781, "0" ]
         }
      ]
   }
}

范围查询

以下端点在一段时间内评估表达式查询:

GET /api/v1/query_range
POST /api/v1/query_range

URL查询参数:

  • query=: Prometheus 表达式查询字符串。
  • start=<rfc3339 | unix_timestamp>: 开始时间戳,包括。
  • end=<rfc3339 | unix_timestamp>: 结束时间戳,包括。
  • step=<duration | float>: 以duration格式或浮点秒数查询分辨率步长。
  • timeout=: 评估超时。可选的。默认为并且受-query.timeout标志值的限制。

您可以使用POST方法和 Content-Type: application/x-www-form-urlencoded标头直接在请求正文中对这些参数进行 URL 编码。这在指定可能违反服务器端 URL 字符限制的大型查询时很有用。

该data查询结果的部分具有以下格式:

{
  "resultType": "matrix",
  "result": <value>
}

< value>占位符的格式参见range-vector 结果格式。

以下示例up在 30 秒范围内计算表达式,查询分辨率为 15 秒。

$ curl 'http://localhost:9090/api/v1/query_range?query=up&start=2015-07-01T20:10:30.781Z&end=2015-07-01T20:11:00.781Z&step=15s'
{
   "status" : "success",
   "data" : {
      "resultType" : "matrix",
      "result" : [
         {
            "metric" : {
               "__name__" : "up",
               "job" : "prometheus",
               "instance" : "localhost:9090"
            },
            "values" : [
               [ 1435781430.781, "1" ],
               [ 1435781445.781, "1" ],
               [ 1435781460.781, "1" ]
            ]
         },
         {
            "metric" : {
               "__name__" : "up",
               "job" : "node",
               "instance" : "localhost:9091"
            },
            "values" : [
               [ 1435781430.781, "0" ],
               [ 1435781445.781, "0" ],
               [ 1435781460.781, "1" ]
            ]
         }
      ]
   }
}

查询元数据

Prometheus 提供了一组 API 端点来查询关于系列及其标签的元数据。

注意:这些 API 端点可能会返回在所选时间范围内没有样本的系列的元数据,和/或样本已通过删除 API 端点标记为已删除的系列的元数据。额外返回的系列元数据的确切范围是将来可能会更改的实现细节。

通过标签匹配器查找系列

以下端点返回与特定标签集匹配的时间序列列表。

GET /api/v1/series
POST /api/v1/series

URL查询参数:

  • match[]=<series_selector>:选择要返回的系列的重复系列选择器参数。match[]必须至少提供一个参数。
  • start=<rfc3339 | unix_timestamp>: 开始时间戳。
    -end=<rfc3339 | unix_timestamp>: 结束时间戳。

您可以使用POST方法和 Content-Type: application/x-www-form-urlencoded标头直接在请求正文中对这些参数进行 URL 编码。这在指定可能违反服务器端 URL 字符限制的大量或动态数量的系列选择器时很有用。

该data查询结果的部分由包含其识别每个系列标签名称/值对对象的列表中。

以下示例返回与选择器up或匹配的所有系列 process_start_time_seconds{job=“prometheus”}:

$ curl -g 'http://localhost:9090/api/v1/series?' --data-urlencode 'match[]=up' --data-urlencode 'match[]=process_start_time_seconds{job="prometheus"}'
{
   "status" : "success",
   "data" : [
      {
         "__name__" : "up",
         "job" : "prometheus",
         "instance" : "localhost:9090"
      },
      {
         "__name__" : "up",
         "job" : "node",
         "instance" : "localhost:9091"
      },
      {
         "__name__" : "process_start_time_seconds",
         "job" : "prometheus",
         "instance" : "localhost:9090"
      }
   ]
}

获取标签名称

以下端点返回标签名称列表:

GET /api/v1/labels
POST /api/v1/labels

URL查询参数:

  • start=<rfc3339 | unix_timestamp>: 开始时间戳。可选的。
  • end=<rfc3339 | unix_timestamp>: 结束时间戳。可选的。
  • match[]=<series_selector>:重复系列选择器参数,选择从中读取标签名称的系列。可选的。

dataJSON 响应的部分是字符串标签名称列表。

这是一个例子。

$ curl 'localhost:9090/api/v1/labels'
{
    "status": "success",
    "data": [
        "__name__",
        "call",
        "code",
        "config",
        "dialer_name",
        "endpoint",
        "event",
        "goversion",
        "handler",
        "instance",
        "interval",
        "job",
        "le",
        "listener_name",
        "name",
        "quantile",
        "reason",
        "role",
        "scrape_job",
        "slice",
        "version"
    ]
}

查询标签值

以下端点返回提供的标签名称的标签值列表:

GET /api/v1/label/<label_name>/values

URL查询参数:

  • start=<rfc3339 | unix_timestamp>: 开始时间戳。可选的。
  • end=<rfc3339 | unix_timestamp>: 结束时间戳。可选的。
  • match[]=<series_selector>:重复系列选择器参数,选择从中读取标签值的系列。可选的。

dataJSON 响应的部分是字符串标签值列表。

此示例查询标签的所有标签值job:

$ curl http://localhost:9090/api/v1/label/job/values
{
   "status" : "success",
   "data" : [
      "node",
      "prometheus"
   ]
}

查询范例

这是实验性的,将来可能会改变。以下端点返回特定时间范围内有效 PromQL 查询的示例列表:

GET /api/v1/query_exemplars
POST /api/v1/query_exemplars

URL查询参数:

  • query=: Prometheus 表达式查询字符串。
  • start=<rfc3339 | unix_timestamp>: 开始时间戳。
  • end=<rfc3339 | unix_timestamp>: 结束时间戳。
$ curl -g 'http://localhost:9090/api/v1/query_exemplars?query=test_exemplar_metric_total&start=2020-09-14T15:22:25.479Z&end=020-09-14T15:23:25.479Z'
{
    "status": "success",
    "data": [
        {
            "seriesLabels": {
                "__name__": "test_exemplar_metric_total",
                "instance": "localhost:8090",
                "job": "prometheus",
                "service": "bar"
            },
            "exemplars": [
                {
                    "labels": {
                        "traceID": "EpTxMJ40fUus7aGY"
                    },
                    "value": "6",
                    "timestamp": 1600096945.479,
                }
            ]
        },
        {
            "seriesLabels": {
                "__name__": "test_exemplar_metric_total",
                "instance": "localhost:8090",
                "job": "prometheus",
                "service": "foo"
            },
            "exemplars": [
                {
                    "labels": {
                        "traceID": "Olp9XHlq763ccsfa"
                    },
                    "value": "19",
                    "timestamp": 1600096955.479,
                },
                {
                    "labels": {
                        "traceID": "hCtjygkIHwAN9vs4"
                    },
                    "value": "20",
                    "timestamp": 1600096965.489,
                },
            ]
        }
    ]
}

表达式查询结果格式

表达式查询可能会在result 该data部分的属性中返回以下响应值。<sample_value>占位符是数字样本值。JSON不支持的特殊浮点值,例如NaN,Inf和-Inf,因此采样值转移所报JSON字符串,而不是原始数据。

范围向量

范围向量作为结果类型返回matrix。相应的 result属性具有以下格式:

[
  {
    "metric": { "<label_name>": "<label_value>", ... },
    "values": [ [ <unix_time>, "<sample_value>" ], ... ]
  },
  ...
]

即时向量

即时向量作为结果类型返回vector。相应的 result属性具有以下格式:

[
  {
    "metric": { "<label_name>": "<label_value>", ... },
    "value": [ <unix_time>, "<sample_value>" ]
  },
  ...
]

标量

标量结果作为结果类型返回scalar。相应的 result属性具有以下格式:

[ <unix_time>, "<scalar_value>" ]

字符串

字符串结果作为结果类型返回string。相应的 result属性具有以下格式:

[ <unix_time>, "<string_value>" ]

目标

以下端点返回 Prometheus 目标发现的当前状态概览:

GET /api/v1/targets

默认情况下,活动和丢弃的目标都是响应的一部分。 labels表示发生重新标记后的标签集。 discoveredLabels表示在重新标记发生之前在服务发现期间检索到的未修改标签。

$ curl http://localhost:9090/api/v1/targets
{
  "status": "success",
  "data": {
    "activeTargets": [
      {
        "discoveredLabels": {
          "__address__": "127.0.0.1:9090",
          "__metrics_path__": "/metrics",
          "__scheme__": "http",
          "job": "prometheus"
        },
        "labels": {
          "instance": "127.0.0.1:9090",
          "job": "prometheus"
        },
        "scrapePool": "prometheus",
        "scrapeUrl": "http://127.0.0.1:9090/metrics",
        "globalUrl": "http://example-prometheus:9090/metrics",
        "lastError": "",
        "lastScrape": "2017-01-17T15:07:44.723715405+01:00",
        "lastScrapeDuration": 0.050688943,
        "health": "up",
        "scrapeInterval": "1m",
        "scrapeTimeout": "10s"
      }
    ],
    "droppedTargets": [
      {
        "discoveredLabels": {
          "__address__": "127.0.0.1:9100",
          "__metrics_path__": "/metrics",
          "__scheme__": "http",
          "__scrape_interval__": "1m",
          "__scrape_timeout__": "10s",
          "job": "node"
        },
      }
    ]
  }
}

所述state查询参数允许调用者滤波器通过主动或丢弃目标,(例如,state=active,state=dropped,state=any)。请注意,过滤掉的目标仍会返回一个空数组。其他值被忽略。

$ curl 'http://localhost:9090/api/v1/targets?state=active'
{
  "status": "success",
  "data": {
    "activeTargets": [
      {
        "discoveredLabels": {
          "__address__": "127.0.0.1:9090",
          "__metrics_path__": "/metrics",
          "__scheme__": "http",
          "job": "prometheus"
        },
        "labels": {
          "instance": "127.0.0.1:9090",
          "job": "prometheus"
        },
        "scrapePool": "prometheus",
        "scrapeUrl": "http://127.0.0.1:9090/metrics",
        "globalUrl": "http://example-prometheus:9090/metrics",
        "lastError": "",
        "lastScrape": "2017-01-17T15:07:44.723715405+01:00",
        "lastScrapeDuration": 50688943,
        "health": "up"
      }
    ],
    "droppedTargets": []
  }
}

规则

该/rulesAPI端点返回报警和记录当前加载规则的列表。此外,它还返回每个警报规则的 Prometheus 实例触发的当前活动警报。

由于/rules端点相当新,它没有与总体 API v1 相同的稳定性保证。

GET /api/v1/rules

URL 查询参数: - type=alert|record:只返回告警规则(如type=alert)或录音规则(如type=record)。当参数不存在或为空时,不进行过滤。

$ curl http://localhost:9090/api/v1/rules

{
    "data": {
        "groups": [
            {
                "rules": [
                    {
                        "alerts": [
                            {
                                "activeAt": "2018-07-04T20:27:12.60602144+02:00",
                                "annotations": {
                                    "summary": "High request latency"
                                },
                                "labels": {
                                    "alertname": "HighRequestLatency",
                                    "severity": "page"
                                },
                                "state": "firing",
                                "value": "1e+00"
                            }
                        ],
                        "annotations": {
                            "summary": "High request latency"
                        },
                        "duration": 600,
                        "health": "ok",
                        "labels": {
                            "severity": "page"
                        },
                        "name": "HighRequestLatency",
                        "query": "job:request_latency_seconds:mean5m{job=\"myjob\"} > 0.5",
                        "type": "alerting"
                    },
                    {
                        "health": "ok",
                        "name": "job:http_inprogress_requests:sum",
                        "query": "sum by (job) (http_inprogress_requests)",
                        "type": "recording"
                    }
                ],
                "file": "/rules.yaml",
                "interval": 60,
                "name": "example"
            }
        ]
    },
    "status": "success"
}

警报

该/alerts端点返回所有活动警报的列表。

由于/alerts端点相当新,它没有与总体 API v1 相同的稳定性保证。

GET /api/v1/alerts
$ curl http://localhost:9090/api/v1/alerts

{
    "data": {
        "alerts": [
            {
                "activeAt": "2018-07-04T20:27:12.60602144+02:00",
                "annotations": {},
                "labels": {
                    "alertname": "my-alert"
                },
                "state": "firing",
                "value": "1e+00"
            }
        ]
    },
    "status": "success"
}

查询目标元数据

以下端点返回有关当前从目标中抓取的指标的元数据。这是实验性的,将来可能会改变。

GET /api/v1/targets/metadata

URL查询参数:

  • match_target=<label_selectors>:通过标签集匹配目标的标签选择器。如果留空,则选择所有目标。
  • metric=< string>:要为其检索元数据的指标名称。如果留空,则检索所有指标元数据。
  • limit=< number>:要匹配的最大目标数。

该data查询结果的部分由包含度量元数据和对象的标贴纸组对象的列表。

以下示例go_goroutines从带有标签的前两个目标返回指标的所有元数据条目job=“prometheus”。

curl -G http://localhost:9091/api/v1/targets/metadata \
    --data-urlencode 'metric=go_goroutines' \
    --data-urlencode 'match_target={job="prometheus"}' \
    --data-urlencode 'limit=2'
{
  "status": "success",
  "data": [
    {
      "target": {
        "instance": "127.0.0.1:9090",
        "job": "prometheus"
      },
      "type": "gauge",
      "help": "Number of goroutines that currently exist.",
      "unit": ""
    },
    {
      "target": {
        "instance": "127.0.0.1:9091",
        "job": "prometheus"
      },
      "type": "gauge",
      "help": "Number of goroutines that currently exist.",
      "unit": ""
    }
  ]
}

以下示例返回带有标签的所有目标的所有指标的元数据instance="127.0.0.1:9090。

curl -G http://localhost:9091/api/v1/targets/metadata \
    --data-urlencode 'match_target={instance="127.0.0.1:9090"}'
{
  "status": "success",
  "data": [
    // ...
    {
      "target": {
        "instance": "127.0.0.1:9090",
        "job": "prometheus"
      },
      "metric": "prometheus_treecache_zookeeper_failures_total",
      "type": "counter",
      "help": "The total number of ZooKeeper failures.",
      "unit": ""
    },
    {
      "target": {
        "instance": "127.0.0.1:9090",
        "job": "prometheus"
      },
      "metric": "prometheus_tsdb_reloads_total",
      "type": "counter",
      "help": "Number of times the database reloaded block data from disk.",
      "unit": ""
    },
    // ...
  ]
}

查询指标元数据

它返回有关当前从目标中删除的指标的元数据。但是,它不提供任何目标信息。这被认为是实验性的,将来可能会改变。

GET /api/v1/metadata

URL查询参数:

  • limit=:要返回的最大指标数。
  • metric=:用于过滤元数据的指标名称。如果留空,则检索所有指标元数据。

data查询结果的部分由一个对象组成,其中每个键都是一个指标名称,每个值都是一个唯一元数据对象列表,如在所有目标中为该指标名称公开的那样。

以下示例返回两个指标。请注意,该指标http_requests_total在列表中包含多个对象。至少一个目标的值HELP与其他目标不匹配。

curl -G http://localhost:9090/api/v1/metadata?limit=2

{
  "status": "success",
  "data": {
    "cortex_ring_tokens": [
      {
        "type": "gauge",
        "help": "Number of tokens in the ring",
        "unit": ""
      }
    ],
    "http_requests_total": [
      {
        "type": "counter",
        "help": "Number of HTTP requests",
        "unit": ""
      },
      {
        "type": "counter",
        "help": "Amount of HTTP requests",
        "unit": ""
      }
    ]
  }
}

以下示例仅返回 metric 的元数据http_requests_total。

curl -G http://localhost:9090/api/v1/metadata?metric=http_requests_total

{
  "status": "success",
  "data": {
    "http_requests_total": [
      {
        "type": "counter",
        "help": "Number of HTTP requests",
        "unit": ""
      },
      {
        "type": "counter",
        "help": "Amount of HTTP requests",
        "unit": ""
      }
    ]
  }
}

警报管理器

以下端点返回 Prometheus 警报管理器发现的当前状态的概述:

GET /api/v1/alertmanagers
活动的和删除的 Alertmanagers 都是响应的一部分。

$ curl http://localhost:9090/api/v1/alertmanagers
{
  "status": "success",
  "data": {
    "activeAlertmanagers": [
      {
        "url": "http://127.0.0.1:9090/api/v1/alerts"
      }
    ],
    "droppedAlertmanagers": [
      {
        "url": "http://127.0.0.1:9093/api/v1/alerts"
      }
    ]
  }
}

地位

以下状态端点公开当前的 Prometheus 配置。

配置

以下端点返回当前加载的配置文件:

GET /api/v1/status/config

配置作为转储的 YAML 文件返回。由于 YAML 库的限制,不包括 YAML 注释。

$ curl http://localhost:9090/api/v1/status/config
{
  "status": "success",
  "data": {
    "yaml": "<content of the loaded config file in YAML>",
  }
}

旗帜

以下端点返回 Prometheus 配置的标志值:

GET /api/v1/status/flags

所有值都是结果类型string。

$ curl http://localhost:9090/api/v1/status/flags
{
  "status": "success",
  "data": {
    "alertmanager.notification-queue-capacity": "10000",
    "alertmanager.timeout": "10s",
    "log.level": "info",
    "query.lookback-delta": "5m",
    "query.max-concurrency": "20",
    ...
  }
}

v2.2 中的新功能

运行时信息

以下端点返回有关 Prometheus 服务器的各种运行时信息属性:

GET /api/v1/status/runtimeinfo

返回值具有不同的类型,具体取决于运行时属性的性质。

$ curl http://localhost:9090/api/v1/status/runtimeinfo
{
  "status": "success",
  "data": {
    "startTime": "2019-11-02T17:23:59.301361365+01:00",
    "CWD": "/",
    "reloadConfigSuccess": true,
    "lastConfigTime": "2019-11-02T17:23:59+01:00",
    "timeSeriesCount": 873,
    "corruptionCount": 0,
    "goroutineCount": 48,
    "GOMAXPROCS": 4,
    "GOGC": "",
    "GODEBUG": "",
    "storageRetention": "15d"
  }
}

注意:准确返回的运行时属性可能会在 Prometheus 版本之间更改,恕不另行通知。
v2.14 中的新功能

构建信息

以下端点返回有关 Prometheus 服务器的各种构建信息属性:

GET /api/v1/status/buildinfo

所有值都是结果类型string。

$ curl http://localhost:9090/api/v1/status/buildinfo
{
  "status": "success",
  "data": {
    "version": "2.13.1",
    "revision": "cb7cbad5f9a2823a622aaa668833ca04f50a0ea7",
    "branch": "master",
    "buildUser": "julius@desktop",
    "buildDate": "20191102-16:19:59",
    "goVersion": "go1.13.1"
  }
}

注意:准确返回的构建属性可能会在 Prometheus 版本之间发生变化,恕不另行通知。
v2.14 中的新功能

TSDB 统计

以下端点返回有关 Prometheus TSDB 的各种基数统计信息:

GET /api/v1/status/tsdb
  • headStats:这提供了有关 TSDB 的头块的以下数据:
  • numSeries : 系列数。
  • chunkCount:块的数量。
  • minTime:以毫秒为单位的当前最小时间戳。
  • maxTime:以毫秒为单位的当前最大时间戳。
  • seriesCountByMetricName: 这将提供指标名称及其系列计数的列表。
  • labelValueCountByLabelName:这将提供标签名称及其值计数的列表。
  • memoryInBytesByLabelName这将提供以字节为单位使用的标签名称和内存的列表。内存使用是通过将给定标签名称的所有值的长度相加来计算的。
  • seriesCountByLabelPair这将提供标签值对及其系列计数的列表。
$ curl http://localhost:9090/api/v1/status/tsdb
{
  "status": "success",
  "data": {
    "headStats": {
      "numSeries": 508,
      "chunkCount": 937,
      "minTime": 1591516800000,
      "maxTime": 1598896800143,
    },
    "seriesCountByMetricName": [
      {
        "name": "net_conntrack_dialer_conn_failed_total",
        "value": 20
      },
      {
        "name": "prometheus_http_request_duration_seconds_bucket",
        "value": 20
      }
    ],
    "labelValueCountByLabelName": [
      {
        "name": "__name__",
        "value": 211
      },
      {
        "name": "event",
        "value": 3
      }
    ],
    "memoryInBytesByLabelName": [
      {
        "name": "__name__",
        "value": 8266
      },
      {
        "name": "instance",
        "value": 28
      }
    ],
    "seriesCountByLabelValuePair": [
      {
        "name": "job=prometheus",
        "value": 425
      },
      {
        "name": "instance=localhost:9090",
        "value": 425
      }
    ]
  }
}

v2.15 中的新功能

WAL 重播统计

以下端点返回有关 WAL 重播的信息:

GET /api/v1/status/walreplay

read:到目前为止重播的段数。 total:需要重播的总段数。 progress : 重放的进度 (0 - 100%)。 state : 回放的状态。可能的状态: -等待:等待重播开始。-进行中:重播正在进行中。-完成:重播已完成。

$ curl http://localhost:9090/api/v1/status/walreplay
{
  "status": "success",
  "data": {
    "min": 2,
    "max": 5,
    "current": 40,
    "state": "in progress"
  }
}

注意:此端点在服务器标记为就绪之前可用,并实时更新以方便监控 WAL 重放的进度。
v2.28 中的新功能

TSDB 管理 API

这些是为高级用户公开数据库功能的 API。除非–web.enable-admin-api设置了,否则不会启用这些 API 。

快照

快照将所有当前数据的快照创建到snapshots/-TSDB 的数据目录下,并返回该目录作为响应。它将选择性地跳过仅存在于头块中且尚未压缩到磁盘的快照数据。

POST /api/v1/admin/tsdb/snapshot
PUT /api/v1/admin/tsdb/snapshot

URL查询参数:

skip_head=<bool>: 跳过头块中存在的数据。可选的。
$ curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot
{
  "status": "success",
  "data": {
    "name": "20171210T211224Z-2be650b6d019eb54"
  }
}

快照现在存在于 < data-dir>/snapshots/20171210T211224Z-2be650b6d019eb54

v2.1 中的新功能并支持 v2.9 中的 PUT

删除系列

DeleteSeries 删除时间范围内选定系列的数据。实际数据仍然存在于磁盘上,并在未来的压缩中被清除,或者可以通过点击Clean Tombstones端点来明确清除。

如果成功,204则返回 a。

POST /api/v1/admin/tsdb/delete_series
PUT /api/v1/admin/tsdb/delete_series

URL查询参数:

  • match[]=<series_selector>:选择要删除的系列的重复标签匹配器参数。match[]必须至少提供一个参数。
  • start=<rfc3339 | unix_timestamp>: 开始时间戳。可选,默认为最短时间。
  • end=<rfc3339 | unix_timestamp>: 结束时间戳。可选,默认为最大可能时间。
    不提及开始和结束时间将清除数据库中匹配系列的所有数据。

例子:

$ curl -X POST \
  -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}'

注意:此端点将系列中的样本标记为已删除,但不一定会阻止在受影响的时间范围内的元数据查询中仍返回关联的系列元数据(即使在清除墓碑之后)。元数据删除的确切范围是将来可能会更改的实施细节。
v2.1 中的新功能并支持 v2.9 中的 PUT

清理墓碑

CleanTombstones 从磁盘中删除已删除的数据并清理现有的逻辑删除。这可以在删除系列后使用以释放空间。

如果成功,204则返回 a。

POST /api/v1/admin/tsdb/clean_tombstones
PUT /api/v1/admin/tsdb/clean_tombstones

这不需要参数或主体。

$ curl -XPOST http://localhost:9090/api/v1/admin/tsdb/clean_tombstones
v2.1 中的新功能并支持 v2.9 中的 PUT。

文档来源
https://prometheus.io/docs/prometheus/latest/querying/operators/

  网络协议 最新文章
使用Easyswoole 搭建简单的Websoket服务
常见的数据通信方式有哪些?
Openssl 1024bit RSA算法---公私钥获取和处
HTTPS协议的密钥交换流程
《小白WEB安全入门》03. 漏洞篇
HttpRunner4.x 安装与使用
2021-07-04
手写RPC学习笔记
K8S高可用版本部署
mySQL计算IP地址范围
上一篇文章      下一篇文章      查看所有文章
加:2021-09-26 10:33:32  更:2021-09-26 10:33:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年6日历 -2024/6/27 1:48:21-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码