downsampling-ilm.asciidoc 22 KB

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