{"id":5701,"date":"2026-01-02T10:19:00","date_gmt":"2026-01-02T10:19:00","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5701"},"modified":"2026-01-03T16:03:02","modified_gmt":"2026-01-03T16:03:02","slug":"k6-grifana","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/k6-grifana\/","title":{"rendered":"K6 Grifana"},"content":{"rendered":"<p>Below Script sends GET request once. It creates a single Virtual User(VU) and sends the get request.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport http from 'k6\/http';\r\nimport { check } from 'k6';\r\n\r\nexport default function () {\r\n  \/\/ Target URL\r\n  let res = http.get('https:\/\/httpbin.test.k6.io\/get');\r\n\r\n  \/\/ Basic check to ensure status is 200\r\n  check(res, {\r\n    'status is 200': (r) =&gt; r.status === 200,\r\n  });\r\n\r\n  \/\/ Print response body to console\r\n  \/\/console.log(res.body);\r\n}\r\n<\/pre>\n<pre>\r\nk6 run test.js\r\n<\/pre>\n<p>To make the same script run for a duration. In this case the number of iterations varies based on how fast the request is completed based on keeping user constant 1(VU).<\/p>\n<pre>\r\nk6 run test.js --duration 5s\r\n<\/pre>\n<p>To make the same script run for a iteration. In this case the number of iterations would be 5 and VU is 1.<\/p>\n<pre>\r\nk6 run test.js --iterations 5\r\n<\/pre>\n<p>Below Script sends GET request and sleeps for 1 second. So if we run the test for 5 seconds then we run 4 request by same user<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport http from 'k6\/http';\r\nimport { check } from 'k6';\r\nimport { sleep } from 'k6';\r\n\r\nexport default function () {\r\n  \/\/ Target URL\r\n  let res = http.get('https:\/\/httpbin.test.k6.io\/get');\r\n  sleep(1);\r\n\r\n  \/\/ Basic check to ensure status is 200\r\n  check(res, {\r\n    'status is 200': (r) =&gt; r.status === 200,\r\n  });\r\n\r\n  \/\/ Print response body to console\r\n  \/\/console.log(res.body);\r\n}\r\n<\/pre>\n<p>To make the same script run for a 10 iteration and 10 VUs.<\/p>\n<pre>\r\nk6 run test.js -i 10 -u 10\r\n<\/pre>\n<p>Instead of supplying in command argument we can do the same thing by defining in constant as below <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport http from 'k6\/http';\r\nimport { check } from 'k6';\r\n\r\nexport const options = {\r\n  vus: 10,          \/\/ fixed number of VUs\r\n  iterations: 10  \/\/ each VU loops for 30 seconds\r\n};\r\n\r\nexport default function () {\r\n  let res = http.get('https:\/\/httpbin.test.k6.io\/get');\r\n\r\n\r\n  check(res, {\r\n    'status is 200': (r) =&gt; r.status === 200,\r\n  });\r\n\r\n  \/\/console.log(res.body);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Below Script sends GET request once. It creates a single Virtual User(VU) and sends the get request. import http from &#8216;k6\/http&#8217;; import { check } from &#8216;k6&#8217;; export default function () { \/\/ Target URL let res = http.get(&#8216;https:\/\/httpbin.test.k6.io\/get&#8217;); \/\/ Basic check to ensure status is 200 check(res, { &#8216;status is 200&#8217;: (r) =&gt; r.status&hellip; <a href=\"https:\/\/codethataint.com\/blog\/k6-grifana\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[373],"tags":[],"class_list":["post-5701","post","type-post","status-publish","format-standard","hentry","category-grifana"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5701"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5701\/revisions"}],"predecessor-version":[{"id":5708,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5701\/revisions\/5708"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}