使用数据流生命周期运行降采样

编辑

使用数据流生命周期运行降采样

编辑

这是一个简化的示例,允许您快速了解降采样如何作为数据流生命周期的一部分工作,以减少采样指标集的存储大小。该示例使用典型的 Kubernetes 集群监控数据。要使用数据流生命周期测试降采样,请按照以下步骤操作

先决条件

编辑

请参阅时间序列数据流先决条件

使用数据流生命周期创建索引模板

编辑

这将为基本数据流创建一个索引模板。索引模板的可用参数在设置时间序列数据流中有详细描述。

为简单起见,在时间序列映射中,所有time_series_metric参数都设置为gauge类型,但也可以使用counter指标类型。time_series_metric值确定在降采样期间使用的统计表示类型。

索引模板包含一组静态时间序列维度hostnamespacenodepod。时间序列维度不会被降采样过程更改。

要启用降采样,此模板包含带有降采样对象的lifecycle部分。fixed_interval参数设置要聚合原始时间序列数据的降采样间隔。after参数指定在索引滚动后多长时间执行降采样。

const response = await client.indices.putIndexTemplate({
  name: "datastream_template",
  index_patterns: ["datastream*"],
  data_stream: {},
  template: {
    lifecycle: {
      downsampling: [
        {
          after: "1m",
          fixed_interval: "1h",
        },
      ],
    },
    settings: {
      index: {
        mode: "time_series",
      },
    },
    mappings: {
      properties: {
        "@timestamp": {
          type: "date",
        },
        kubernetes: {
          properties: {
            container: {
              properties: {
                cpu: {
                  properties: {
                    usage: {
                      properties: {
                        core: {
                          properties: {
                            ns: {
                              type: "long",
                            },
                          },
                        },
                        limit: {
                          properties: {
                            pct: {
                              type: "float",
                            },
                          },
                        },
                        nanocores: {
                          type: "long",
                          time_series_metric: "gauge",
                        },
                        node: {
                          properties: {
                            pct: {
                              type: "float",
                            },
                          },
                        },
                      },
                    },
                  },
                },
                memory: {
                  properties: {
                    available: {
                      properties: {
                        bytes: {
                          type: "long",
                          time_series_metric: "gauge",
                        },
                      },
                    },
                    majorpagefaults: {
                      type: "long",
                    },
                    pagefaults: {
                      type: "long",
                      time_series_metric: "gauge",
                    },
                    rss: {
                      properties: {
                        bytes: {
                          type: "long",
                          time_series_metric: "gauge",
                        },
                      },
                    },
                    usage: {
                      properties: {
                        bytes: {
                          type: "long",
                          time_series_metric: "gauge",
                        },
                        limit: {
                          properties: {
                            pct: {
                              type: "float",
                            },
                          },
                        },
                        node: {
                          properties: {
                            pct: {
                              type: "float",
                            },
                          },
                        },
                      },
                    },
                    workingset: {
                      properties: {
                        bytes: {
                          type: "long",
                          time_series_metric: "gauge",
                        },
                      },
                    },
                  },
                },
                name: {
                  type: "keyword",
                },
                start_time: {
                  type: "date",
                },
              },
            },
            host: {
              type: "keyword",
              time_series_dimension: true,
            },
            namespace: {
              type: "keyword",
              time_series_dimension: true,
            },
            node: {
              type: "keyword",
              time_series_dimension: true,
            },
            pod: {
              type: "keyword",
              time_series_dimension: true,
            },
          },
        },
      },
    },
  },
});
console.log(response);
PUT _index_template/datastream_template
{
  "index_patterns": [
    "datastream*"
  ],
  "data_stream": {},
  "template": {
    "lifecycle": {
      "downsampling": [
        {
          "after": "1m",
          "fixed_interval": "1h"
        }
      ]
    },
    "settings": {
      "index": {
        "mode": "time_series"
      }
    },
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "kubernetes": {
          "properties": {
            "container": {
              "properties": {
                "cpu": {
                  "properties": {
                    "usage": {
                      "properties": {
                        "core": {
                          "properties": {
                            "ns": {
                              "type": "long"
                            }
                          }
                        },
                        "limit": {
                          "properties": {
                            "pct": {
                              "type": "float"
                            }
                          }
                        },
                        "nanocores": {
                          "type": "long",
                          "time_series_metric": "gauge"
                        },
                        "node": {
                          "properties": {
                            "pct": {
                              "type": "float"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "memory": {
                  "properties": {
                    "available": {
                      "properties": {
                        "bytes": {
                          "type": "long",
                          "time_series_metric": "gauge"
                        }
                      }
                    },
                    "majorpagefaults": {
                      "type": "long"
                    },
                    "pagefaults": {
                      "type": "long",
                      "time_series_metric": "gauge"
                    },
                    "rss": {
                      "properties": {
                        "bytes": {
                          "type": "long",
                          "time_series_metric": "gauge"
                        }
                      }
                    },
                    "usage": {
                      "properties": {
                        "bytes": {
                          "type": "long",
                          "time_series_metric": "gauge"
                        },
                        "limit": {
                          "properties": {
                            "pct": {
                              "type": "float"
                            }
                          }
                        },
                        "node": {
                          "properties": {
                            "pct": {
                              "type": "float"
                            }
                          }
                        }
                      }
                    },
                    "workingset": {
                      "properties": {
                        "bytes": {
                          "type": "long",
                          "time_series_metric": "gauge"
                        }
                      }
                    }
                  }
                },
                "name": {
                  "type": "keyword"
                },
                "start_time": {
                  "type": "date"
                }
              }
            },
            "host": {
              "type": "keyword",
              "time_series_dimension": true
            },
            "namespace": {
              "type": "keyword",
              "time_series_dimension": true
            },
            "node": {
              "type": "keyword",
              "time_series_dimension": true
            },
            "pod": {
              "type": "keyword",
              "time_series_dimension": true
            }
          }
        }
      }
    }
  }
}

摄取时间序列数据

编辑

使用批量 API 请求自动创建您的 TSDS 并索引一组十个文档。

重要提示: 在运行此批量请求之前,您需要将时间戳更新到当前时间后的三到五个小时内。也就是说,搜索2022-06-21T15并替换为当前日期,并将小时调整为当前时间加上三个小时。

resp = client.bulk(
    index="datastream",
    refresh=True,
    operations=[
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:49:00Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 91153,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 463314616
                        },
                        "usage": {
                            "bytes": 307007078,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 585236
                        },
                        "rss": {
                            "bytes": 102728
                        },
                        "pagefaults": 120901,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:45:50Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 124501,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 982546514
                        },
                        "usage": {
                            "bytes": 360035574,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 1339884
                        },
                        "rss": {
                            "bytes": 381174
                        },
                        "pagefaults": 178473,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:44:50Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 38907,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 862723768
                        },
                        "usage": {
                            "bytes": 379572388,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 431227
                        },
                        "rss": {
                            "bytes": 386580
                        },
                        "pagefaults": 233166,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:44:40Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 86706,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 567160996
                        },
                        "usage": {
                            "bytes": 103266017,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 1724908
                        },
                        "rss": {
                            "bytes": 105431
                        },
                        "pagefaults": 233166,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:44:00Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 150069,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 639054643
                        },
                        "usage": {
                            "bytes": 265142477,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 1786511
                        },
                        "rss": {
                            "bytes": 189235
                        },
                        "pagefaults": 138172,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:42:40Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 82260,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 854735585
                        },
                        "usage": {
                            "bytes": 309798052,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 924058
                        },
                        "rss": {
                            "bytes": 110838
                        },
                        "pagefaults": 259073,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:42:10Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 153404,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 279586406
                        },
                        "usage": {
                            "bytes": 214904955,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 1047265
                        },
                        "rss": {
                            "bytes": 91914
                        },
                        "pagefaults": 302252,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:40:20Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 125613,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 822782853
                        },
                        "usage": {
                            "bytes": 100475044,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 2109932
                        },
                        "rss": {
                            "bytes": 278446
                        },
                        "pagefaults": 74843,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:40:10Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 100046,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 567160996
                        },
                        "usage": {
                            "bytes": 362826547,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 1986724
                        },
                        "rss": {
                            "bytes": 402801
                        },
                        "pagefaults": 296495,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        },
        {
            "create": {}
        },
        {
            "@timestamp": "2022-06-21T15:38:30Z",
            "kubernetes": {
                "host": "gke-apps-0",
                "node": "gke-apps-0-0",
                "pod": "gke-apps-0-0-0",
                "container": {
                    "cpu": {
                        "usage": {
                            "nanocores": 40018,
                            "core": {
                                "ns": 12828317850
                            },
                            "node": {
                                "pct": 0.0000277905
                            },
                            "limit": {
                                "pct": 0.0000277905
                            }
                        }
                    },
                    "memory": {
                        "available": {
                            "bytes": 1062428344
                        },
                        "usage": {
                            "bytes": 265142477,
                            "node": {
                                "pct": 0.01770037710617187
                            },
                            "limit": {
                                "pct": 0.00009923134671484496
                            }
                        },
                        "workingset": {
                            "bytes": 2294743
                        },
                        "rss": {
                            "bytes": 340623
                        },
                        "pagefaults": 224530,
                        "majorpagefaults": 0
                    },
                    "start_time": "2021-03-30T07:59:06Z",
                    "name": "container-name-44"
                },
                "namespace": "namespace26"
            }
        }
    ],
)
print(resp)
response = client.bulk(
  index: 'datastream',
  refresh: true,
  body: [
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:49:00Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 91_153,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 463_314_616
            },
            usage: {
              bytes: 307_007_078,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 585_236
            },
            rss: {
              bytes: 102_728
            },
            pagefaults: 120_901,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:45:50Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 124_501,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 982_546_514
            },
            usage: {
              bytes: 360_035_574,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 1_339_884
            },
            rss: {
              bytes: 381_174
            },
            pagefaults: 178_473,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:44:50Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 38_907,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 862_723_768
            },
            usage: {
              bytes: 379_572_388,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 431_227
            },
            rss: {
              bytes: 386_580
            },
            pagefaults: 233_166,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:44:40Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 86_706,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 567_160_996
            },
            usage: {
              bytes: 103_266_017,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 1_724_908
            },
            rss: {
              bytes: 105_431
            },
            pagefaults: 233_166,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:44:00Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 150_069,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 639_054_643
            },
            usage: {
              bytes: 265_142_477,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 1_786_511
            },
            rss: {
              bytes: 189_235
            },
            pagefaults: 138_172,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:42:40Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 82_260,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 854_735_585
            },
            usage: {
              bytes: 309_798_052,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 924_058
            },
            rss: {
              bytes: 110_838
            },
            pagefaults: 259_073,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:42:10Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 153_404,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 279_586_406
            },
            usage: {
              bytes: 214_904_955,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 1_047_265
            },
            rss: {
              bytes: 91_914
            },
            pagefaults: 302_252,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:40:20Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 125_613,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 822_782_853
            },
            usage: {
              bytes: 100_475_044,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 2_109_932
            },
            rss: {
              bytes: 278_446
            },
            pagefaults: 74_843,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:40:10Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 100_046,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 567_160_996
            },
            usage: {
              bytes: 362_826_547,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 1_986_724
            },
            rss: {
              bytes: 402_801
            },
            pagefaults: 296_495,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    },
    {
      create: {}
    },
    {
      "@timestamp": '2022-06-21T15:38:30Z',
      kubernetes: {
        host: 'gke-apps-0',
        node: 'gke-apps-0-0',
        pod: 'gke-apps-0-0-0',
        container: {
          cpu: {
            usage: {
              nanocores: 40_018,
              core: {
                ns: 12_828_317_850
              },
              node: {
                pct: 2.77905e-05
              },
              limit: {
                pct: 2.77905e-05
              }
            }
          },
          memory: {
            available: {
              bytes: 1_062_428_344
            },
            usage: {
              bytes: 265_142_477,
              node: {
                pct: 0.01770037710617187
              },
              limit: {
                pct: 9.923134671484496e-05
              }
            },
            workingset: {
              bytes: 2_294_743
            },
            rss: {
              bytes: 340_623
            },
            pagefaults: 224_530,
            majorpagefaults: 0
          },
          start_time: '2021-03-30T07:59:06Z',
          name: 'container-name-44'
        },
        namespace: 'namespace26'
      }
    }
  ]
)
puts response
const response = await client.bulk({
  index: "datastream",
  refresh: "true",
  operations: [
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:49:00Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 91153,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 463314616,
            },
            usage: {
              bytes: 307007078,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 585236,
            },
            rss: {
              bytes: 102728,
            },
            pagefaults: 120901,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:45:50Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 124501,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 982546514,
            },
            usage: {
              bytes: 360035574,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 1339884,
            },
            rss: {
              bytes: 381174,
            },
            pagefaults: 178473,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:44:50Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 38907,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 862723768,
            },
            usage: {
              bytes: 379572388,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 431227,
            },
            rss: {
              bytes: 386580,
            },
            pagefaults: 233166,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:44:40Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 86706,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 567160996,
            },
            usage: {
              bytes: 103266017,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 1724908,
            },
            rss: {
              bytes: 105431,
            },
            pagefaults: 233166,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:44:00Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 150069,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 639054643,
            },
            usage: {
              bytes: 265142477,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 1786511,
            },
            rss: {
              bytes: 189235,
            },
            pagefaults: 138172,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:42:40Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 82260,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 854735585,
            },
            usage: {
              bytes: 309798052,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 924058,
            },
            rss: {
              bytes: 110838,
            },
            pagefaults: 259073,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:42:10Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 153404,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 279586406,
            },
            usage: {
              bytes: 214904955,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 1047265,
            },
            rss: {
              bytes: 91914,
            },
            pagefaults: 302252,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:40:20Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 125613,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 822782853,
            },
            usage: {
              bytes: 100475044,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 2109932,
            },
            rss: {
              bytes: 278446,
            },
            pagefaults: 74843,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:40:10Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 100046,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 567160996,
            },
            usage: {
              bytes: 362826547,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 1986724,
            },
            rss: {
              bytes: 402801,
            },
            pagefaults: 296495,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
    {
      create: {},
    },
    {
      "@timestamp": "2022-06-21T15:38:30Z",
      kubernetes: {
        host: "gke-apps-0",
        node: "gke-apps-0-0",
        pod: "gke-apps-0-0-0",
        container: {
          cpu: {
            usage: {
              nanocores: 40018,
              core: {
                ns: 12828317850,
              },
              node: {
                pct: 0.0000277905,
              },
              limit: {
                pct: 0.0000277905,
              },
            },
          },
          memory: {
            available: {
              bytes: 1062428344,
            },
            usage: {
              bytes: 265142477,
              node: {
                pct: 0.01770037710617187,
              },
              limit: {
                pct: 0.00009923134671484496,
              },
            },
            workingset: {
              bytes: 2294743,
            },
            rss: {
              bytes: 340623,
            },
            pagefaults: 224530,
            majorpagefaults: 0,
          },
          start_time: "2021-03-30T07:59:06Z",
          name: "container-name-44",
        },
        namespace: "namespace26",
      },
    },
  ],
});
console.log(response);
PUT /datastream/_bulk?refresh
{"create": {}}
{"@timestamp":"2022-06-21T15:49:00Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":91153,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":463314616},"usage":{"bytes":307007078,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":585236},"rss":{"bytes":102728},"pagefaults":120901,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:45:50Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":124501,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":982546514},"usage":{"bytes":360035574,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":1339884},"rss":{"bytes":381174},"pagefaults":178473,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:44:50Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":38907,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":862723768},"usage":{"bytes":379572388,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":431227},"rss":{"bytes":386580},"pagefaults":233166,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:44:40Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":86706,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":567160996},"usage":{"bytes":103266017,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":1724908},"rss":{"bytes":105431},"pagefaults":233166,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:44:00Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":150069,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":639054643},"usage":{"bytes":265142477,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":1786511},"rss":{"bytes":189235},"pagefaults":138172,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:42:40Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":82260,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":854735585},"usage":{"bytes":309798052,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":924058},"rss":{"bytes":110838},"pagefaults":259073,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:42:10Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":153404,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":279586406},"usage":{"bytes":214904955,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":1047265},"rss":{"bytes":91914},"pagefaults":302252,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:40:20Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":125613,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":822782853},"usage":{"bytes":100475044,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":2109932},"rss":{"bytes":278446},"pagefaults":74843,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:40:10Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":100046,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":567160996},"usage":{"bytes":362826547,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":1986724},"rss":{"bytes":402801},"pagefaults":296495,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}
{"create": {}}
{"@timestamp":"2022-06-21T15:38:30Z","kubernetes":{"host":"gke-apps-0","node":"gke-apps-0-0","pod":"gke-apps-0-0-0","container":{"cpu":{"usage":{"nanocores":40018,"core":{"ns":12828317850},"node":{"pct":2.77905e-05},"limit":{"pct":2.77905e-05}}},"memory":{"available":{"bytes":1062428344},"usage":{"bytes":265142477,"node":{"pct":0.01770037710617187},"limit":{"pct":9.923134671484496e-05}},"workingset":{"bytes":2294743},"rss":{"bytes":340623},"pagefaults":224530,"majorpagefaults":0},"start_time":"2021-03-30T07:59:06Z","name":"container-name-44"},"namespace":"namespace26"}}

查看数据流的当前状态

编辑

现在您已经创建了数据流并向其中添加了文档,请检查以确认新索引的当前状态。

resp = client.indices.get_data_stream()
print(resp)
response = client.indices.get_data_stream
puts response
const response = await client.indices.getDataStream();
console.log(response);
GET _data_stream

如果尚未应用数据流生命周期策略,则您的结果将如下所示。请注意原始的index_name.ds-datastream-2024.04.29-000001

{
  "data_streams": [
    {
      "name": "datastream",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "indices": [
        {
          "index_name": ".ds-datastream-2024.04.29-000001",
          "index_uuid": "vUMNtCyXQhGdlo1BD-cGRw",
          "managed_by": "Data stream lifecycle"
        }
      ],
      "generation": 1,
      "status": "GREEN",
      "template": "datastream_template",
      "lifecycle": {
        "enabled": true,
        "downsampling": [
          {
            "after": "1m",
            "fixed_interval": "1h"
          }
        ]
      },
      "next_generation_managed_by": "Data stream lifecycle",
      "hidden": false,
      "system": false,
      "allow_custom_routing": false,
      "replicated": false,
      "rollover_on_write": false,
      "time_series": {
        "temporal_ranges": [
          {
            "start": "2024-04-29T15:55:46.000Z",
            "end": "2024-04-29T18:25:46.000Z"
          }
        ]
      }
    }
  ]
}

接下来,运行搜索查询

resp = client.search(
    index="datastream",
)
print(resp)
response = client.search(
  index: 'datastream'
)
puts response
const response = await client.search({
  index: "datastream",
});
console.log(response);
GET datastream/_search

该查询将返回您新添加的十个文档。

{
  "took": 23,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10,
      "relation": "eq"
    },
...

滚动数据流

编辑

数据流生命周期将自动滚动数据流并执行降采样。此步骤仅在为了在本教程的范围内查看降采样结果时才需要。

使用滚动 API滚动数据流

const response = await client.indices.rollover({
  alias: "datastream",
});
console.log(response);
POST /datastream/_rollover/

查看降采样结果

编辑

默认情况下,数据流生命周期操作每五分钟执行一次。降采样发生在索引滚动之后,并且索引时间序列结束时间已过,因为预计源索引在此之前仍会接收主要写入。索引在之前的步骤后现在已滚动,但其时间序列范围结束很可能仍在未来。一旦索引时间序列范围过去,请重新运行GET _data_stream请求。

resp = client.indices.get_data_stream()
print(resp)
response = client.indices.get_data_stream
puts response
const response = await client.indices.getDataStream();
console.log(response);
GET _data_stream

在执行数据流生命周期操作后,原始的.ds-datastream-2024.04.29-000001索引将被新的降采样索引替换,在本例中为downsample-1h-.ds-datastream-2024.04.29-000001

{
  "data_streams": [
    {
      "name": "datastream",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "indices": [
        {
          "index_name": "downsample-1h-.ds-datastream-2024.04.29-000001",
          "index_uuid": "VqXuShP4T8ODAOnWFcqitg",
          "managed_by": "Data stream lifecycle"
        },
        {
          "index_name": ".ds-datastream-2024.04.29-000002",
          "index_uuid": "8gCeSdjUSWG-o-PeEAJ0jA",
          "managed_by": "Data stream lifecycle"
        }
      ],
...

对数据流运行搜索查询(请注意,在查询降采样索引时,有一些需要注意的细微差别)。

resp = client.search(
    index="datastream",
)
print(resp)
response = client.search(
  index: 'datastream'
)
puts response
const response = await client.search({
  index: "datastream",
});
console.log(response);
GET datastream/_search

新的降采样索引只包含一个文档,其中包括基于原始采样指标的minmaxsumvalue_count统计信息。

{
  "took": 26,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "downsample-1h-.ds-datastream-2024.04.29-000001",
        "_id": "0eL0wMf38sl_s5JnAAABjyrMjoA",
        "_score": 1,
        "_source": {
          "@timestamp": "2024-04-29T17:00:00.000Z",
          "_doc_count": 10,
          "kubernetes": {
            "container": {
              "cpu": {
                "usage": {
                  "core": {
                    "ns": 12828317850
                  },
                  "limit": {
                    "pct": 0.0000277905
                  },
                  "nanocores": {
                    "min": 38907,
                    "max": 153404,
                    "sum": 992677,
                    "value_count": 10
                  },
                  "node": {
                    "pct": 0.0000277905
                  }
                }
              },
              "memory": {
                "available": {
                  "bytes": {
                    "min": 279586406,
                    "max": 1062428344,
                    "sum": 7101494721,
                    "value_count": 10
                  }
                },
                "majorpagefaults": 0,
                "pagefaults": {
                  "min": 74843,
                  "max": 302252,
                  "sum": 2061071,
                  "value_count": 10
                },
                "rss": {
                  "bytes": {
                    "min": 91914,
                    "max": 402801,
                    "sum": 2389770,
                    "value_count": 10
                  }
                },
                "usage": {
                  "bytes": {
                    "min": 100475044,
                    "max": 379572388,
                    "sum": 2668170609,
                    "value_count": 10
                  },
                  "limit": {
                    "pct": 0.00009923134
                  },
                  "node": {
                    "pct": 0.017700378
                  }
                },
                "workingset": {
                  "bytes": {
                    "min": 431227,
                    "max": 2294743,
                    "sum": 14230488,
                    "value_count": 10
                  }
                }
              },
              "name": "container-name-44",
              "start_time": "2021-03-30T07:59:06.000Z"
            },
            "host": "gke-apps-0",
            "namespace": "namespace26",
            "node": "gke-apps-0-0",
            "pod": "gke-apps-0-0-0"
          }
        }
      }
    ]
  }
}

使用数据流统计 API获取数据流的统计信息,包括存储大小。

resp = client.indices.data_streams_stats(
    name="datastream",
    human=True,
)
print(resp)
response = client.indices.data_streams_stats(
  name: 'datastream',
  human: true
)
puts response
const response = await client.indices.dataStreamsStats({
  name: "datastream",
  human: "true",
});
console.log(response);
GET /_data_stream/datastream/_stats?human=true
{
  "_shards": {
    "total": 4,
    "successful": 4,
    "failed": 0
  },
  "data_stream_count": 1,
  "backing_indices": 2,
  "total_store_size": "37.3kb",
  "total_store_size_bytes": 38230,
  "data_streams": [
    {
      "data_stream": "datastream",
      "backing_indices": 2,
      "store_size": "37.3kb",
      "store_size_bytes": 38230,
      "maximum_timestamp": 1714410000000
    }
  ]
}

此示例演示了降采样如何作为数据流生命周期的一部分工作,以减少指标数据的存储大小,因为它的时效性降低且查询频率降低。