downsampling-ilm.asciidoc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. [[downsampling-ilm]]
  2. === Run downsampling with ILM
  3. ++++
  4. <titleabbrev>Run downsampling with ILM</titleabbrev>
  5. ++++
  6. This is a simplified example that allows you to see quickly how
  7. <<downsampling,downsampling>> works as part of an ILM policy to reduce the
  8. storage size of a sampled set of metrics. The example uses typical Kubernetes
  9. cluster monitoring data. To test out downsampling with ILM, follow these steps:
  10. . Check the <<downsampling-ilm-prereqs,prerequisites>>.
  11. . <<downsampling-ilm-policy>>.
  12. . <<downsampling-ilm-create-index-template>>.
  13. . <<downsampling-ilm-ingest-data>>.
  14. . <<downsampling-ilm-view-results>>.
  15. [discrete]
  16. [[downsampling-ilm-prereqs]]
  17. ==== Prerequisites
  18. Refer to <<tsds-prereqs,time series data stream prerequisites>>.
  19. Before running this example you may want to try the
  20. <<downsampling-manual,Run downsampling manually>> example.
  21. [discrete]
  22. [[downsampling-ilm-policy]]
  23. ==== Create an index lifecycle policy
  24. Create an ILM policy for your time series data. While not required, an ILM
  25. policy is recommended to automate the management of your time series data stream
  26. indices.
  27. To enable downsampling, add a <<ilm-downsample,Downsample action>> and set
  28. <<ilm-downsample-options,`fixed_interval`>> to the downsampling interval at
  29. which you want to aggregate the original time series data.
  30. In this example, an ILM policy is configured for the `hot` phase. The downsample
  31. takes place after the index is rolled over and the <<index-time-series-end-time, index time series end time>>
  32. has lapsed as the source index is still expected to receive major writes until then.
  33. {ilm-cap} will not proceed with any action that expects the index to not receive
  34. writes anymore until the <<index-time-series-end-time, index's end time>> has
  35. passed. The {ilm-cap} actions that wait on the end time before proceeding are:
  36. - <<ilm-delete>>
  37. - <<ilm-downsample>>
  38. - <<ilm-forcemerge>>
  39. - <<ilm-readonly>>
  40. - <<ilm-searchable-snapshot>>
  41. - <<ilm-shrink>>
  42. [source,console]
  43. ----
  44. PUT _ilm/policy/datastream_policy
  45. {
  46. "policy": {
  47. "phases": {
  48. "hot": {
  49. "actions": {
  50. "rollover" : {
  51. "max_age": "5m"
  52. },
  53. "downsample": {
  54. "fixed_interval": "1h"
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. ----
  62. [discrete]
  63. [[downsampling-ilm-create-index-template]]
  64. ==== Create an index template
  65. This creates an index template for a basic data stream. The available parameters
  66. for an index template are described in detail in <<set-up-a-data-stream,Set up a
  67. time series data stream>>.
  68. For simplicity, in the time series mapping all `time_series_metric` parameters
  69. are set to type `gauge`, but the `counter` metric type may also be used. The
  70. `time_series_metric` values determine the kind of statistical representations
  71. that are used during downsampling.
  72. The index template includes a set of static <<time-series-dimension,time series
  73. dimensions>>: `host`, `namespace`, `node`, and `pod`. The time series dimensions
  74. are not changed by the downsampling process.
  75. [source,console]
  76. ----
  77. PUT _index_template/datastream_template
  78. {
  79. "index_patterns": [
  80. "datastream*"
  81. ],
  82. "data_stream": {},
  83. "template": {
  84. "settings": {
  85. "index": {
  86. "mode": "time_series",
  87. "number_of_replicas": 0,
  88. "number_of_shards": 2
  89. },
  90. "index.lifecycle.name": "datastream_policy"
  91. },
  92. "mappings": {
  93. "properties": {
  94. "@timestamp": {
  95. "type": "date"
  96. },
  97. "kubernetes": {
  98. "properties": {
  99. "container": {
  100. "properties": {
  101. "cpu": {
  102. "properties": {
  103. "usage": {
  104. "properties": {
  105. "core": {
  106. "properties": {
  107. "ns": {
  108. "type": "long"
  109. }
  110. }
  111. },
  112. "limit": {
  113. "properties": {
  114. "pct": {
  115. "type": "float"
  116. }
  117. }
  118. },
  119. "nanocores": {
  120. "type": "long",
  121. "time_series_metric": "gauge"
  122. },
  123. "node": {
  124. "properties": {
  125. "pct": {
  126. "type": "float"
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. },
  134. "memory": {
  135. "properties": {
  136. "available": {
  137. "properties": {
  138. "bytes": {
  139. "type": "long",
  140. "time_series_metric": "gauge"
  141. }
  142. }
  143. },
  144. "majorpagefaults": {
  145. "type": "long"
  146. },
  147. "pagefaults": {
  148. "type": "long",
  149. "time_series_metric": "gauge"
  150. },
  151. "rss": {
  152. "properties": {
  153. "bytes": {
  154. "type": "long",
  155. "time_series_metric": "gauge"
  156. }
  157. }
  158. },
  159. "usage": {
  160. "properties": {
  161. "bytes": {
  162. "type": "long",
  163. "time_series_metric": "gauge"
  164. },
  165. "limit": {
  166. "properties": {
  167. "pct": {
  168. "type": "float"
  169. }
  170. }
  171. },
  172. "node": {
  173. "properties": {
  174. "pct": {
  175. "type": "float"
  176. }
  177. }
  178. }
  179. }
  180. },
  181. "workingset": {
  182. "properties": {
  183. "bytes": {
  184. "type": "long",
  185. "time_series_metric": "gauge"
  186. }
  187. }
  188. }
  189. }
  190. },
  191. "name": {
  192. "type": "keyword"
  193. },
  194. "start_time": {
  195. "type": "date"
  196. }
  197. }
  198. },
  199. "host": {
  200. "type": "keyword",
  201. "time_series_dimension": true
  202. },
  203. "namespace": {
  204. "type": "keyword",
  205. "time_series_dimension": true
  206. },
  207. "node": {
  208. "type": "keyword",
  209. "time_series_dimension": true
  210. },
  211. "pod": {
  212. "type": "keyword",
  213. "time_series_dimension": true
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. ----
  222. // TEST[continued]
  223. ////
  224. [source,console]
  225. ----
  226. DELETE _index_template/*
  227. ----
  228. // TEST[continued]
  229. ////
  230. [discrete]
  231. [[downsampling-ilm-ingest-data]]
  232. ==== Ingest time series data
  233. Use a bulk API request to automatically create your TSDS and index a set of ten
  234. documents.
  235. **Important:** Before running this bulk request you need to update the
  236. timestamps to within three to five hours after your current time. That is,
  237. search `2022-06-21T15` and replace with your present date, and adjust the hour
  238. to your current time plus three hours.
  239. [source,console]
  240. ----
  241. PUT /datastream/_bulk?refresh
  242. {"create": {}}
  243. {"@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"}}
  244. {"create": {}}
  245. {"@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"}}
  246. {"create": {}}
  247. {"@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"}}
  248. {"create": {}}
  249. {"@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"}}
  250. {"create": {}}
  251. {"@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"}}
  252. {"create": {}}
  253. {"@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"}}
  254. {"create": {}}
  255. {"@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"}}
  256. {"create": {}}
  257. {"@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"}}
  258. {"create": {}}
  259. {"@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"}}
  260. {"create": {}}
  261. {"@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"}}
  262. ----
  263. // TEST[skip: The @timestamp value won't match an accepted range in the TSDS]
  264. [discrete]
  265. [[downsampling-ilm-view-results]]
  266. ==== View the results
  267. Now that you've created and added documents to the data stream, check to confirm
  268. the current state of the new index.
  269. [source,console]
  270. ----
  271. GET _data_stream
  272. ----
  273. // TEST[skip: The @timestamp value won't match an accepted range in the TSDS]
  274. If the ILM policy has not yet been applied, your results will be like the
  275. following. Note the original `index_name`: `.ds-datastream-<timestamp>-000001`.
  276. [source,console-result]
  277. ----
  278. {
  279. "data_streams": [
  280. {
  281. "name": "datastream",
  282. "timestamp_field": {
  283. "name": "@timestamp"
  284. },
  285. "indices": [
  286. {
  287. "index_name": ".ds-datastream-2022.08.26-000001",
  288. "index_uuid": "5g-3HrfETga-5EFKBM6R-w"
  289. },
  290. {
  291. "index_name": ".ds-datastream-2022.08.26-000002",
  292. "index_uuid": "o0yRTdhWSo2pY8XMvfwy7Q"
  293. }
  294. ],
  295. "generation": 2,
  296. "status": "GREEN",
  297. "template": "datastream_template",
  298. "ilm_policy": "datastream_policy",
  299. "hidden": false,
  300. "system": false,
  301. "allow_custom_routing": false,
  302. "replicated": false,
  303. "rollover_on_write": false,
  304. "time_series": {
  305. "temporal_ranges": [
  306. {
  307. "start": "2022-08-26T13:29:07.000Z",
  308. "end": "2022-08-26T19:29:07.000Z"
  309. }
  310. ]
  311. }
  312. }
  313. ]
  314. }
  315. ----
  316. // TEST[skip:todo]
  317. // TEST[continued]
  318. Next, run a search query:
  319. [source,console]
  320. ----
  321. GET datastream/_search
  322. ----
  323. // TEST[skip: The @timestamp value won't match an accepted range in the TSDS]
  324. The query returns your ten newly added documents.
  325. [source,console-result]
  326. ----
  327. {
  328. "took": 17,
  329. "timed_out": false,
  330. "_shards": {
  331. "total": 4,
  332. "successful": 4,
  333. "skipped": 0,
  334. "failed": 0
  335. },
  336. "hits": {
  337. "total": {
  338. "value": 10,
  339. "relation": "eq"
  340. },
  341. ...
  342. ----
  343. // TEST[skip:todo]
  344. // TEST[continued]
  345. By default, index lifecycle management checks every ten minutes for indices that
  346. meet policy criteria. Wait for about ten minutes (maybe brew up a quick coffee
  347. or tea &#9749; ) and then re-run the `GET _data_stream` request.
  348. [source,console]
  349. ----
  350. GET _data_stream
  351. ----
  352. // TEST[skip: The @timestamp value won't match an accepted range in the TSDS]
  353. After the ILM policy has taken effect, the original
  354. `.ds-datastream-2022.08.26-000001` index is replaced with a new, downsampled
  355. index, in this case `downsample-6tkn-.ds-datastream-2022.08.26-000001`.
  356. [source,console-result]
  357. ----
  358. {
  359. "data_streams": [
  360. {
  361. "name": "datastream",
  362. "timestamp_field": {
  363. "name": "@timestamp"
  364. },
  365. "indices": [
  366. {
  367. "index_name": "downsample-6tkn-.ds-datastream-2022.08.26-000001",
  368. "index_uuid": "qRane1fQQDCNgKQhXmTIvg"
  369. },
  370. {
  371. "index_name": ".ds-datastream-2022.08.26-000002",
  372. "index_uuid": "o0yRTdhWSo2pY8XMvfwy7Q"
  373. }
  374. ],
  375. ...
  376. ----
  377. // TEST[skip:todo]
  378. // TEST[continued]
  379. Run a search query on the datastream (note that when querying downsampled indices there are <<querying-downsampled-indices-notes,a few nuances to be aware of>>).
  380. [source,console]
  381. ----
  382. GET datastream/_search
  383. ----
  384. // TEST[continued]
  385. The new downsampled index contains just one document that includes the `min`,
  386. `max`, `sum`, and `value_count` statistics based off of the original sampled
  387. metrics.
  388. [source,console-result]
  389. ----
  390. {
  391. "took": 6,
  392. "timed_out": false,
  393. "_shards": {
  394. "total": 4,
  395. "successful": 4,
  396. "skipped": 0,
  397. "failed": 0
  398. },
  399. "hits": {
  400. "total": {
  401. "value": 1,
  402. "relation": "eq"
  403. },
  404. "max_score": 1,
  405. "hits": [
  406. {
  407. "_index": "downsample-6tkn-.ds-datastream-2022.08.26-000001",
  408. "_id": "0eL0wC_4-45SnTNFAAABgtpz0wA",
  409. "_score": 1,
  410. "_source": {
  411. "@timestamp": "2022-08-26T14:00:00.000Z",
  412. "_doc_count": 10,
  413. "kubernetes.host": "gke-apps-0",
  414. "kubernetes.namespace": "namespace26",
  415. "kubernetes.node": "gke-apps-0-0",
  416. "kubernetes.pod": "gke-apps-0-0-0",
  417. "kubernetes.container.cpu.usage.nanocores": {
  418. "min": 38907,
  419. "max": 153404,
  420. "sum": 992677,
  421. "value_count": 10
  422. },
  423. "kubernetes.container.memory.available.bytes": {
  424. "min": 279586406,
  425. "max": 1062428344,
  426. "sum": 7101494721,
  427. "value_count": 10
  428. },
  429. "kubernetes.container.memory.pagefaults": {
  430. "min": 74843,
  431. "max": 302252,
  432. "sum": 2061071,
  433. "value_count": 10
  434. },
  435. "kubernetes.container.memory.rss.bytes": {
  436. "min": 91914,
  437. "max": 402801,
  438. "sum": 2389770,
  439. "value_count": 10
  440. },
  441. "kubernetes.container.memory.usage.bytes": {
  442. "min": 100475044,
  443. "max": 379572388,
  444. "sum": 2668170609,
  445. "value_count": 10
  446. },
  447. "kubernetes.container.memory.workingset.bytes": {
  448. "min": 431227,
  449. "max": 2294743,
  450. "sum": 14230488,
  451. "value_count": 10
  452. },
  453. "kubernetes.container.cpu.usage.core.ns": 12828317850,
  454. "kubernetes.container.cpu.usage.limit.pct": 0.000027790500098490156,
  455. "kubernetes.container.cpu.usage.node.pct": 0.000027790500098490156,
  456. "kubernetes.container.memory.majorpagefaults": 0,
  457. "kubernetes.container.memory.usage.limit.pct": 0.00009923134348355234,
  458. "kubernetes.container.memory.usage.node.pct": 0.017700377851724625,
  459. "kubernetes.container.name": "container-name-44",
  460. "kubernetes.container.start_time": "2021-03-30T07:59:06.000Z"
  461. }
  462. }
  463. ]
  464. }
  465. }
  466. ----
  467. // TEST[skip:todo]
  468. // TEST[continued]
  469. Use the <<data-stream-stats-api,data stream stats API>> to get statistics for
  470. the data stream, including the storage size.
  471. [source,console]
  472. ----
  473. GET /_data_stream/datastream/_stats?human=true
  474. ----
  475. // TEST[continued]
  476. [source,console-result]
  477. ----
  478. {
  479. "_shards": {
  480. "total": 4,
  481. "successful": 4,
  482. "failed": 0
  483. },
  484. "data_stream_count": 1,
  485. "backing_indices": 2,
  486. "total_store_size": "16.6kb",
  487. "total_store_size_bytes": 17059,
  488. "data_streams": [
  489. {
  490. "data_stream": "datastream",
  491. "backing_indices": 2,
  492. "store_size": "16.6kb",
  493. "store_size_bytes": 17059,
  494. "maximum_timestamp": 1661522400000
  495. }
  496. ]
  497. }
  498. ----
  499. // TEST[skip:todo]
  500. // TEST[continued]
  501. This example demonstrates how downsampling works as part of an ILM policy to
  502. reduce the storage size of metrics data as it becomes less current and less
  503. frequently queried.
  504. You can also try our <<downsampling-manual,Run downsampling manually>>
  505. example to learn how downsampling can work outside of an ILM policy.
  506. ////
  507. [source,console]
  508. ----
  509. DELETE _data_stream/*
  510. DELETE _index_template/*
  511. DELETE _ilm/policy/datastream_policy
  512. ----
  513. // TEST[continued]
  514. ////