downsampling-ilm.asciidoc 22 KB

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