diff --git a/app/vmselect/vmui/asset-manifest.json b/app/vmselect/vmui/asset-manifest.json index 956ea30844..82a7095ef1 100644 --- a/app/vmselect/vmui/asset-manifest.json +++ b/app/vmselect/vmui/asset-manifest.json @@ -1,13 +1,13 @@ { "files": { "main.css": "./static/css/main.fce049bf.css", - "main.js": "./static/js/main.4b213512.js", + "main.js": "./static/js/main.ff023df1.js", "static/js/685.bebe1265.chunk.js": "./static/js/685.bebe1265.chunk.js", - "static/media/MetricsQL.md": "./static/media/MetricsQL.aaabf95f2c9bf356bde4.md", + "static/media/MetricsQL.md": "./static/media/MetricsQL.3de5efa763ef6e05a579.md", "index.html": "./index.html" }, "entrypoints": [ "static/css/main.fce049bf.css", - "static/js/main.4b213512.js" + "static/js/main.ff023df1.js" ] } \ No newline at end of file diff --git a/app/vmselect/vmui/index.html b/app/vmselect/vmui/index.html index a7a33c4324..60135eb88f 100644 --- a/app/vmselect/vmui/index.html +++ b/app/vmselect/vmui/index.html @@ -1 +1 @@ -
'+(n?e:Zo(e,!0))+"
\n":""+(n?e:Zo(e,!0))+"
\n"}blockquote(e){return"\n".concat(e,"\n")}html(e,t){return e}heading(e,t,n){return"
".concat(e,"
\n")}table(e,t){return t&&(t="".concat(t,"")),"".concat(e,"
")}br(){return"An error occurred:
"+Zo(n.message+"",!0)+"";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}const Ji=new class{constructor(){Do(this,Qi),Do(this,Ki),Ho(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),Ho(this,"options",this.setOptions),Ho(this,"parse",zo(this,Ki,Zi).call(this,Ui.lex,Yi.parse)),Ho(this,"parseInline",zo(this,Ki,Zi).call(this,Ui.lexInline,Yi.parseInline)),Ho(this,"Parser",Yi),Ho(this,"Renderer",Bi),Ho(this,"TextRenderer",qi),Ho(this,"Lexer",Ui),Ho(this,"Tokenizer",ii),Ho(this,"Hooks",Wi),this.use(...arguments)}walkTokens(e,t){let n=[];for(const a of e)switch(n=n.concat(t.call(this,a)),a.type){case"table":{const e=a;for(const r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(const r of e.rows)for(const e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=a;n=n.concat(this.walkTokens(e.items,t));break}default:{var r;const e=a;null!==(r=this.defaults.extensions)&&void 0!==r&&null!==(r=r.childTokens)&&void 0!==r&&r[e.type]?this.defaults.extensions.childTokens[e.type].forEach((r=>{const a=e[r].flat(1/0);n=n.concat(this.walkTokens(a,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(){const e=this.defaults.extensions||{renderers:{},childTokens:{}};for(var t=arguments.length,n=new Array(t),r=0;r
\n This table returns a list of metrics with the highest cardinality.\n The cardinality of a metric is the number of time series associated with that metric,\n where each time series is defined as a unique combination of key-value label pairs.\n
\n\n When looking to reduce the number of active series in your data source,\n you can start by inspecting individual metrics with high cardinality\n (i.e. that have lots of active time series associated with them),\n since that single metric contributes a large fraction of the series that make up your total series count.\n
",seriesCountByLabelName:"\n\n This table returns a list of the labels with the highest number of series.\n
\n\n Use this table to identify labels that are storing dimensions with high cardinality\n (many different label values).\n
\n\n It is recommended to choose labels such that they have a finite set of values,\n since every unique combination of key-value label pairs creates a new time series\n and therefore can dramatically increase the number of time series in your system.\n
",seriesCountByFocusLabelValue:"\n\n This table returns a list of unique label values per selected label.\n
\n\n Use this table to identify label values that are storing per each selected series.\n
",labelValueCountByLabelName:"\n\n This table returns a list of labels with the highest number of the unique values.\n
\n ",seriesCountByLabelValuePair:"\n\n This table returns a list of the label values pairs with the highest number of series.\n
\n\n Use this table to identify unique label values pairs. This helps to identify same labels \n is applied to count timeseries in your system, since every unique combination of key-value label pairs \n creates a new time series and therefore can dramatically increase the number of time series in your system\n
"}}get tablesHeaders(){return{seriesCountByMetricName:lm,seriesCountByLabelName:sm,seriesCountByFocusLabelValue:cm,seriesCountByLabelValuePair:um,labelValueCountByLabelName:dm}}totalSeries(e){return"labelValueCountByLabelName"===e?-1:arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.tsdbStatus.totalSeriesPrev:this.tsdbStatus.totalSeries}}const lm=[{id:"name",label:"Metric name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of a metric to the total number of series"},{id:"action",label:""}],sm=[{id:"name",label:"Label name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label to the total number of series"},{id:"action",label:""}],cm=[{id:"name",label:"Label value"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total"},{disablePadding:!1,id:"action",label:"",numeric:!1}],um=[{id:"name",label:"Label=value pair"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label value pair to the total number of series"},{id:"action",label:""}],dm=[{id:"name",label:"Label name"},{id:"value",label:"Number of unique values"},{id:"action",label:""}],hm=()=>{const e=new im,[t]=je(),n=t.get("match"),a=t.get("focusLabel"),i=+(t.get("topN")||10),l=t.get("date")||o()().tz().format(Lt),s=Va(l),c=(0,r.useRef)(),{serverUrl:u}=At(),[d,h]=(0,r.useState)(!1),[m,p]=(0,r.useState)(),[f,v]=(0,r.useState)(e.defaultTSDBStatus),[g,y]=(0,r.useState)(!1),_=async e=>{const t=await fetch(e);if(t.ok)return await t.json();throw new Error("Request failed with status ".concat(t.status))},b=async t=>{if(!u)return;p(""),h(!0),v(e.defaultTSDBStatus);const r={...t,date:t.date,topN:0,match:"",focusLabel:""},a={...t,date:o()(t.date).subtract(1,"day").format(Lt)},i=[om(u,t),om(u,a)];s!==l&&(t.match||t.focusLabel)&&i.push(om(u,r));try{var d,m,g,y,b,w,k,x,S,C;const[e,t,r]=await Promise.all(i.map(_)),a={...t.data},{data:o}=r||c.current||e;c.current={data:o};const l={...e.data,totalSeries:(null===(d=e.data)||void 0===d?void 0:d.totalSeries)||(null===(m=e.data)||void 0===m||null===(g=m.headStats)||void 0===g?void 0:g.numSeries)||0,totalLabelValuePairs:(null===(y=e.data)||void 0===y?void 0:y.totalLabelValuePairs)||(null===(b=e.data)||void 0===b||null===(w=b.headStats)||void 0===w?void 0:w.numLabelValuePairs)||0,seriesCountByLabelName:(null===(k=e.data)||void 0===k?void 0:k.seriesCountByLabelName)||[],seriesCountByFocusLabelValue:(null===(x=e.data)||void 0===x?void 0:x.seriesCountByFocusLabelValue)||[],totalSeriesByAll:(null===o||void 0===o?void 0:o.totalSeries)||(null===o||void 0===o||null===(S=o.headStats)||void 0===S?void 0:S.numSeries)||f.totalSeriesByAll||0,totalSeriesPrev:(null===a||void 0===a?void 0:a.totalSeries)||(null===a||void 0===a||null===(C=a.headStats)||void 0===C?void 0:C.numSeries)||0},s=null===n||void 0===n?void 0:n.replace(/[{}"]/g,"");l.seriesCountByLabelValuePair=l.seriesCountByLabelValuePair.filter((e=>e.name!==s)),((e,t)=>{Object.keys(e).forEach((n=>{const r=n,a=e[r],o=t[r];Array.isArray(a)&&Array.isArray(o)&&a.forEach((e=>{var t;const n=null===(t=o.find((t=>t.name===e.name)))||void 0===t?void 0:t.value;e.diff=n?e.value-n:0,e.valuePrev=n||0}))}))})(l,a),v(l),h(!1)}catch(Ap){h(!1),Ap instanceof Error&&p("".concat(Ap.name,": ").concat(Ap.message))}};return(0,r.useEffect)((()=>{b({topN:i,match:n,date:l,focusLabel:a})}),[u,n,a,i,l]),(0,r.useEffect)((()=>{m&&(v(e.defaultTSDBStatus),h(!1))}),[m]),(0,r.useEffect)((()=>{const e=Ge(u);y(!!e)}),[u]),e.tsdbStatusData=f,{isLoading:d,appConfigurator:e,error:m,isCluster:g}},mm={seriesCountByMetricName:e=>{let{query:t}=e;return pm("__name__",t)},seriesCountByLabelName:e=>{let{query:t}=e;return"{".concat(t,'!=""}')},seriesCountByFocusLabelValue:e=>{let{query:t,focusLabel:n}=e;return pm(n,t)},seriesCountByLabelValuePair:e=>{let{query:t}=e;const n=t.split("="),r=n[0],a=n.slice(1).join("=");return pm(r,a)},labelValueCountByLabelName:e=>{let{query:t,match:n}=e;return""===n?"{".concat(t,'!=""}'):"".concat(n.replace("}",""),", ").concat(t,'!=""}')}},pm=(e,t)=>e?"{"+e+"="+JSON.stringify(t)+"}":"",fm=e=>{var t;let{totalSeries:n=0,totalSeriesPrev:r=0,totalSeriesAll:a=0,seriesCountByMetricName:o=[],isPrometheus:i}=e;const{isMobile:l}=Ur(),[s]=je(),c=s.get("match"),u=s.get("focusLabel"),d=/__name__/.test(c||""),h=(null===(t=o[0])||void 0===t?void 0:t.value)/a*100,m=n-r,p=Math.abs(m)/r*100,f=[{title:"Total series",value:n.toLocaleString("en-US"),dynamic:n&&r&&!i?"".concat(p.toFixed(2),"%"):"",display:!u,info:'The total number of active time series. \n A time series is uniquely identified by its name plus a set of its labels. \n For example, temperature{city="NY",country="US"} and temperature{city="SF",country="US"} \n are two distinct series, since they differ by the city label.'},{title:"Percentage from total",value:isNaN(h)?"-":"".concat(h.toFixed(2),"%"),display:d,info:"The share of these series in the total number of time series."}].filter((e=>e.display));return f.length?Et("div",{className:wr()({"vm-cardinality-totals":!0,"vm-cardinality-totals_mobile":l}),children:f.map((e=>{let{title:t,value:n,info:a,dynamic:o}=e;return Et("div",{className:"vm-cardinality-totals-card",children:[Et("h4",{className:"vm-cardinality-totals-card__title",children:[t,a&&Et(da,{title:Et("p",{className:"vm-cardinality-totals-card__tooltip",children:a}),children:Et("div",{className:"vm-cardinality-totals-card__info-icon",children:Et(Pn,{})})})]}),Et("span",{className:"vm-cardinality-totals-card__value",children:n}),!!o&&Et(da,{title:"in relation to the previous day: ".concat(r.toLocaleString("en-US")),children:Et("span",{className:wr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":m<0,"vm-dynamic-number_negative vm-dynamic-number_up":m>0}),children:o})})]},t)}))}):null},vm=(e,t)=>{const[n]=je(),a=n.get(t)?n.get(t):e,[o,i]=(0,r.useState)(a);return(0,r.useEffect)((()=>{a!==o&&i(a)}),[a]),[o,i]},gm=e=>{let{isPrometheus:t,isCluster:n,...a}=e;const{isMobile:o}=Ur(),[i]=je(),{setSearchParamsFromKeys:l}=ro(),s=i.get("tips")||"",[c,u]=vm("","match"),[d,h]=vm("","focusLabel"),[m,p]=vm(10,"topN"),f=(0,r.useMemo)((()=>m<0?"Number must be bigger than zero":""),[m]),v=()=>{l({match:c,topN:m,focusLabel:d})};return(0,r.useEffect)((()=>{const e=i.get("match"),t=+(i.get("topN")||10),n=i.get("focusLabel");e!==c&&u(e||""),t!==m&&p(t),n!==d&&h(n||"")}),[i]),Et("div",{className:wr()({"vm-cardinality-configurator":!0,"vm-cardinality-configurator_mobile":o,"vm-block":!0,"vm-block_mobile":o}),children:[Et("div",{className:"vm-cardinality-configurator-controls",children:[Et("div",{className:"vm-cardinality-configurator-controls__query",children:Et(ja,{label:"Time series selector",type:"string",value:c,onChange:u,onEnter:v})}),Et("div",{className:"vm-cardinality-configurator-controls__item",children:Et(ja,{label:"Focus label",type:"text",value:d||"",onChange:h,onEnter:v,endIcon:Et(da,{title:Et("div",{children:Et("p",{children:"To identify values with the highest number of series for the selected label."})}),children:Et(lr,{})})})}),Et("div",{className:"vm-cardinality-configurator-controls__item vm-cardinality-configurator-controls__item_limit",children:Et(ja,{label:"Limit entries",type:"number",value:t?10:m,error:f,disabled:t,helperText:t?"not available for Prometheus":"",onChange:e=>{const t=+e;p(isNaN(t)?0:t)},onEnter:v})})]}),Et("div",{className:"vm-cardinality-configurator-bottom",children:[Et(fm,{isPrometheus:t,isCluster:n,...a}),n&&Et("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Et(Ml,{href:"https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cardinality-explorer-statistic-inaccuracy",withIcon:!0,children:[Et(or,{}),"Statistic inaccuracy explanation"]})}),Et("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Et(Ml,{href:"https://docs.victoriametrics.com/#cardinality-explorer",withIcon:!0,children:[Et(or,{}),"Documentation"]})}),Et("div",{className:"vm-cardinality-configurator-bottom__execute",children:[Et(da,{title:s?"Hide tips":"Show tips",children:Et(ea,{variant:"text",color:s?"warning":"gray",startIcon:Et(dr,{}),onClick:()=>{const e=i.get("tips")||"";l({tips:e?"":"true"})},ariaLabel:"visibility tips"})}),Et(ea,{variant:"text",startIcon:Et(On,{}),onClick:()=>{l({match:"",focusLabel:""})},children:"Reset"}),Et(ea,{startIcon:Et(Bn,{}),onClick:v,children:"Execute Query"})]})]})]})};function ym(e){const{order:t,orderBy:n,onRequestSort:r,headerCells:a}=e;return Et("thead",{className:"vm-table-header vm-cardinality-panel-table__header",children:Et("tr",{className:"vm-table__row vm-table__row_header",children:a.map((e=>{return Et("th",{className:wr()({"vm-table-cell vm-table-cell_header":!0,"vm-table-cell_sort":"action"!==e.id&&"percentage"!==e.id,"vm-table-cell_right":"action"===e.id}),onClick:(a=e.id,e=>{r(e,a)}),children:Et("div",{className:"vm-table-cell__content",children:[e.info?Et(da,{title:e.info,children:[Et("div",{className:"vm-metrics-content-header__tip-icon",children:Et(Pn,{})}),e.label]}):Et(St.FK,{children:e.label}),"action"!==e.id&&"percentage"!==e.id&&Et("div",{className:wr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":n===e.id,"vm-table__sort-icon_desc":"desc"===t&&n===e.id}),children:Et(jn,{})})]})},e.id);var a}))})})}const _m=["date","timestamp","time"];function bm(e,t,n){const r=e[n],a=t[n],i=_m.includes("".concat(n))?o()("".concat(r)).unix():r,l=_m.includes("".concat(n))?o()("".concat(a)).unix():a;return li?1:0}function wm(e,t){return"desc"===e?(e,n)=>bm(e,n,t):(e,n)=>-bm(e,n,t)}function km(e,t){const n=e.map(((e,t)=>[e,t]));return n.sort(((e,n)=>{const r=t(e[0],n[0]);return 0!==r?r:e[1]-n[1]})),n.map((e=>e[0]))}const xm=e=>{let{rows:t,headerCells:n,defaultSortColumn:a,tableCells:o}=e;const[i,l]=(0,r.useState)("desc"),[s,c]=(0,r.useState)(a),u=km(t,wm(i,s));return Et("table",{className:"vm-table vm-cardinality-panel-table",children:[Et(ym,{order:i,orderBy:s,onRequestSort:(e,t)=>{l(s===t&&"asc"===i?"desc":"asc"),c(t)},rowCount:t.length,headerCells:n}),Et("tbody",{className:"vm-table-header",children:u.map((e=>Et("tr",{className:"vm-table__row",children:o(e)},e.name)))})]})},Sm=e=>{let{row:t,totalSeries:n,totalSeriesPrev:r,onActionClick:a}=e;const o=n>0?t.value/n*100:-1,i=r>0?t.valuePrev/r*100:-1,l=[o,i].some((e=>-1===e)),s=o-i,c=l?"":"".concat(s.toFixed(2),"%"),u=()=>{a(t.name)};return Et(St.FK,{children:[Et("td",{className:"vm-table-cell",children:Et("span",{className:"vm-link vm-link_colored",onClick:u,children:t.name})},t.name),Et("td",{className:"vm-table-cell",children:[t.value,!!t.diff&&Et(da,{title:"in relation to the previous day: ".concat(t.valuePrev),children:Et("span",{className:wr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive":t.diff<0,"vm-dynamic-number_negative":t.diff>0}),children:["\xa0",t.diff>0?"+":"",t.diff]})})]},t.value),o>0&&Et("td",{className:"vm-table-cell",children:Et("div",{className:"vm-cardinality-panel-table__progress",children:[Et(Pl,{value:o}),c&&Et(da,{title:"in relation to the previous day",children:Et("span",{className:wr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":s<0,"vm-dynamic-number_negative vm-dynamic-number_up":s>0}),children:c})})]})},t.progressValue),Et("td",{className:"vm-table-cell vm-table-cell_right",children:Et("div",{className:"vm-table-cell__content",children:Et(da,{title:"Filter by ".concat(t.name),children:Et(ea,{variant:"text",size:"small",onClick:u,children:Et(qn,{})})})})},"action")]})},Cm=e=>{let{data:t}=e;const[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)([0,0]);return(0,r.useEffect)((()=>{const e=t.sort(((e,t)=>t.value-e.value)),n=(e=>{const t=e.map((e=>e.value)),n=Math.ceil(t[0]||1),r=n/9;return new Array(11).fill(n+r).map(((e,t)=>Math.round(e-r*t)))})(e);i(n),a(e.map((e=>({...e,percentage:e.value/n[0]*100}))))}),[t]),Et("div",{className:"vm-simple-bar-chart",children:[Et("div",{className:"vm-simple-bar-chart-y-axis",children:o.map((e=>Et("div",{className:"vm-simple-bar-chart-y-axis__tick",children:e},e)))}),Et("div",{className:"vm-simple-bar-chart-data",children:n.map((e=>{let{name:t,value:n,percentage:r}=e;return Et(da,{title:"".concat(t,": ").concat(n),placement:"top-center",children:Et("div",{className:"vm-simple-bar-chart-data-item",style:{maxHeight:"".concat(r||0,"%")}})},"".concat(t,"_").concat(n))}))})]})},Em=e=>{let{rows:t,tabs:n=[],chartContainer:a,totalSeries:o,totalSeriesPrev:i,onActionClick:l,sectionTitle:s,tip:c,tableHeaderCells:u,isPrometheus:d}=e;const{isMobile:h}=Ur(),[m,p]=(0,r.useState)("table"),f=d&&!t.length,v=(0,r.useMemo)((()=>n.map(((e,t)=>({value:e,label:e,icon:Et(0===t?Wn:Yn,{})})))),[n]);return Et("div",{className:wr()({"vm-metrics-content":!0,"vm-metrics-content_mobile":h,"vm-block":!0,"vm-block_mobile":h}),children:[Et("div",{className:"vm-metrics-content-header vm-section-header",children:[Et("h5",{className:wr()({"vm-metrics-content-header__title":!0,"vm-section-header__title":!0,"vm-section-header__title_mobile":h}),children:[!h&&c&&Et(da,{title:Et("p",{dangerouslySetInnerHTML:{__html:c},className:"vm-metrics-content-header__tip"}),children:Et("div",{className:"vm-metrics-content-header__tip-icon",children:Et(Pn,{})})}),s]}),Et("div",{className:"vm-section-header__tabs",children:Et(Er,{activeItem:m,items:v,onChange:p})})]}),f&&Et("div",{className:"vm-metrics-content-prom-data",children:[Et("div",{className:"vm-metrics-content-prom-data__icon",children:Et(Pn,{})}),Et("h3",{className:"vm-metrics-content-prom-data__title",children:"Prometheus Data Limitation"}),Et("p",{className:"vm-metrics-content-prom-data__text",children:["Due to missing data from your Prometheus source, some tables may appear empty.",Et("br",{}),"This does not indicate an issue with your system or our tool."]})]}),!f&&"table"===m&&Et("div",{ref:a,className:wr()({"vm-metrics-content__table":!0,"vm-metrics-content__table_mobile":h}),children:Et(xm,{rows:t,headerCells:u,defaultSortColumn:"value",tableCells:e=>Et(Sm,{row:e,totalSeries:o,totalSeriesPrev:i,onActionClick:l})})}),!f&&"graph"===m&&Et("div",{className:"vm-metrics-content__chart",children:Et(Cm,{data:t.map((e=>{let{name:t,value:n}=e;return{name:t,value:n}}))})})]})},Nm=e=>{let{title:t,children:n}=e;return Et("div",{className:"vm-cardinality-tip",children:[Et("div",{className:"vm-cardinality-tip-header",children:[Et("div",{className:"vm-cardinality-tip-header__tip-icon",children:Et(dr,{})}),Et("h4",{className:"vm-cardinality-tip-header__title",children:t||"Tips"})]}),Et("p",{className:"vm-cardinality-tip__description",children:n})]})},Am=()=>Et(Nm,{title:"Metrics with a high number of series",children:Et("ul",{children:[Et("li",{children:["Identify and eliminate labels with frequently changed values to reduce their\xa0",Et(Ml,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-cardinality",children:"cardinality"}),"\xa0and\xa0",Et(Ml,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate",children:"high churn rate"})]}),Et("li",{children:["Find unused time series and\xa0",Et(Ml,{href:"https://docs.victoriametrics.com/relabeling.html",children:"drop entire metrics"})]}),Et("li",{children:["Aggregate time series before they got ingested into the database via\xa0",Et(Ml,{href:"https://docs.victoriametrics.com/stream-aggregation.html",children:"streaming aggregation"})]})]})}),Mm=()=>Et(Nm,{title:"Labels with a high number of unique values",children:Et("ul",{children:[Et("li",{children:"Decrease the number of unique label values to reduce cardinality"}),Et("li",{children:["Drop the label entirely via\xa0",Et(Ml,{href:"https://docs.victoriametrics.com/relabeling.html",children:"relabeling"})]}),Et("li",{children:"For volatile label values (such as URL path, user session, etc.) consider printing them to the log file instead of adding to time series"})]})}),Tm=()=>Et(Nm,{title:"Dashboard of a single metric",children:[Et("p",{children:"This dashboard helps to understand the cardinality of a single metric."}),Et("p",{children:"Each time series is a unique combination of key-value label pairs. Therefore a label key with many values can create a lot of time series for a particular metric. If you\u2019re trying to decrease the cardinality of a metric, start by looking at the labels with the highest number of values."}),Et("p",{children:"Use the series selector at the top of the page to apply additional filters."})]}),Lm=()=>Et(Nm,{title:"Dashboard of a label",children:[Et("p",{children:"This dashboard helps you understand the count of time series per label."}),Et("p",{children:"Use the selector at the top of the page to pick a label name you\u2019d like to inspect. For the selected label name, you\u2019ll see the label values that have the highest number of series associated with them. So if you\u2019ve chosen `instance` as your label name, you may see that `657` time series have value \u201chost-1\u201d attached to them and `580` time series have value `host-2` attached to them."}),Et("p",{children:"This can be helpful in allowing you to determine where the bulk of your time series are coming from. If the label \u201cinstance=host-1\u201d was applied to 657 series and the label \u201cinstance=host-2\u201d was only applied to 580 series, you\u2019d know, for example, that host-01 was responsible for sending the majority of the time series."})]}),Om=()=>{const{isMobile:e}=Ur(),[t]=je(),{setSearchParamsFromKeys:n}=ro(),r=t.get("tips")||"",a=t.get("match")||"",o=t.get("focusLabel")||"",{isLoading:i,appConfigurator:l,error:s,isCluster:c}=hm(),{tsdbStatusData:u,getDefaultState:d,tablesHeaders:h,sectionsTips:m}=l,p=d(a,o);return Et("div",{className:wr()({"vm-cardinality-panel":!0,"vm-cardinality-panel_mobile":e}),children:[i&&Et(yl,{message:"Please wait while cardinality stats is calculated. \n This may take some time if the db contains big number of time series."}),Et(gm,{isPrometheus:l.isPrometheusData,totalSeries:u.totalSeries,totalSeriesPrev:u.totalSeriesPrev,totalSeriesAll:u.totalSeriesByAll,totalLabelValuePairs:u.totalLabelValuePairs,seriesCountByMetricName:u.seriesCountByMetricName,isCluster:c}),r&&Et("div",{className:"vm-cardinality-panel-tips",children:[!a&&!o&&Et(Am,{}),a&&!o&&Et(Tm,{}),!a&&!o&&Et(Mm,{}),o&&Et(Lm,{})]}),s&&Et(qr,{variant:"error",children:s}),l.keys(a,o).map((e=>{return Et(Em,{sectionTitle:l.sectionsTitles(o)[e],tip:m[e],rows:u[e],onActionClick:(t=e,e=>{const r={match:mm[t]({query:e,focusLabel:o,match:a})};"labelValueCountByLabelName"!==t&&"seriesCountByLabelName"!=t||(r.focusLabel=e),"seriesCountByFocusLabelValue"==t&&(r.focusLabel=""),n(r)}),tabs:p.tabs[e],chartContainer:p.containerRefs[e],totalSeriesPrev:l.totalSeries(e,!0),totalSeries:l.totalSeries(e),tableHeaderCells:h[e],isPrometheus:l.isPrometheusData},e);var t}))]})},Pm=e=>(["topByAvgDuration","topByCount","topBySumDuration"].forEach((t=>{const n=e[t];Array.isArray(n)&&n.forEach((e=>{const t=Xt(1e3*e.timeRangeSeconds);e.url=((e,t)=>{var n;const{query:r,timeRangeSeconds:a}=e,o=["g0.expr=".concat(encodeURIComponent(r))],i=null===(n=nn.find((e=>e.duration===t)))||void 0===n?void 0:n.id;return i&&o.push("g0.relative_time=".concat(i)),a&&o.push("g0.range_input=".concat(t)),"".concat(Ye.home,"?").concat(o.join("&"))})(e,t),e.timeRange=t}))})),e),Im=e=>{let{topN:t,maxLifetime:n}=e;const{serverUrl:a}=At(),{setSearchParamsFromKeys:o}=ro(),[i,l]=(0,r.useState)(null),[s,c]=(0,r.useState)(!1),[u,d]=(0,r.useState)(),h=(0,r.useMemo)((()=>((e,t,n)=>"".concat(e,"/api/v1/status/top_queries?topN=").concat(t||"","&maxLifetime=").concat(n||""))(a,t,n)),[a,t,n]);return{data:i,error:u,loading:s,fetch:async()=>{c(!0),o({topN:t,maxLifetime:n});try{const e=await fetch(h),t=await e.json();l(e.ok?Pm(t):null),d(String(t.error||""))}catch(Ap){Ap instanceof Error&&"AbortError"!==Ap.name&&d("".concat(Ap.name,": ").concat(Ap.message))}c(!1)}}},Rm=e=>{let{rows:t,columns:n,defaultOrderBy:a}=e;const o=hl(),[i,l]=(0,r.useState)(a||"count"),[s,c]=(0,r.useState)("desc"),u=(0,r.useMemo)((()=>km(t,wm(s,i))),[t,i,s]),d=e=>()=>{var t;t=e,c((e=>"asc"===e&&i===t?"desc":"asc")),l(t)},h=e=>{let{query:t}=e;return async()=>{await o(t,"Query has been copied")}};return Et("table",{className:"vm-table",children:[Et("thead",{className:"vm-table-header",children:Et("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>Et("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:d(e.sortBy||e.key),children:Et("div",{className:"vm-table-cell__content",children:[e.title||e.key,Et("div",{className:wr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":i===e.key,"vm-table__sort-icon_desc":"desc"===s&&i===e.key}),children:Et(jn,{})})]})},e.key))),Et("th",{className:"vm-table-cell vm-table-cell_header"})," "]})}),Et("tbody",{className:"vm-table-body",children:u.map(((e,t)=>Et("tr",{className:"vm-table__row",children:[n.map((t=>Et("td",{className:"vm-table-cell",children:e[t.key]||"-"},t.key))),Et("td",{className:"vm-table-cell vm-table-cell_no-padding",children:Et("div",{className:"vm-top-queries-panels__table-actions",children:[e.url&&Et(da,{title:"Execute query",children:Et(Ie,{to:e.url,target:"_blank",rel:"noreferrer","aria-disabled":!0,children:Et(ea,{variant:"text",size:"small",startIcon:Et(qn,{}),ariaLabel:"execute query"})})}),Et(da,{title:"Copy query",children:Et(ea,{variant:"text",size:"small",startIcon:Et(nr,{}),onClick:h(e),ariaLabel:"copy query"})})]})})]},t)))})]})},Dm=["table","JSON"].map(((e,t)=>({value:String(t),label:e,icon:Et(0===t?Wn:Kn,{})}))),zm=e=>{let{rows:t,title:n,columns:a,defaultOrderBy:o}=e;const{isMobile:i}=Ur(),[l,s]=(0,r.useState)(0);return Et("div",{className:wr()({"vm-top-queries-panel":!0,"vm-block":!0,"vm-block_mobile":i}),children:[Et("div",{className:wr()({"vm-top-queries-panel-header":!0,"vm-section-header":!0,"vm-top-queries-panel-header_mobile":i}),children:[Et("h5",{className:wr()({"vm-section-header__title":!0,"vm-section-header__title_mobile":i}),children:n}),Et("div",{className:"vm-section-header__tabs",children:Et(Er,{activeItem:String(l),items:Dm,onChange:e=>{s(+e)}})})]}),Et("div",{className:wr()({"vm-top-queries-panel__table":!0,"vm-top-queries-panel__table_mobile":i}),children:[0===l&&Et(Rm,{rows:t,columns:a,defaultOrderBy:o}),1===l&&Et($h,{data:t})]})]})},Fm=()=>{const{isMobile:e}=Ur(),[t,n]=vm(10,"topN"),[a,i]=vm("10m","maxLifetime"),{data:l,error:s,loading:c,fetch:u}=Im({topN:t,maxLifetime:a}),d=(0,r.useMemo)((()=>{const e=a.trim().split(" ").reduce(((e,t)=>{const n=Wt(t);return n?{...e,...n}:{...e}}),{});return!!o().duration(e).asMilliseconds()}),[a]),h=(0,r.useMemo)((()=>!!t&&t<1),[t]),m=(0,r.useMemo)((()=>h?"Number must be bigger than zero":""),[h]),p=(0,r.useMemo)((()=>d?"":"Invalid duration value"),[d]),f=e=>{if(!l)return e;const t=l[e];return"number"===typeof t?Hd(t,t,t):t||e},v=e=>{"Enter"===e.key&&u()};return(0,r.useEffect)((()=>{l&&(t||n(+l.topN),a||i(l.maxLifetime))}),[l]),(0,r.useEffect)((()=>(u(),window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)})),[]),Et("div",{className:wr()({"vm-top-queries":!0,"vm-top-queries_mobile":e}),children:[c&&Et(yl,{containerStyles:{height:"500px"}}),Et("div",{className:wr()({"vm-top-queries-controls":!0,"vm-block":!0,"vm-block_mobile":e}),children:[Et("div",{className:"vm-top-queries-controls-fields",children:[Et("div",{className:"vm-top-queries-controls-fields__item",children:Et(ja,{label:"Max lifetime",value:a,error:p,helperText:"For example ".concat("30ms, 15s, 3d4h, 1y2w"),onChange:e=>{i(e)},onKeyDown:v})}),Et("div",{className:"vm-top-queries-controls-fields__item",children:Et(ja,{label:"Number of returned queries",type:"number",value:t||"",error:m,onChange:e=>{n(+e)},onKeyDown:v})})]}),Et("div",{className:wr()({"vm-top-queries-controls-bottom":!0,"vm-top-queries-controls-bottom_mobile":e}),children:[Et("div",{className:"vm-top-queries-controls-bottom__info",children:["VictoriaMetrics tracks the last\xa0",Et(da,{title:"search.queryStats.lastQueriesCount",children:Et("b",{children:f("search.queryStats.lastQueriesCount")})}),"\xa0queries with durations at least\xa0",Et(da,{title:"search.queryStats.minQueryDuration",children:Et("b",{children:f("search.queryStats.minQueryDuration")})})]}),Et("div",{className:"vm-top-queries-controls-bottom__button",children:Et(ea,{startIcon:Et(Bn,{}),onClick:u,children:"Execute"})})]})]}),s&&Et(qr,{variant:"error",children:s}),l&&Et(St.FK,{children:Et("div",{className:"vm-top-queries-panels",children:[Et(zm,{rows:l.topBySumDuration,title:"Queries with most summary time to execute",columns:[{key:"query"},{key:"sumDurationSeconds",title:"sum duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"sumDurationSeconds"}),Et(zm,{rows:l.topByAvgDuration,title:"Most heavy queries",columns:[{key:"query"},{key:"avgDurationSeconds",title:"avg duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"avgDurationSeconds"}),Et(zm,{rows:l.topByCount,title:"Most frequently executed queries",columns:[{key:"query"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}]})]})})]})},jm={"color-primary":"#589DF6","color-secondary":"#316eca","color-error":"#e5534b","color-warning":"#c69026","color-info":"#539bf5","color-success":"#57ab5a","color-background-body":"#22272e","color-background-block":"#2d333b","color-background-tooltip":"rgba(22, 22, 22, 0.8)","color-text":"#cdd9e5","color-text-secondary":"#768390","color-text-disabled":"#636e7b","box-shadow":"rgba(0, 0, 0, 0.16) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.2) 0px 2px 8px 0px","border-divider":"1px solid rgba(99, 110, 123, 0.5)","color-hover-black":"rgba(0, 0, 0, 0.12)","color-log-hits-bar":"rgba(255, 255, 255, 0.18)"},Hm={"color-primary":"#3F51B5","color-secondary":"#E91E63","color-error":"#FD080E","color-warning":"#FF8308","color-info":"#03A9F4","color-success":"#4CAF50","color-background-body":"#FEFEFF","color-background-block":"#FFFFFF","color-background-tooltip":"rgba(80,80,80,0.9)","color-text":"#110f0f","color-text-secondary":"#706F6F","color-text-disabled":"#A09F9F","box-shadow":"rgba(0, 0, 0, 0.08) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.1) 0px 2px 8px 0px","border-divider":"1px solid rgba(0, 0, 0, 0.15)","color-hover-black":"rgba(0, 0, 0, 0.06)","color-log-hits-bar":"rgba(0, 0, 0, 0.18)"},Vm=()=>{const[e,t]=(0,r.useState)(yt()),n=e=>{t(e.matches)};return(0,r.useEffect)((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)");return e.addEventListener("change",n),()=>e.removeEventListener("change",n)}),[]),e},$m=["primary","secondary","error","warning","info","success"],Um=e=>{let{onLoaded:t}=e;const n=Ke(),{palette:a={}}=We(),{theme:o}=At(),i=Vm(),l=Mt(),s=Cr(),[c,u]=(0,r.useState)({[pt.dark]:jm,[pt.light]:Hm,[pt.system]:yt()?jm:Hm}),d=()=>{const{innerWidth:e,innerHeight:t}=window,{clientWidth:n,clientHeight:r}=document.documentElement;gt("scrollbar-width","".concat(e-n,"px")),gt("scrollbar-height","".concat(t-r,"px")),gt("vh","".concat(.01*t,"px"))},h=()=>{$m.forEach(((e,n)=>{const r=(e=>{let t=e.replace("#","").trim();if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6!==t.length)throw new Error("Invalid HEX color.");return(299*parseInt(t.slice(0,2),16)+587*parseInt(t.slice(2,4),16)+114*parseInt(t.slice(4,6),16))/1e3>=128?"#000000":"#FFFFFF"})(vt("color-".concat(e)));gt("".concat(e,"-text"),r),n===$m.length-1&&(l({type:"SET_DARK_THEME"}),t(!0))}))},m=()=>{const e=Xe("THEME")||pt.system,t=c[e];Object.entries(t).forEach((e=>{let[t,n]=e;gt(t,n)})),h(),n&&($m.forEach((e=>{const t=a[e];t&>("color-".concat(e),t)})),h())};return(0,r.useEffect)((()=>{d(),m()}),[c]),(0,r.useEffect)(d,[s]),(0,r.useEffect)((()=>{const e=yt()?jm:Hm;c[pt.system]!==e?u((t=>({...t,[pt.system]:e}))):m()}),[o,i]),(0,r.useEffect)((()=>{n&&l({type:"SET_THEME",payload:pt.light})}),[]),null},Bm=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(!1),o=(0,r.useRef)(document.body),i=e=>{e.preventDefault(),e.stopPropagation(),"dragenter"===e.type||"dragover"===e.type?a(!0):"dragleave"===e.type&&a(!1)};return Sr("dragenter",i,o),Sr("dragleave",i,o),Sr("dragover",i,o),Sr("drop",(e=>{var n;e.preventDefault(),e.stopPropagation(),a(!1),null!==e&&void 0!==e&&null!==(n=e.dataTransfer)&&void 0!==n&&n.files&&e.dataTransfer.files[0]&&(e=>{const n=Array.from(e||[]);t(n)})(e.dataTransfer.files)}),o),Sr("paste",(e=>{var n;const r=null===(n=e.clipboardData)||void 0===n?void 0:n.items;if(!r)return;const a=Array.from(r).filter((e=>"application/json"===e.type)).map((e=>e.getAsFile())).filter((e=>null!==e));t(a)}),o),{files:e,dragging:n}},qm=e=>{let{onOpenModal:t,onChange:n}=e;return Et("div",{className:"vm-upload-json-buttons",children:[Et(ea,{variant:"outlined",onClick:t,children:"Paste JSON"}),Et(ea,{children:["Upload Files",Et("input",{id:"json",type:"file",accept:"application/json",multiple:!0,title:" ",onChange:n})]})]})},Ym=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)([]),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=na(!1),c=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";a((n=>[{filename:t,text:": ".concat(e.message)},...n]))},u=(e,n)=>{try{const r=JSON.parse(e),a=r.trace||r;if(!a.duration_msec)return void c(new Error(mt.traceNotFound),n);const o=new kl(a,n);t((e=>[o,...e]))}catch(Ap){Ap instanceof Error&&c(Ap,n)}},d=e=>{e.map((e=>{const t=new FileReader,n=(null===e||void 0===e?void 0:e.name)||"";t.onload=e=>{var t;const r=String(null===(t=e.target)||void 0===t?void 0:t.result);u(r,n)},t.readAsText(e)}))},h=e=>{a([]);const t=Array.from(e.target.files||[]);d(t),e.target.value=""},m=e=>()=>{(e=>{a((t=>t.filter(((t,n)=>n!==e))))})(e)},{files:p,dragging:f}=Bm();return(0,r.useEffect)((()=>{d(p)}),[p]),Et("div",{className:"vm-trace-page",children:[Et("div",{className:"vm-trace-page-header",children:[Et("div",{className:"vm-trace-page-header-errors",children:n.map(((e,t)=>Et("div",{className:"vm-trace-page-header-errors-item",children:[Et(qr,{variant:"error",children:[Et("b",{className:"vm-trace-page-header-errors-item__filename",children:e.filename}),Et("span",{children:e.text})]}),Et(ea,{className:"vm-trace-page-header-errors-item__close",startIcon:Et(Ln,{}),variant:"text",color:"error",onClick:m(t)})]},"".concat(e,"_").concat(t))))}),Et("div",{children:o&&Et(qm,{onOpenModal:l,onChange:h})})]}),o&&Et("div",{children:Et(zl,{jsonEditor:!0,traces:e,onDeleteClick:n=>{const r=e.filter((e=>e.idValue!==n.idValue));t([...r])}})}),!o&&Et("div",{className:"vm-trace-page-preview",children:[Et("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain tracing information in JSON format.","\n","In order to use tracing please refer to the doc:\xa0",Et("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/#query-tracing",target:"_blank",rel:"help noreferrer",children:"https://docs.victoriametrics.com/#query-tracing"}),"\n","Tracing graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Et(qm,{onOpenModal:l,onChange:h})]}),i&&Et(ua,{title:"Paste JSON",onClose:s,children:Et(Dl,{editable:!0,displayTitle:!0,defaultTile:"JSON ".concat(e.length+1),onClose:s,onUpload:u})}),f&&Et("div",{className:"vm-trace-page__dropzone"})]})},Wm=e=>{const{serverUrl:t}=At(),{period:n}=pn(),[a,o]=(0,r.useState)([]),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)(),u=(0,r.useMemo)((()=>((e,t,n)=>{const r="{job=".concat(JSON.stringify(n),"}");return"".concat(e,"/api/v1/label/instance/values?match[]=").concat(encodeURIComponent(r),"&start=").concat(t.start,"&end=").concat(t.end)})(t,n,e)),[t,n,e]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{l(!0);try{const e=await fetch(u),t=await e.json(),n=t.data||[];o(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?c(void 0):c("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Ap){Ap instanceof Error&&c("".concat(Ap.name,": ").concat(Ap.message))}l(!1)})().catch(console.error)}),[u]),{instances:a,isLoading:i,error:s}},Km=(e,t)=>{const{serverUrl:n}=At(),{period:a}=pn(),[o,i]=(0,r.useState)([]),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>((e,t,n,r)=>{const a=Object.entries({job:n,instance:r}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))})).join(","),o="{".concat(a,"}");return"".concat(e,"/api/v1/label/__name__/values?match[]=").concat(encodeURIComponent(o),"&start=").concat(t.start,"&end=").concat(t.end)})(n,a,e,t)),[n,a,e,t]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{s(!0);try{const e=await fetch(d),t=await e.json(),n=t.data||[];i(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Ap){Ap instanceof Error&&u("".concat(Ap.name,": ").concat(Ap.message))}s(!1)})().catch(console.error)}),[d]),{names:o,isLoading:l,error:c}},Qm=e=>{let{name:t,job:n,instance:a,rateEnabled:o,isBucket:i,height:l}=e;const{isMobile:s}=Ur(),{customStep:c,yaxis:u}=jr(),{period:d}=pn(),h=Hr(),m=fn(),p=Qt(d.end-d.start),f=Kt(c),v=Xt(10*f*1e3),[g,y]=(0,r.useState)(!1),[_,b]=(0,r.useState)(!1),w=g&&c===p?v:c,k=(0,r.useMemo)((()=>{const e=Object.entries({job:n,instance:a}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))}));e.push("__name__=".concat(JSON.stringify(t))),"node_cpu_seconds_total"==t&&e.push('mode!="idle"');const r="{".concat(e.join(","),"}");if(i)return"sum(rate(".concat(r,")) by (vmrange, le)");const l=o?"rollup_rate(".concat(r,")"):"rollup(".concat(r,")");return"\nwith (q = ".concat(l,') (\n alias(min(label_match(q, "rollup", "min")), "min"),\n alias(max(label_match(q, "rollup", "max")), "max"),\n alias(avg(label_match(q, "rollup", "avg")), "avg"),\n)')}),[t,n,a,o,i]),{isLoading:x,graphData:S,error:C,queryErrors:E,warning:N,isHistogram:A}=Nl({predefinedQuery:[k],visible:!0,customStep:w,showAllSeries:_});return(0,r.useEffect)((()=>{y(A)}),[A]),Et("div",{className:wr()({"vm-explore-metrics-graph":!0,"vm-explore-metrics-graph_mobile":s}),children:[x&&Et(yl,{}),C&&Et(qr,{variant:"error",children:C}),E[0]&&Et(qr,{variant:"error",children:E[0]}),N&&Et(jl,{warning:N,query:[k],onChange:b}),S&&d&&Et(Dh,{data:S,period:d,customStep:w,query:[k],yaxis:u,setYaxisLimits:e=>{h({type:"SET_YAXIS_LIMITS",payload:e})},setPeriod:e=>{let{from:t,to:n}=e;m({type:"SET_PERIOD",payload:{from:t,to:n}})},showLegend:!1,height:l,isHistogram:A})]})},Zm=e=>{let{name:t,index:n,length:r,isBucket:a,rateEnabled:o,onChangeRate:i,onRemoveItem:l,onChangeOrder:s}=e;const{isMobile:c}=Ur(),{value:u,setTrue:d,setFalse:h}=na(!1),m=()=>{l(t)},p=()=>{s(t,n,n+1)},f=()=>{s(t,n,n-1)};return Et("div",c?{className:"vm-explore-metrics-item-header vm-explore-metrics-item-header_mobile",children:[Et("div",{className:"vm-explore-metrics-item-header__name",children:t}),Et(ea,{variant:"text",size:"small",startIcon:Et(cr,{}),onClick:d,ariaLabel:"open panel settings"}),u&&Et(ua,{title:t,onClose:h,children:Et("div",{className:"vm-explore-metrics-item-header-modal",children:[Et("div",{className:"vm-explore-metrics-item-header-modal-order",children:[Et(ea,{startIcon:Et(Gn,{}),variant:"outlined",onClick:f,disabled:0===n,ariaLabel:"move graph up"}),Et("p",{children:["position:",Et("span",{className:"vm-explore-metrics-item-header-modal-order__index",children:["#",n+1]})]}),Et(ea,{endIcon:Et(Zn,{}),variant:"outlined",onClick:p,disabled:n===r-1,ariaLabel:"move graph down"})]}),!a&&Et("div",{className:"vm-explore-metrics-item-header-modal__rate",children:[Et(sl,{label:Et("span",{children:["enable ",Et("code",{children:"rate()"})]}),value:o,onChange:i,fullWidth:!0}),Et("p",{children:"calculates the average per-second speed of metrics change"})]}),Et(ea,{startIcon:Et(Ln,{}),color:"error",variant:"outlined",onClick:m,fullWidth:!0,children:"Remove graph"})]})})]}:{className:"vm-explore-metrics-item-header",children:[Et("div",{className:"vm-explore-metrics-item-header-order",children:[Et(da,{title:"move graph up",children:Et(ea,{className:"vm-explore-metrics-item-header-order__up",startIcon:Et(Fn,{}),variant:"text",color:"gray",size:"small",onClick:f,ariaLabel:"move graph up"})}),Et("div",{className:"vm-explore-metrics-item-header__index",children:["#",n+1]}),Et(da,{title:"move graph down",children:Et(ea,{className:"vm-explore-metrics-item-header-order__down",startIcon:Et(Fn,{}),variant:"text",color:"gray",size:"small",onClick:p,ariaLabel:"move graph down"})})]}),Et("div",{className:"vm-explore-metrics-item-header__name",children:t}),!a&&Et("div",{className:"vm-explore-metrics-item-header__rate",children:Et(da,{title:"calculates the average per-second speed of metric's change",children:Et(sl,{label:Et("span",{children:["enable ",Et("code",{children:"rate()"})]}),value:o,onChange:i})})}),Et("div",{className:"vm-explore-metrics-item-header__close",children:Et(da,{title:"close graph",children:Et(ea,{startIcon:Et(Ln,{}),variant:"text",color:"gray",size:"small",onClick:m,ariaLabel:"close graph"})})})]})},Gm=e=>{let{name:t,job:n,instance:a,index:o,length:i,size:l,onRemoveItem:s,onChangeOrder:c}=e;const u=(0,r.useMemo)((()=>/_sum?|_total?|_count?/.test(t)),[t]),d=(0,r.useMemo)((()=>/_bucket?/.test(t)),[t]),[h,m]=(0,r.useState)(u),p=Cr(),f=(0,r.useMemo)(l.height,[l,p]);return(0,r.useEffect)((()=>{m(u)}),[n]),Et("div",{className:"vm-explore-metrics-item vm-block vm-block_empty-padding",children:[Et(Zm,{name:t,index:o,length:i,isBucket:d,rateEnabled:h,size:l.id,onChangeRate:m,onRemoveItem:s,onChangeOrder:c}),Et(Qm,{name:t,job:n,instance:a,rateEnabled:h,isBucket:d,height:f},"".concat(t,"_").concat(n,"_").concat(a,"_").concat(h))]})},Jm=e=>{let{values:t,onRemoveItem:n}=e;const{isMobile:r}=Ur();return r?Et("span",{className:"vm-select-input-content__counter",children:["selected ",t.length]}):Et(St.FK,{children:t.map((e=>{return Et("div",{className:"vm-select-input-content__selected",children:[Et("span",{children:e}),Et("div",{onClick:(t=e,e=>{n(t),e.stopPropagation()}),children:Et(Ln,{})})]},e);var t}))})},Xm=e=>{let{value:t,list:n,label:a,placeholder:o,noOptionsText:i,clearable:l=!1,searchable:s=!1,autofocus:c,disabled:u,onChange:d}=e;const{isDarkTheme:h}=At(),{isMobile:m}=Ur(),[p,f]=(0,r.useState)(""),v=(0,r.useRef)(null),[g,y]=(0,r.useState)(null),[_,b]=(0,r.useState)(!1),w=(0,r.useRef)(null),k=Array.isArray(t),x=Array.isArray(t)?t:void 0,S=m&&k&&!(null===x||void 0===x||!x.length),C=(0,r.useMemo)((()=>_?p:Array.isArray(t)?"":t),[t,p,_,k]),E=(0,r.useMemo)((()=>_?p||"(.+)":""),[p,_]),N=()=>{w.current&&w.current.blur()},A=()=>{b(!1),N()},M=e=>{f(""),d(e),k||A(),k&&w.current&&w.current.focus()};return(0,r.useEffect)((()=>{f(""),_&&w.current&&w.current.focus(),_||N()}),[_,w]),(0,r.useEffect)((()=>{c&&w.current&&!m&&w.current.focus()}),[c,w]),Sr("keyup",(e=>{w.current!==e.target&&b(!1)})),Xr(v,A,g),Et("div",{className:wr()({"vm-select":!0,"vm-select_dark":h,"vm-select_disabled":u}),children:[Et("div",{className:"vm-select-input",onClick:e=>{e.target instanceof HTMLInputElement||u||b((e=>!e))},ref:v,children:[Et("div",{className:"vm-select-input-content",children:[!(null===x||void 0===x||!x.length)&&Et(Jm,{values:x,onRemoveItem:M}),!S&&Et("input",{value:C,type:"text",placeholder:o,onInput:e=>{f(e.target.value)},onFocus:()=>{u||b(!0)},onBlur:()=>{n.includes(p)&&d(p)},ref:w,readOnly:m||!s})]}),a&&Et("span",{className:"vm-text-field__label",children:a}),l&&t&&Et("div",{className:"vm-select-input__icon",onClick:(e=>t=>{M(e),t.stopPropagation()})(""),children:Et(Ln,{})}),Et("div",{className:wr()({"vm-select-input__icon":!0,"vm-select-input__icon_open":_}),children:Et(jn,{})})]}),Et(Mo,{label:a,value:E,options:n.map((e=>({value:e}))),anchor:v,selected:x,minLength:1,fullWidth:!0,noOptionsText:i,onSelect:M,onOpenAutocomplete:b,onChangeWrapperRef:y})]})},ep=lt.map((e=>e.id)),tp=e=>{let{jobs:t,instances:n,names:a,job:o,instance:i,size:l,selectedMetrics:s,onChangeJob:c,onChangeInstance:u,onToggleMetric:d,onChangeSize:h}=e;const m=(0,r.useMemo)((()=>o?"":"No instances. Please select job"),[o]),p=(0,r.useMemo)((()=>o?"":"No metric names. Please select job"),[o]),{isMobile:f}=Ur(),{value:v,toggle:g,setFalse:y}=na("false"!==Xe("EXPLORE_METRICS_TIPS"));return(0,r.useEffect)((()=>{Je("EXPLORE_METRICS_TIPS","".concat(v))}),[v]),Et(St.FK,{children:[Et("div",{className:wr()({"vm-explore-metrics-header":!0,"vm-explore-metrics-header_mobile":f,"vm-block":!0,"vm-block_mobile":f}),children:[Et("div",{className:"vm-explore-metrics-header__job",children:Et(Xm,{value:o,list:t,label:"Job",placeholder:"Please select job",onChange:c,autofocus:!o&&!!t.length&&!f,searchable:!0})}),Et("div",{className:"vm-explore-metrics-header__instance",children:Et(Xm,{value:i,list:n,label:"Instance",placeholder:"Please select instance",onChange:u,noOptionsText:m,clearable:!0,searchable:!0})}),Et("div",{className:"vm-explore-metrics-header__size",children:[Et(Xm,{label:"Size graphs",value:l,list:ep,onChange:h}),Et(da,{title:"".concat(v?"Hide":"Show"," tip"),children:Et(ea,{variant:"text",color:v?"warning":"gray",startIcon:Et(dr,{}),onClick:g,ariaLabel:"visibility tips"})})]}),Et("div",{className:"vm-explore-metrics-header-metrics",children:Et(Xm,{label:"Metrics",value:s,list:a,placeholder:"Search metric name",onChange:d,noOptionsText:p,clearable:!0,searchable:!0})})]}),v&&Et(qr,{variant:"warning",children:Et("div",{className:"vm-explore-metrics-header-description",children:[Et("p",{children:["Please note: this page is solely designed for exploring Prometheus metrics. Prometheus metrics always contain ",Et("code",{children:"job"})," and ",Et("code",{children:"instance"})," labels (see ",Et("a",{className:"vm-link vm-link_colored",href:"https://prometheus.io/docs/concepts/jobs_instances/",children:"these docs"}),"), and this page relies on them as filters. ",Et("br",{}),"Please use this page for Prometheus metrics only, in accordance with their naming conventions."]}),Et(ea,{variant:"text",size:"small",startIcon:Et(Ln,{}),onClick:y,ariaLabel:"close tips"})]})})]})},np=ct("job",""),rp=ct("instance",""),ap=ct("metrics",""),op=ct("size",""),ip=lt.find((e=>op?e.id===op:e.isDefault))||lt[0],lp=()=>{const[e,t]=(0,r.useState)(np),[n,a]=(0,r.useState)(rp),[o,i]=(0,r.useState)(ap?ap.split("&"):[]),[l,s]=(0,r.useState)(ip);(e=>{let{job:t,instance:n,metrics:a,size:o}=e;const{duration:i,relativeTime:l,period:{date:s}}=pn(),{customStep:c}=jr(),{setSearchParamsFromKeys:u}=ro(),d=()=>{const e=rm({"g0.range_input":i,"g0.end_input":s,"g0.step_input":c,"g0.relative_time":l,size:o,job:t,instance:n,metrics:a});u(e)};(0,r.useEffect)(d,[i,l,s,c,t,n,a,o]),(0,r.useEffect)(d,[])})({job:e,instance:n,metrics:o.join("&"),size:l.id});const{jobs:c,isLoading:u,error:d}=(()=>{const{serverUrl:e}=At(),{period:t}=pn(),[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)(!1),[l,s]=(0,r.useState)(),c=(0,r.useMemo)((()=>((e,t)=>"".concat(e,"/api/v1/label/job/values?start=").concat(t.start,"&end=").concat(t.end))(e,t)),[e,t]);return(0,r.useEffect)((()=>{(async()=>{i(!0);try{const e=await fetch(c),t=await e.json(),n=t.data||[];a(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?s(void 0):s("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Ap){Ap instanceof Error&&s("".concat(Ap.name,": ").concat(Ap.message))}i(!1)})().catch(console.error)}),[c]),{jobs:n,isLoading:o,error:l}})(),{instances:h,isLoading:m,error:p}=Wm(e),{names:f,isLoading:v,error:g}=Km(e,n),y=(0,r.useMemo)((()=>u||m||v),[u,m,v]),_=(0,r.useMemo)((()=>d||p||g),[d,p,g]),b=e=>{i(e?t=>t.includes(e)?t.filter((t=>t!==e)):[...t,e]:[])},w=(e,t,n)=>{const r=n>o.length-1;n<0||r||i((e=>{const r=[...e],[a]=r.splice(t,1);return r.splice(n,0,a),r}))};return(0,r.useEffect)((()=>{n&&h.length&&!h.includes(n)&&a("")}),[h,n]),Et("div",{className:"vm-explore-metrics",children:[Et(tp,{jobs:c,instances:h,names:f,job:e,size:l.id,instance:n,selectedMetrics:o,onChangeJob:t,onChangeSize:e=>{const t=lt.find((t=>t.id===e));t&&s(t)},onChangeInstance:a,onToggleMetric:b}),y&&Et(yl,{}),_&&Et(qr,{variant:"error",children:_}),!e&&Et(qr,{variant:"info",children:"Please select job to see list of metric names."}),e&&!o.length&&Et(qr,{variant:"info",children:"Please select metric names to see the graphs."}),Et("div",{className:"vm-explore-metrics-body",children:o.map(((t,r)=>Et(Gm,{name:t,job:e,instance:n,index:r,length:o.length,size:l,onRemoveItem:b,onChangeOrder:w},t)))})]})},sp=()=>{const t=hl();return Et("div",{className:"vm-preview-icons",children:Object.entries(e).map((e=>{let[n,r]=e;return Et("div",{className:"vm-preview-icons-item",onClick:(a=n,async()=>{await t("<".concat(a,"/>"),"<".concat(a,"/> has been copied"))}),children:[Et("div",{className:"vm-preview-icons-item__svg",children:r()}),Et("div",{className:"vm-preview-icons-item__name",children:"<".concat(n,"/>")})]},n);var a}))})};var cp=function(e){return e.copy="Copy",e.copied="Copied",e}(cp||{});const up=e=>{let{code:t}=e;const[n,a]=(0,r.useState)(cp.copy);return(0,r.useEffect)((()=>{let e=null;return n===cp.copied&&(e=setTimeout((()=>a(cp.copy)),1e3)),()=>{e&&clearTimeout(e)}}),[n]),Et("code",{className:"vm-code-example",children:[t,Et("div",{className:"vm-code-example__copy",children:Et(da,{title:n,children:Et(ea,{size:"small",variant:"text",onClick:()=>{navigator.clipboard.writeText(t),a(cp.copied)},startIcon:Et(nr,{}),ariaLabel:"close"})})})]})},dp=()=>Et("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/MetricsQL.html",target:"_blank",rel:"help noreferrer",children:"MetricsQL"}),hp=()=>Et("a",{className:"vm-link vm-link_colored",href:"https://grafana.com/grafana/dashboards/1860-node-exporter-full/",target:"_blank",rel:"help noreferrer",children:"Node Exporter Full"}),mp=()=>Et("section",{className:"vm-with-template-tutorial",children:[Et("h2",{className:"vm-with-template-tutorial__title",children:["Tutorial for WITH expressions in ",Et(dp,{})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:["Let's look at the following real query from ",Et(hp,{})," dashboard:"]}),Et(up,{code:'(\n (\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n -\n node_memory_MemFree_bytes{instance=~"$node:$port", job=~"$job"}\n )\n /\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n) * 100'}),Et("p",{className:"vm-with-template-tutorial-section__text",children:"It is clear the query calculates the percentage of used memory for the given $node, $port and $job. Isn't it? :)"})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:"What's wrong with this query? Copy-pasted label filters for distinct timeseries which makes it easy to mistype these filters during modification. Let's simplify the query with WITH expressions:"}),Et(up,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n node_memory_MemTotal_bytes{commonFilters}\n -\n node_memory_MemFree_bytes{commonFilters}\n)\n /\nnode_memory_MemTotal_bytes{commonFilters} * 100'})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:["Now label filters are located in a single place instead of three distinct places. The query mentions node_memory_MemTotal_bytes metric twice and ","{commonFilters}"," three times. WITH expressions may improve this:"]}),Et(up,{code:'WITH (\n my_resource_utilization(free, limit, filters) = (limit{filters} - free{filters}) / limit{filters} * 100\n)\nmy_resource_utilization(\n node_memory_MemFree_bytes,\n node_memory_MemTotal_bytes,\n {instance=~"$node:$port",job=~"$job"},\n)'}),Et("p",{className:"vm-with-template-tutorial-section__text",children:"Now the template function my_resource_utilization() may be used for monitoring arbitrary resources - memory, CPU, network, storage, you name it."})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:["Let's take another nice query from ",Et(hp,{})," dashboard:"]}),Et(up,{code:'(\n (\n (\n count(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',instance=~"$node:$port",job=~"$job"}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n)'}),Et("p",{className:"vm-with-template-tutorial-section__text",children:"Do you understand what does this mess do? Is it manageable? :) WITH expressions are happy to help in a few iterations."})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:"1. Extract common filters used in multiple places into a commonFilters variable:"}),Et(up,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n (\n (\n count(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n)'})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:'2. Extract "count(count(...) by (cpu))" into cpuCount variable:'}),Et(up,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu))\n)\n(\n (\n cpuCount\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n) / cpuCount'})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:"3. Extract rate(...) part into cpuIdle variable, since it is clear now that this part calculates the number of idle CPUs:"}),Et(up,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu)),\n cpuIdle = sum(rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:["4. Put node_cpu_seconds_total","{commonFilters}"," into its own varialbe with the name cpuSeconds:"]}),Et(up,{code:'WITH (\n cpuSeconds = node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(cpuSeconds) by (cpu)),\n cpuIdle = sum(rate(cpuSeconds{mode=\'idle\'}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'}),Et("p",{className:"vm-with-template-tutorial-section__text",children:"Now the query became more clear comparing to the initial query."})]}),Et("div",{className:"vm-with-template-tutorial-section",children:[Et("p",{className:"vm-with-template-tutorial-section__text",children:"WITH expressions may be nested and may be put anywhere. Try expanding the following query:"}),Et(up,{code:"WITH (\n f(a, b) = WITH (\n f1(x) = b-x,\n f2(x) = x+x\n ) f1(a)*f2(b)\n) f(foo, with(x=bar) x)"})]})]}),pp=()=>{const{serverUrl:e}=At(),[t,n]=je(),[a,o]=(0,r.useState)(""),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)();return{data:a,error:s,loading:i,expand:async r=>{t.set("expr",r),n(t);const a=((e,t)=>"".concat(e,"/expand-with-exprs?query=").concat(encodeURIComponent(t),"&format=json"))(e,r);l(!0);try{const e=await fetch(a),t=await e.json();o((null===t||void 0===t?void 0:t.expr)||""),c(String(t.error||""))}catch(Ap){Ap instanceof Error&&"AbortError"!==Ap.name&&c("".concat(Ap.name,": ").concat(Ap.message))}l(!1)}}},fp=()=>{const[e]=je(),{data:t,loading:n,error:a,expand:o}=pp(),[i,l]=(0,r.useState)(e.get("expr")||""),s=()=>{o(i)};return(0,r.useEffect)((()=>{i&&o(i)}),[]),Et("section",{className:"vm-with-template",children:[n&&Et(yl,{}),Et("div",{className:"vm-with-template-body vm-block",children:[Et("div",{className:"vm-with-template-body__expr",children:Et(ja,{type:"textarea",label:"MetricsQL query with optional WITH expressions",value:i,error:a,autofocus:!0,onEnter:s,onChange:e=>{l(e)}})}),Et("div",{className:"vm-with-template-body__result",children:Et(ja,{type:"textarea",label:"MetricsQL query after expanding WITH expressions and applying other optimizations",value:t,disabled:!0})}),Et("div",{className:"vm-with-template-body-top",children:Et(ea,{variant:"contained",onClick:s,startIcon:Et(Bn,{}),children:"Expand"})})]}),Et("div",{className:"vm-block",children:Et(mp,{})})]})},vp=()=>{const{serverUrl:e}=At(),[t,n]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1),[i,l]=(0,r.useState)();return{data:t,error:i,loading:a,fetchData:async(t,r)=>{const a=((e,t,n)=>{const r=["format=json","relabel_configs=".concat(encodeURIComponent(t)),"metric=".concat(encodeURIComponent(n))];return"".concat(e,"/metric-relabel-debug?").concat(r.join("&"))})(e,t,r);o(!0);try{const e=await fetch(a),t=await e.json();n(t.error?null:t),l(String(t.error||""))}catch(Ap){Ap instanceof Error&&"AbortError"!==Ap.name&&l("".concat(Ap.name,": ").concat(Ap.message))}o(!1)}}},gp={config:'- if: \'{bar_label=~"b.*"}\'\n source_labels: [foo_label, bar_label]\n separator: "_"\n target_label: foobar\n- action: labeldrop\n regex: "foo_.*"\n- target_label: job\n replacement: "my-application-2"',labels:'{__name__="my_metric", bar_label="bar", foo_label="foo", job="my-application", instance="192.168.0.1"}'},yp=()=>{const[e,t]=je(),{data:n,loading:a,error:o,fetchData:i}=vp(),[l,s]=vm("","config"),[c,u]=vm("","labels"),d=(0,r.useCallback)((()=>{i(l,c),e.set("config",l),e.set("labels",c),t(e)}),[l,c]);return(0,r.useEffect)((()=>{const t=e.get("config")||"",n=e.get("labels")||"";(n||t)&&(i(t,n),s(t),u(n))}),[]),Et("section",{className:"vm-relabeling",children:[a&&Et(yl,{}),Et("div",{className:"vm-relabeling-header vm-block",children:[Et("div",{className:"vm-relabeling-header-configs",children:Et(ja,{type:"textarea",label:"Relabel configs",value:l,autofocus:!0,onChange:e=>{s(e||"")},onEnter:d})}),Et("div",{className:"vm-relabeling-header__labels",children:Et(ja,{type:"textarea",label:"Labels",value:c,onChange:e=>{u(e||"")},onEnter:d})}),Et("div",{className:"vm-relabeling-header-bottom",children:[Et("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/relabeling.html",rel:"help noreferrer",children:[Et(Pn,{}),"Relabeling cookbook"]}),Et("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/vmagent.html#relabeling",rel:"help noreferrer",children:[Et(or,{}),"Documentation"]}),Et(ea,{variant:"text",onClick:()=>{const{config:n,labels:r}=gp;s(n),u(r),i(n,r),e.set("config",n),e.set("labels",r),t(e)},children:"Try example"}),Et(ea,{variant:"contained",onClick:d,startIcon:Et(Bn,{}),children:"Submit"})]})]}),o&&Et(qr,{variant:"error",children:o}),n&&Et("div",{className:"vm-relabeling-steps vm-block",children:[n.originalLabels&&Et("div",{className:"vm-relabeling-steps-item",children:Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Original labels:"}),Et("code",{dangerouslySetInnerHTML:{__html:n.originalLabels}})]})}),n.steps.map(((e,t)=>Et("div",{className:"vm-relabeling-steps-item",children:[Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Step:"}),t+1]}),Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Relabeling Rule:"}),Et("code",{children:Et("pre",{children:e.rule})})]}),Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Input Labels:"}),Et("code",{children:Et("pre",{dangerouslySetInnerHTML:{__html:e.inLabels}})})]}),Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Output labels:"}),Et("code",{children:Et("pre",{dangerouslySetInnerHTML:{__html:e.outLabels}})})]})]},t))),n.resultingLabels&&Et("div",{className:"vm-relabeling-steps-item",children:Et("div",{className:"vm-relabeling-steps-item__row",children:[Et("span",{children:"Resulting labels:"}),Et("code",{dangerouslySetInnerHTML:{__html:n.resultingLabels}})]})})]})]})},_p=e=>{let{rows:t,columns:n,defaultOrderBy:a,copyToClipboard:o,paginationOffset:i}=e;const[l,s]=(0,r.useState)(a),[c,u]=(0,r.useState)("desc"),[d,h]=(0,r.useState)(null),m=(0,r.useMemo)((()=>{const{startIndex:e,endIndex:n}=i;return km(t,wm(c,l)).slice(e,n)}),[t,l,c,i]),p=(e,t)=>async()=>{if(d!==t)try{await navigator.clipboard.writeText(String(e)),h(t)}catch(Ap){console.error(Ap)}};return(0,r.useEffect)((()=>{if(null===d)return;const e=setTimeout((()=>h(null)),2e3);return()=>clearTimeout(e)}),[d]),Et("table",{className:"vm-table",children:[Et("thead",{className:"vm-table-header",children:Et("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>{return Et("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:(t=e.key,()=>{u((e=>"asc"===e&&l===t?"desc":"asc")),s(t)}),children:Et("div",{className:"vm-table-cell__content",children:[Et("div",{children:String(e.title||e.key)}),Et("div",{className:wr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":l===e.key,"vm-table__sort-icon_desc":"desc"===c&&l===e.key}),children:Et(jn,{})})]})},String(e.key));var t})),o&&Et("th",{className:"vm-table-cell vm-table-cell_header"})]})}),Et("tbody",{className:"vm-table-body",children:m.map(((e,t)=>Et("tr",{className:"vm-table__row",children:[n.map((t=>Et("td",{className:wr()({"vm-table-cell":!0,["".concat(t.className)]:t.className}),children:e[t.key]||"-"},String(t.key)))),o&&Et("td",{className:"vm-table-cell vm-table-cell_right",children:e[o]&&Et("div",{className:"vm-table-cell__content",children:Et(da,{title:d===t?"Copied":"Copy row",children:Et(ea,{variant:"text",color:d===t?"success":"gray",size:"small",startIcon:Et(d===t?Jn:nr,{}),onClick:p(e[o],t),ariaLabel:"copy row"})})})})]},t)))})]})},bp=()=>{const{isMobile:e}=Ur(),{timezone:t}=pn(),{data:n,lastUpdated:a,isLoading:i,error:l,fetchData:s}=(()=>{const{serverUrl:e}=At(),[t,n]=(0,r.useState)([]),[a,i]=(0,r.useState)(o()().format(Pt)),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>"".concat(e,"/api/v1/status/active_queries")),[e]),h=async()=>{s(!0);try{const e=await fetch(d),t=await e.json();n(t.data),i(o()().format("HH:mm:ss:SSS")),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Ap){Ap instanceof Error&&u("".concat(Ap.name,": ").concat(Ap.message))}s(!1)};return(0,r.useEffect)((()=>{h().catch(console.error)}),[d]),{data:t,lastUpdated:a,isLoading:l,error:c,fetchData:h}})(),c=(0,r.useMemo)((()=>n.map((e=>{const t=o()(e.start).tz().format(Ot),n=o()(e.end).tz().format(Ot);return{duration:e.duration,remote_addr:e.remote_addr,query:e.query,args:"".concat(t," to ").concat(n,", step=").concat(Yt(e.step)),data:JSON.stringify(e,null,2)}}))),[n,t]),u=(0,r.useMemo)((()=>{if(null===c||void 0===c||!c.length)return[];const e=Object.keys(c[0]),t={remote_addr:"client address"},n=["data"];return e.filter((e=>!n.includes(e))).map((e=>({key:e,title:t[e]||e})))}),[c]);return Et("div",{className:"vm-active-queries",children:[i&&Et(yl,{}),Et("div",{className:"vm-active-queries-header",children:[!c.length&&!l&&Et(qr,{variant:"info",children:"There are currently no active queries running"}),l&&Et(qr,{variant:"error",children:l}),Et("div",{className:"vm-active-queries-header-controls",children:[Et(ea,{variant:"contained",onClick:async()=>{s().catch(console.error)},startIcon:Et(zn,{}),children:"Update"}),Et("div",{className:"vm-active-queries-header__update-msg",children:["Last updated: ",a]})]})]}),!!c.length&&Et("div",{className:wr()({"vm-block":!0,"vm-block_mobile":e}),children:Et(_p,{rows:c,columns:u,defaultOrderBy:"duration",copyToClipboard:"data",paginationOffset:{startIndex:0,endIndex:1/0}})})]})},wp=e=>{let{onClose:t,onUpload:n}=e;const{isMobile:a}=Ur(),[o,i]=(0,r.useState)(""),[l,s]=(0,r.useState)(""),c=(0,r.useMemo)((()=>{try{return JSON.parse(o),""}catch(Ap){return Ap instanceof Error?Ap.message:"Unknown error"}}),[o]),u=()=>{s(c),c||(n(o),t())};return Et("div",{className:wr()({"vm-json-form vm-json-form_one-field":!0,"vm-json-form_mobile vm-json-form_one-field_mobile":a}),children:[Et(ja,{value:o,label:"JSON",type:"textarea",error:l,autofocus:!0,onChange:e=>{s(""),i(e)},onEnter:u}),Et("div",{className:"vm-json-form-footer",children:Et("div",{className:"vm-json-form-footer__controls vm-json-form-footer__controls_right",children:[Et(ea,{variant:"outlined",color:"error",onClick:t,children:"Cancel"}),Et(ea,{variant:"contained",onClick:u,children:"apply"})]})})]})},kp=e=>{let{data:t,period:n}=e;const{isMobile:a}=Ur(),{tableCompact:o}=Ir(),i=Rr(),[l,s]=(0,r.useState)([]),[c,u]=(0,r.useState)(),[d,h]=(0,r.useState)(),[m,p]=(0,r.useState)(!1),[f,v]=(0,r.useState)([]),[g,y]=(0,r.useState)(),_=(0,r.useMemo)((()=>Uh(d||[]).map((e=>e.key))),[d]),b=(0,r.useMemo)((()=>{const e=t.some((e=>"matrix"===e.data.resultType));return t.some((e=>"vector"===e.data.resultType))&&e?Nr:e?Nr.filter((e=>"chart"===e.value)):Nr.filter((e=>"chart"!==e.value))}),[t]),[w,k]=(0,r.useState)(b[0].value),{yaxis:x,spanGaps:S}=jr(),C=Hr(),E=e=>{C({type:"SET_YAXIS_LIMITS",payload:e})};return(0,r.useEffect)((()=>{const e="chart"===w?"matrix":"vector",n=t.filter((t=>t.data.resultType===e&&t.trace)).map((e=>{var t,n;return e.trace?new kl(e.trace,(null===e||void 0===e||null===(t=e.vmui)||void 0===t||null===(n=t.params)||void 0===n?void 0:n.query)||"Query"):null}));s(n.filter(Boolean))}),[t,w]),(0,r.useEffect)((()=>{const e=[],n=[],r=[];t.forEach(((t,a)=>{const o=t.data.result.map((e=>{var n,r,o;return{...e,group:Number(null!==(n=null===(r=t.vmui)||void 0===r||null===(o=r.params)||void 0===o?void 0:o.id)&&void 0!==n?n:a)+1}}));var i,l;"matrix"===t.data.resultType?(n.push(...o),e.push((null===(i=t.vmui)||void 0===i||null===(l=i.params)||void 0===l?void 0:l.query)||"Query")):r.push(...o)})),v(e),u(n),h(r)}),[t]),(0,r.useEffect)((()=>{p(!!c&&Cl(c))}),[c]),Et("div",{className:wr()({"vm-query-analyzer-view":!0,"vm-query-analyzer-view_mobile":a}),children:[!!l.length&&Et(zl,{traces:l,onDeleteClick:e=>{s((t=>t.filter((t=>t.idValue!==e.idValue))))}}),Et("div",{className:wr()({"vm-block":!0,"vm-block_mobile":a}),children:[Et("div",{className:"vm-custom-panel-body-header",children:[Et("div",{className:"vm-custom-panel-body-header__tabs",children:Et(Er,{activeItem:w,items:b,onChange:e=>{k(e)}})}),Et("div",{className:"vm-custom-panel-body-header__graph-controls",children:["chart"===w&&Et(va,{}),"chart"===w&&Et(Hh,{yaxis:x,setYaxisLimits:E,toggleEnableLimits:()=>{C({type:"TOGGLE_ENABLE_YAXIS_LIMITS"})},spanGaps:{value:S,onChange:e=>{C({type:"SET_SPAN_GAPS",payload:e})}}}),"table"===w&&Et(Kh,{columns:_,defaultColumns:g,onChangeColumns:y,tableCompact:o,toggleTableCompact:()=>{i({type:"TOGGLE_TABLE_COMPACT"})}})]})]}),c&&n&&"chart"===w&&Et(Dh,{data:c,period:n,customStep:n.step||"1s",query:f,yaxis:x,setYaxisLimits:E,setPeriod:()=>null,height:a?.5*window.innerHeight:500,isHistogram:m,spanGaps:S}),d&&"code"===w&&Et($h,{data:d}),d&&"table"===w&&Et(qh,{data:d,displayColumns:g})]})]})},xp=e=>{var t,n;let{data:a,period:i}=e;const l=(0,r.useMemo)((()=>a.filter((e=>e.stats&&"matrix"===e.data.resultType))),[a]),s=(0,r.useMemo)((()=>{var e,t;return null===(e=a.find((e=>{var t;return null===e||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment})))||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment}),[a]),c=(0,r.useMemo)((()=>{if(!i)return"";const e=o()(1e3*i.start).tz().format(Ot),t=o()(1e3*i.end).tz().format(Ot);return"".concat(e," - ").concat(t)}),[i]),{value:u,setTrue:d,setFalse:h}=na(!1);return Et(St.FK,{children:[Et("div",{className:"vm-query-analyzer-info-header",children:[Et(ea,{startIcon:Et(Pn,{}),variant:"outlined",color:"warning",onClick:d,children:"Show report info"}),i&&Et(St.FK,{children:[Et("div",{className:"vm-query-analyzer-info-header__period",children:[Et(ar,{})," step: ",i.step]}),Et("div",{className:"vm-query-analyzer-info-header__period",children:[Et(Hn,{})," ",c]})]})]}),u&&Et(ua,{title:"Report info",onClose:h,children:Et("div",{className:"vm-query-analyzer-info",children:[s&&Et("div",{className:"vm-query-analyzer-info-item vm-query-analyzer-info-item_comment",children:[Et("div",{className:"vm-query-analyzer-info-item__title",children:"Comment:"}),Et("div",{className:"vm-query-analyzer-info-item__text",children:s})]}),l.map(((e,t)=>{var n;return Et("div",{className:"vm-query-analyzer-info-item",children:[Et("div",{className:"vm-query-analyzer-info-item__title",children:l.length>1?"Query ".concat(t+1,":"):"Stats:"}),Et("div",{className:"vm-query-analyzer-info-item__text",children:[Object.entries(e.stats||{}).map((e=>{let[t,n]=e;return Et("div",{children:[t,": ",null!==n&&void 0!==n?n:"-"]},t)})),"isPartial: ",String(null!==(n=e.isPartial)&&void 0!==n?n:"-")]})]},t)})),Et("div",{className:"vm-query-analyzer-info-type",children:null!==(t=l[0])&&void 0!==t&&null!==(n=t.vmui)&&void 0!==n&&n.params?"The report was created using vmui":"The report was created manually"})]})})]})},Sp=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(""),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=na(!1),c=(0,r.useMemo)((()=>{var t,n;if(!e)return;const r=null===(t=e[0])||void 0===t||null===(n=t.vmui)||void 0===n?void 0:n.params,a={start:+((null===r||void 0===r?void 0:r.start)||0),end:+((null===r||void 0===r?void 0:r.end)||0),step:null===r||void 0===r?void 0:r.step,date:""};if(!r){const t=e.filter((e=>"matrix"===e.data.resultType)).map((e=>e.data.result)).flat().map((e=>{var t;return e.values?null===(t=e.values)||void 0===t?void 0:t.map((e=>e[0])):[0]})).flat(),n=Array.from(new Set(t.filter(Boolean))).sort(((e,t)=>e-t));a.start=n[0],a.end=n[n.length-1],a.step=qt((e=>{const t=e.slice(1).map(((t,n)=>t-e[n])),n={};t.forEach((e=>{const t=e.toString();n[t]=(n[t]||0)+1}));let r=0,a=0;for(const o in n)n[o]>a&&(a=n[o],r=Number(o));return r})(n))}return a.date=Gt(en(a.end)),a}),[e]),u=e=>{try{const n=JSON.parse(e),r=Array.isArray(n)?n:[n];(e=>e.every((e=>{if("object"===typeof e&&null!==e){const t=e.data;if("object"===typeof t&&null!==t){const e=t.result,n=t.resultType;return Array.isArray(e)&&"string"===typeof n}}return!1})))(r)?t(r):a("Invalid structure - JSON does not match the expected format")}catch(Ap){Ap instanceof Error&&a("".concat(Ap.name,": ").concat(Ap.message))}},d=e=>{e.map((e=>{const t=new FileReader;t.onload=e=>{var t;const n=String(null===(t=e.target)||void 0===t?void 0:t.result);u(n)},t.readAsText(e)}))},h=e=>{a("");const t=Array.from(e.target.files||[]);d(t),e.target.value=""},{files:m,dragging:p}=Bm();return(0,r.useEffect)((()=>{d(m)}),[m]),Et("div",{className:"vm-trace-page",children:[o&&Et("div",{className:"vm-trace-page-header",children:[Et("div",{className:"vm-trace-page-header-errors",children:Et(xp,{data:e,period:c})}),Et("div",{children:Et(qm,{onOpenModal:l,onChange:h})})]}),n&&Et("div",{className:"vm-trace-page-header-errors-item vm-trace-page-header-errors-item_margin-bottom",children:[Et(qr,{variant:"error",children:n}),Et(ea,{className:"vm-trace-page-header-errors-item__close",startIcon:Et(Ln,{}),variant:"text",color:"error",onClick:()=>{a("")}})]}),o&&Et(kp,{data:e,period:c}),!o&&Et("div",{className:"vm-trace-page-preview",children:[Et("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain query information in JSON format.","\n","Graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Et(qm,{onOpenModal:l,onChange:h})]}),i&&Et(ua,{title:"Paste JSON",onClose:s,children:Et(wp,{onClose:s,onUpload:u})}),p&&Et("div",{className:"vm-trace-page__dropzone"})]})},Cp=()=>{const[e,t]=(0,r.useState)(!1);return Et(St.FK,{children:Et(Le,{children:Et(Gr,{children:Et(St.FK,{children:[Et(Um,{onLoaded:t}),e&&Et(ke,{children:Et(be,{path:"/",element:Et(No,{}),children:[Et(be,{path:Ye.home,element:Et(em,{})}),Et(be,{path:Ye.metrics,element:Et(lp,{})}),Et(be,{path:Ye.cardinality,element:Et(Om,{})}),Et(be,{path:Ye.topQueries,element:Et(Fm,{})}),Et(be,{path:Ye.trace,element:Et(Ym,{})}),Et(be,{path:Ye.queryAnalyzer,element:Et(Sp,{})}),Et(be,{path:Ye.dashboards,element:Et(am,{})}),Et(be,{path:Ye.withTemplate,element:Et(fp,{})}),Et(be,{path:Ye.relabel,element:Et(yp,{})}),Et(be,{path:Ye.activeQueries,element:Et(bp,{})}),Et(be,{path:Ye.icons,element:Et(sp,{})})]})})]})})})})},Ep=e=>{e&&n.e(685).then(n.bind(n,685)).then((t=>{let{getCLS:n,getFID:r,getFCP:a,getLCP:o,getTTFB:i}=t;n(e),r(e),a(e),o(e),i(e)}))},Np=document.getElementById("root");Np&&(0,r.render)(Et(Cp,{}),Np),Ep()})()})(); \ No newline at end of file diff --git a/app/vmselect/vmui/static/js/main.ff023df1.js b/app/vmselect/vmui/static/js/main.ff023df1.js new file mode 100644 index 0000000000..4489a62ccf --- /dev/null +++ b/app/vmselect/vmui/static/js/main.ff023df1.js @@ -0,0 +1,2 @@ +/*! For license information please see main.ff023df1.js.LICENSE.txt */ +(()=>{var e={61:(e,t,n)=>{"use strict";var r=n(375),a=n(629),o=a(r("String.prototype.indexOf"));e.exports=function(e,t){var n=r(e,!!t);return"function"===typeof n&&o(e,".prototype.")>-1?a(n):n}},629:(e,t,n)=>{"use strict";var r=n(989),a=n(375),o=n(259),i=n(277),l=a("%Function.prototype.apply%"),s=a("%Function.prototype.call%"),c=a("%Reflect.apply%",!0)||r.call(s,l),u=n(709),d=a("%Math.max%");e.exports=function(e){if("function"!==typeof e)throw new i("a function is required");var t=c(r,s,arguments);return o(t,1+d(0,e.length-(arguments.length-1)),!0)};var h=function(){return c(r,l,arguments)};u?u(e.exports,"apply",{value:h}):e.exports.apply=h},159:function(e){e.exports=function(){"use strict";var e=1e3,t=6e4,n=36e5,r="millisecond",a="second",o="minute",i="hour",l="day",s="week",c="month",u="quarter",d="year",h="date",m="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,v={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},g=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},y={s:g,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),a=n%60;return(t<=0?"+":"-")+g(r,2,"0")+":"+g(a,2,"0")},m:function e(t,n){if(t.date()'+(n?e:Xo(e,!0))+"
\n":""+(n?e:Xo(e,!0))+"
\n"}blockquote(e){return"\n".concat(e,"\n")}html(e,t){return e}heading(e,t,n){return"
".concat(e,"
\n")}table(e,t){return t&&(t="".concat(t,"")),"".concat(e,"
")}br(){return"An error occurred:
"+Xo(n.message+"",!0)+"";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}const el=new class{constructor(){jo(this,Gi),Uo(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),Uo(this,"options",this.setOptions),Uo(this,"parse",Ho(Gi,this,Ji).call(this,Yi.lex,Qi.parse)),Uo(this,"parseInline",Ho(Gi,this,Ji).call(this,Yi.lexInline,Qi.parseInline)),Uo(this,"Parser",Qi),Uo(this,"Renderer",Wi),Uo(this,"TextRenderer",Ki),Uo(this,"Lexer",Yi),Uo(this,"Tokenizer",ci),Uo(this,"Hooks",Zi),this.use(...arguments)}walkTokens(e,t){let n=[];for(const a of e)switch(n=n.concat(t.call(this,a)),a.type){case"table":{const e=a;for(const r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(const r of e.rows)for(const e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=a;n=n.concat(this.walkTokens(e.items,t));break}default:{var r;const e=a;null!==(r=this.defaults.extensions)&&void 0!==r&&null!==(r=r.childTokens)&&void 0!==r&&r[e.type]?this.defaults.extensions.childTokens[e.type].forEach((r=>{const a=e[r].flat(1/0);n=n.concat(this.walkTokens(a,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(){const e=this.defaults.extensions||{renderers:{},childTokens:{}};for(var t=arguments.length,n=new Array(t),r=0;r
\n This table returns a list of metrics with the highest cardinality.\n The cardinality of a metric is the number of time series associated with that metric,\n where each time series is defined as a unique combination of key-value label pairs.\n
\n\n When looking to reduce the number of active series in your data source,\n you can start by inspecting individual metrics with high cardinality\n (i.e. that have lots of active time series associated with them),\n since that single metric contributes a large fraction of the series that make up your total series count.\n
",seriesCountByLabelName:"\n\n This table returns a list of the labels with the highest number of series.\n
\n\n Use this table to identify labels that are storing dimensions with high cardinality\n (many different label values).\n
\n\n It is recommended to choose labels such that they have a finite set of values,\n since every unique combination of key-value label pairs creates a new time series\n and therefore can dramatically increase the number of time series in your system.\n
",seriesCountByFocusLabelValue:"\n\n This table returns a list of unique label values per selected label.\n
\n\n Use this table to identify label values that are storing per each selected series.\n
",labelValueCountByLabelName:"\n\n This table returns a list of labels with the highest number of the unique values.\n
\n ",seriesCountByLabelValuePair:"\n\n This table returns a list of the label values pairs with the highest number of series.\n
\n\n Use this table to identify unique label values pairs. This helps to identify same labels \n is applied to count timeseries in your system, since every unique combination of key-value label pairs \n creates a new time series and therefore can dramatically increase the number of time series in your system\n
"}}get tablesHeaders(){return{seriesCountByMetricName:cm,seriesCountByLabelName:um,seriesCountByFocusLabelValue:dm,seriesCountByLabelValuePair:hm,labelValueCountByLabelName:mm}}totalSeries(e){return"labelValueCountByLabelName"===e?-1:arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.tsdbStatus.totalSeriesPrev:this.tsdbStatus.totalSeries}}const cm=[{id:"name",label:"Metric name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of a metric to the total number of series"},{id:"action",label:""}],um=[{id:"name",label:"Label name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label to the total number of series"},{id:"action",label:""}],dm=[{id:"name",label:"Label value"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total"},{disablePadding:!1,id:"action",label:"",numeric:!1}],hm=[{id:"name",label:"Label=value pair"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label value pair to the total number of series"},{id:"action",label:""}],mm=[{id:"name",label:"Label name"},{id:"value",label:"Number of unique values"},{id:"action",label:""}],pm=()=>{const e=new sm,[t]=He(),n=t.get("match"),a=t.get("focusLabel"),i=+(t.get("topN")||10),l=t.get("date")||o()().tz().format(It),s=$a(l),c=(0,r.useRef)(),{serverUrl:u}=Mt(),[d,h]=(0,r.useState)(!1),[m,p]=(0,r.useState)(),[f,v]=(0,r.useState)(e.defaultTSDBStatus),[g,y]=(0,r.useState)(!1),_=async e=>{const t=await fetch(e);if(t.ok)return await t.json();throw new Error("Request failed with status ".concat(t.status))},b=async t=>{if(!u)return;p(""),h(!0),v(e.defaultTSDBStatus);const r={...t,date:t.date,topN:0,match:"",focusLabel:""},a={...t,date:o()(t.date).subtract(1,"day").format(It)},i=[lm(u,t),lm(u,a)];s!==l&&(t.match||t.focusLabel)&&i.push(lm(u,r));try{var d,m,g,y,b,w,k,x,S,C;const[e,t,r]=await Promise.all(i.map(_)),a={...t.data},{data:o}=r||c.current||e;c.current={data:o};const l={...e.data,totalSeries:(null===(d=e.data)||void 0===d?void 0:d.totalSeries)||(null===(m=e.data)||void 0===m||null===(g=m.headStats)||void 0===g?void 0:g.numSeries)||0,totalLabelValuePairs:(null===(y=e.data)||void 0===y?void 0:y.totalLabelValuePairs)||(null===(b=e.data)||void 0===b||null===(w=b.headStats)||void 0===w?void 0:w.numLabelValuePairs)||0,seriesCountByLabelName:(null===(k=e.data)||void 0===k?void 0:k.seriesCountByLabelName)||[],seriesCountByFocusLabelValue:(null===(x=e.data)||void 0===x?void 0:x.seriesCountByFocusLabelValue)||[],totalSeriesByAll:(null===o||void 0===o?void 0:o.totalSeries)||(null===o||void 0===o||null===(S=o.headStats)||void 0===S?void 0:S.numSeries)||f.totalSeriesByAll||0,totalSeriesPrev:(null===a||void 0===a?void 0:a.totalSeries)||(null===a||void 0===a||null===(C=a.headStats)||void 0===C?void 0:C.numSeries)||0},s=null===n||void 0===n?void 0:n.replace(/[{}"]/g,"");l.seriesCountByLabelValuePair=l.seriesCountByLabelValuePair.filter((e=>e.name!==s)),((e,t)=>{Object.keys(e).forEach((n=>{const r=n,a=e[r],o=t[r];Array.isArray(a)&&Array.isArray(o)&&a.forEach((e=>{var t;const n=null===(t=o.find((t=>t.name===e.name)))||void 0===t?void 0:t.value;e.diff=n?e.value-n:0,e.valuePrev=n||0}))}))})(l,a),v(l),h(!1)}catch(Tp){h(!1),Tp instanceof Error&&p("".concat(Tp.name,": ").concat(Tp.message))}};return(0,r.useEffect)((()=>{b({topN:i,match:n,date:l,focusLabel:a})}),[u,n,a,i,l]),(0,r.useEffect)((()=>{m&&(v(e.defaultTSDBStatus),h(!1))}),[m]),(0,r.useEffect)((()=>{const e=Je(u);y(!!e)}),[u]),e.tsdbStatusData=f,{isLoading:d,appConfigurator:e,error:m,isCluster:g}},fm={seriesCountByMetricName:e=>{let{query:t}=e;return vm("__name__",t)},seriesCountByLabelName:e=>{let{query:t}=e;return"{".concat(t,'!=""}')},seriesCountByFocusLabelValue:e=>{let{query:t,focusLabel:n}=e;return vm(n,t)},seriesCountByLabelValuePair:e=>{let{query:t}=e;const n=t.split("="),r=n[0],a=n.slice(1).join("=");return vm(r,a)},labelValueCountByLabelName:e=>{let{query:t,match:n}=e;return""===n?"{".concat(t,'!=""}'):"".concat(n.replace("}",""),", ").concat(t,'!=""}')}},vm=(e,t)=>e?"{"+e+"="+JSON.stringify(t)+"}":"",gm=e=>{var t;let{totalSeries:n=0,totalSeriesPrev:r=0,totalSeriesAll:a=0,seriesCountByMetricName:o=[],isPrometheus:i}=e;const{isMobile:l}=Br(),[s]=He(),c=s.get("match"),u=s.get("focusLabel"),d=/__name__/.test(c||""),h=(null===(t=o[0])||void 0===t?void 0:t.value)/a*100,m=n-r,p=Math.abs(m)/r*100,f=[{title:"Total series",value:n.toLocaleString("en-US"),dynamic:n&&r&&!i?"".concat(p.toFixed(2),"%"):"",display:!u,info:'The total number of active time series. \n A time series is uniquely identified by its name plus a set of its labels. \n For example, temperature{city="NY",country="US"} and temperature{city="SF",country="US"} \n are two distinct series, since they differ by the city label.'},{title:"Percentage from total",value:isNaN(h)?"-":"".concat(h.toFixed(2),"%"),display:d,info:"The share of these series in the total number of time series."}].filter((e=>e.display));return f.length?Nt("div",{className:kr()({"vm-cardinality-totals":!0,"vm-cardinality-totals_mobile":l}),children:f.map((e=>{let{title:t,value:n,info:a,dynamic:o}=e;return Nt("div",{className:"vm-cardinality-totals-card",children:[Nt("h4",{className:"vm-cardinality-totals-card__title",children:[t,a&&Nt(ha,{title:Nt("p",{className:"vm-cardinality-totals-card__tooltip",children:a}),children:Nt("div",{className:"vm-cardinality-totals-card__info-icon",children:Nt(On,{})})})]}),Nt("span",{className:"vm-cardinality-totals-card__value",children:n}),!!o&&Nt(ha,{title:"in relation to the previous day: ".concat(r.toLocaleString("en-US")),children:Nt("span",{className:kr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":m<0,"vm-dynamic-number_negative vm-dynamic-number_up":m>0}),children:o})})]},t)}))}):null},ym=(e,t)=>{const[n]=He(),a=n.get(t)?n.get(t):e,[o,i]=(0,r.useState)(a);return(0,r.useEffect)((()=>{a!==o&&i(a)}),[a]),[o,i]},_m=e=>{let{isPrometheus:t,isCluster:n,...a}=e;const{isMobile:o}=Br(),[i]=He(),{setSearchParamsFromKeys:l}=ao(),s=i.get("tips")||"",[c,u]=ym("","match"),[d,h]=ym("","focusLabel"),[m,p]=ym(10,"topN"),f=(0,r.useMemo)((()=>m<0?"Number must be bigger than zero":""),[m]),v=()=>{l({match:c,topN:m,focusLabel:d})};return(0,r.useEffect)((()=>{const e=i.get("match"),t=+(i.get("topN")||10),n=i.get("focusLabel");e!==c&&u(e||""),t!==m&&p(t),n!==d&&h(n||"")}),[i]),Nt("div",{className:kr()({"vm-cardinality-configurator":!0,"vm-cardinality-configurator_mobile":o,"vm-block":!0,"vm-block_mobile":o}),children:[Nt("div",{className:"vm-cardinality-configurator-controls",children:[Nt("div",{className:"vm-cardinality-configurator-controls__query",children:Nt(Ha,{label:"Time series selector",type:"string",value:c,onChange:u,onEnter:v})}),Nt("div",{className:"vm-cardinality-configurator-controls__item",children:Nt(Ha,{label:"Focus label",type:"text",value:d||"",onChange:h,onEnter:v,endIcon:Nt(ha,{title:Nt("div",{children:Nt("p",{children:"To identify values with the highest number of series for the selected label."})}),children:Nt(sr,{})})})}),Nt("div",{className:"vm-cardinality-configurator-controls__item vm-cardinality-configurator-controls__item_limit",children:Nt(Ha,{label:"Limit entries",type:"number",value:t?10:m,error:f,disabled:t,helperText:t?"not available for Prometheus":"",onChange:e=>{const t=+e;p(isNaN(t)?0:t)},onEnter:v})})]}),Nt("div",{className:"vm-cardinality-configurator-bottom",children:[Nt(gm,{isPrometheus:t,isCluster:n,...a}),n&&Nt("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Nt(Ll,{href:"https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cardinality-explorer-statistic-inaccuracy",withIcon:!0,children:[Nt(ir,{}),"Statistic inaccuracy explanation"]})}),Nt("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Nt(Ll,{href:"https://docs.victoriametrics.com/#cardinality-explorer",withIcon:!0,children:[Nt(ir,{}),"Documentation"]})}),Nt("div",{className:"vm-cardinality-configurator-bottom__execute",children:[Nt(ha,{title:s?"Hide tips":"Show tips",children:Nt(ta,{variant:"text",color:s?"warning":"gray",startIcon:Nt(hr,{}),onClick:()=>{const e=i.get("tips")||"";l({tips:e?"":"true"})},ariaLabel:"visibility tips"})}),Nt(ta,{variant:"text",startIcon:Nt(Pn,{}),onClick:()=>{l({match:"",focusLabel:""})},children:"Reset"}),Nt(ta,{startIcon:Nt(qn,{}),onClick:v,children:"Execute Query"})]})]})]})};function bm(e){const{order:t,orderBy:n,onRequestSort:r,headerCells:a}=e;return Nt("thead",{className:"vm-table-header vm-cardinality-panel-table__header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:a.map((e=>{return Nt("th",{className:kr()({"vm-table-cell vm-table-cell_header":!0,"vm-table-cell_sort":"action"!==e.id&&"percentage"!==e.id,"vm-table-cell_right":"action"===e.id}),onClick:(a=e.id,e=>{r(e,a)}),children:Nt("div",{className:"vm-table-cell__content",children:[e.info?Nt(ha,{title:e.info,children:[Nt("div",{className:"vm-metrics-content-header__tip-icon",children:Nt(On,{})}),e.label]}):Nt(Ct.FK,{children:e.label}),"action"!==e.id&&"percentage"!==e.id&&Nt("div",{className:kr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":n===e.id,"vm-table__sort-icon_desc":"desc"===t&&n===e.id}),children:Nt(Hn,{})})]})},e.id);var a}))})})}const wm=["date","timestamp","time"];function km(e,t,n){const r=e[n],a=t[n],i=wm.includes("".concat(n))?o()("".concat(r)).unix():r,l=wm.includes("".concat(n))?o()("".concat(a)).unix():a;return li?1:0}function xm(e,t){return"desc"===e?(e,n)=>km(e,n,t):(e,n)=>-km(e,n,t)}function Sm(e,t){const n=e.map(((e,t)=>[e,t]));return n.sort(((e,n)=>{const r=t(e[0],n[0]);return 0!==r?r:e[1]-n[1]})),n.map((e=>e[0]))}const Cm=e=>{let{rows:t,headerCells:n,defaultSortColumn:a,tableCells:o}=e;const[i,l]=(0,r.useState)("desc"),[s,c]=(0,r.useState)(a),u=Sm(t,xm(i,s));return Nt("table",{className:"vm-table vm-cardinality-panel-table",children:[Nt(bm,{order:i,orderBy:s,onRequestSort:(e,t)=>{l(s===t&&"asc"===i?"desc":"asc"),c(t)},rowCount:t.length,headerCells:n}),Nt("tbody",{className:"vm-table-header",children:u.map((e=>Nt("tr",{className:"vm-table__row",children:o(e)},e.name)))})]})},Em=e=>{let{row:t,totalSeries:n,totalSeriesPrev:r,onActionClick:a}=e;const o=n>0?t.value/n*100:-1,i=r>0?t.valuePrev/r*100:-1,l=[o,i].some((e=>-1===e)),s=o-i,c=l?"":"".concat(s.toFixed(2),"%"),u=()=>{a(t.name)};return Nt(Ct.FK,{children:[Nt("td",{className:"vm-table-cell",children:Nt("span",{className:"vm-link vm-link_colored",onClick:u,children:t.name})},t.name),Nt("td",{className:"vm-table-cell",children:[t.value,!!t.diff&&Nt(ha,{title:"in relation to the previous day: ".concat(t.valuePrev),children:Nt("span",{className:kr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive":t.diff<0,"vm-dynamic-number_negative":t.diff>0}),children:["\xa0",t.diff>0?"+":"",t.diff]})})]},t.value),o>0&&Nt("td",{className:"vm-table-cell",children:Nt("div",{className:"vm-cardinality-panel-table__progress",children:[Nt(Rl,{value:o}),c&&Nt(ha,{title:"in relation to the previous day",children:Nt("span",{className:kr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":s<0,"vm-dynamic-number_negative vm-dynamic-number_up":s>0}),children:c})})]})},t.progressValue),Nt("td",{className:"vm-table-cell vm-table-cell_right",children:Nt("div",{className:"vm-table-cell__content",children:Nt(ha,{title:"Filter by ".concat(t.name),children:Nt(ta,{variant:"text",size:"small",onClick:u,children:Nt(Yn,{})})})})},"action")]})},Nm=e=>{let{data:t}=e;const[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)([0,0]);return(0,r.useEffect)((()=>{const e=t.sort(((e,t)=>t.value-e.value)),n=(e=>{const t=e.map((e=>e.value)),n=Math.ceil(t[0]||1),r=n/9;return new Array(11).fill(n+r).map(((e,t)=>Math.round(e-r*t)))})(e);i(n),a(e.map((e=>({...e,percentage:e.value/n[0]*100}))))}),[t]),Nt("div",{className:"vm-simple-bar-chart",children:[Nt("div",{className:"vm-simple-bar-chart-y-axis",children:o.map((e=>Nt("div",{className:"vm-simple-bar-chart-y-axis__tick",children:e},e)))}),Nt("div",{className:"vm-simple-bar-chart-data",children:n.map((e=>{let{name:t,value:n,percentage:r}=e;return Nt(ha,{title:"".concat(t,": ").concat(n),placement:"top-center",children:Nt("div",{className:"vm-simple-bar-chart-data-item",style:{maxHeight:"".concat(r||0,"%")}})},"".concat(t,"_").concat(n))}))})]})},Am=e=>{let{rows:t,tabs:n=[],chartContainer:a,totalSeries:o,totalSeriesPrev:i,onActionClick:l,sectionTitle:s,tip:c,tableHeaderCells:u,isPrometheus:d}=e;const{isMobile:h}=Br(),[m,p]=(0,r.useState)("table"),f=d&&!t.length,v=(0,r.useMemo)((()=>n.map(((e,t)=>({value:e,label:e,icon:Nt(0===t?Kn:Wn,{})})))),[n]);return Nt("div",{className:kr()({"vm-metrics-content":!0,"vm-metrics-content_mobile":h,"vm-block":!0,"vm-block_mobile":h}),children:[Nt("div",{className:"vm-metrics-content-header vm-section-header",children:[Nt("h5",{className:kr()({"vm-metrics-content-header__title":!0,"vm-section-header__title":!0,"vm-section-header__title_mobile":h}),children:[!h&&c&&Nt(ha,{title:Nt("p",{dangerouslySetInnerHTML:{__html:c},className:"vm-metrics-content-header__tip"}),children:Nt("div",{className:"vm-metrics-content-header__tip-icon",children:Nt(On,{})})}),s]}),Nt("div",{className:"vm-section-header__tabs",children:Nt(Nr,{activeItem:m,items:v,onChange:p})})]}),f&&Nt("div",{className:"vm-metrics-content-prom-data",children:[Nt("div",{className:"vm-metrics-content-prom-data__icon",children:Nt(On,{})}),Nt("h3",{className:"vm-metrics-content-prom-data__title",children:"Prometheus Data Limitation"}),Nt("p",{className:"vm-metrics-content-prom-data__text",children:["Due to missing data from your Prometheus source, some tables may appear empty.",Nt("br",{}),"This does not indicate an issue with your system or our tool."]})]}),!f&&"table"===m&&Nt("div",{ref:a,className:kr()({"vm-metrics-content__table":!0,"vm-metrics-content__table_mobile":h}),children:Nt(Cm,{rows:t,headerCells:u,defaultSortColumn:"value",tableCells:e=>Nt(Em,{row:e,totalSeries:o,totalSeriesPrev:i,onActionClick:l})})}),!f&&"graph"===m&&Nt("div",{className:"vm-metrics-content__chart",children:Nt(Nm,{data:t.map((e=>{let{name:t,value:n}=e;return{name:t,value:n}}))})})]})},Mm=e=>{let{title:t,children:n}=e;return Nt("div",{className:"vm-cardinality-tip",children:[Nt("div",{className:"vm-cardinality-tip-header",children:[Nt("div",{className:"vm-cardinality-tip-header__tip-icon",children:Nt(hr,{})}),Nt("h4",{className:"vm-cardinality-tip-header__title",children:t||"Tips"})]}),Nt("p",{className:"vm-cardinality-tip__description",children:n})]})},Tm=()=>Nt(Mm,{title:"Metrics with a high number of series",children:Nt("ul",{children:[Nt("li",{children:["Identify and eliminate labels with frequently changed values to reduce their\xa0",Nt(Ll,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-cardinality",children:"cardinality"}),"\xa0and\xa0",Nt(Ll,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate",children:"high churn rate"})]}),Nt("li",{children:["Find unused time series and\xa0",Nt(Ll,{href:"https://docs.victoriametrics.com/relabeling.html",children:"drop entire metrics"})]}),Nt("li",{children:["Aggregate time series before they got ingested into the database via\xa0",Nt(Ll,{href:"https://docs.victoriametrics.com/stream-aggregation.html",children:"streaming aggregation"})]})]})}),Lm=()=>Nt(Mm,{title:"Labels with a high number of unique values",children:Nt("ul",{children:[Nt("li",{children:"Decrease the number of unique label values to reduce cardinality"}),Nt("li",{children:["Drop the label entirely via\xa0",Nt(Ll,{href:"https://docs.victoriametrics.com/relabeling.html",children:"relabeling"})]}),Nt("li",{children:"For volatile label values (such as URL path, user session, etc.) consider printing them to the log file instead of adding to time series"})]})}),Im=()=>Nt(Mm,{title:"Dashboard of a single metric",children:[Nt("p",{children:"This dashboard helps to understand the cardinality of a single metric."}),Nt("p",{children:"Each time series is a unique combination of key-value label pairs. Therefore a label key with many values can create a lot of time series for a particular metric. If you\u2019re trying to decrease the cardinality of a metric, start by looking at the labels with the highest number of values."}),Nt("p",{children:"Use the series selector at the top of the page to apply additional filters."})]}),Pm=()=>Nt(Mm,{title:"Dashboard of a label",children:[Nt("p",{children:"This dashboard helps you understand the count of time series per label."}),Nt("p",{children:"Use the selector at the top of the page to pick a label name you\u2019d like to inspect. For the selected label name, you\u2019ll see the label values that have the highest number of series associated with them. So if you\u2019ve chosen `instance` as your label name, you may see that `657` time series have value \u201chost-1\u201d attached to them and `580` time series have value `host-2` attached to them."}),Nt("p",{children:"This can be helpful in allowing you to determine where the bulk of your time series are coming from. If the label \u201cinstance=host-1\u201d was applied to 657 series and the label \u201cinstance=host-2\u201d was only applied to 580 series, you\u2019d know, for example, that host-01 was responsible for sending the majority of the time series."})]}),Om=()=>{const{isMobile:e}=Br(),[t]=He(),{setSearchParamsFromKeys:n}=ao(),r=t.get("tips")||"",a=t.get("match")||"",o=t.get("focusLabel")||"",{isLoading:i,appConfigurator:l,error:s,isCluster:c}=pm(),{tsdbStatusData:u,getDefaultState:d,tablesHeaders:h,sectionsTips:m}=l,p=d(a,o);return Nt("div",{className:kr()({"vm-cardinality-panel":!0,"vm-cardinality-panel_mobile":e}),children:[i&&Nt(bl,{message:"Please wait while cardinality stats is calculated. \n This may take some time if the db contains big number of time series."}),Nt(_m,{isPrometheus:l.isPrometheusData,totalSeries:u.totalSeries,totalSeriesPrev:u.totalSeriesPrev,totalSeriesAll:u.totalSeriesByAll,totalLabelValuePairs:u.totalLabelValuePairs,seriesCountByMetricName:u.seriesCountByMetricName,isCluster:c}),r&&Nt("div",{className:"vm-cardinality-panel-tips",children:[!a&&!o&&Nt(Tm,{}),a&&!o&&Nt(Im,{}),!a&&!o&&Nt(Lm,{}),o&&Nt(Pm,{})]}),s&&Nt(Yr,{variant:"error",children:s}),l.keys(a,o).map((e=>{return Nt(Am,{sectionTitle:l.sectionsTitles(o)[e],tip:m[e],rows:u[e],onActionClick:(t=e,e=>{const r={match:fm[t]({query:e,focusLabel:o,match:a})};"labelValueCountByLabelName"!==t&&"seriesCountByLabelName"!=t||(r.focusLabel=e),"seriesCountByFocusLabelValue"==t&&(r.focusLabel=""),n(r)}),tabs:p.tabs[e],chartContainer:p.containerRefs[e],totalSeriesPrev:l.totalSeries(e,!0),totalSeries:l.totalSeries(e),tableHeaderCells:h[e],isPrometheus:l.isPrometheusData},e);var t}))]})},Rm=e=>(["topByAvgDuration","topByCount","topBySumDuration"].forEach((t=>{const n=e[t];Array.isArray(n)&&n.forEach((e=>{const t=en(1e3*e.timeRangeSeconds);e.url=((e,t)=>{var n;const{query:r,timeRangeSeconds:a}=e,o=["g0.expr=".concat(encodeURIComponent(r))],i=null===(n=rn.find((e=>e.duration===t)))||void 0===n?void 0:n.id;return i&&o.push("g0.relative_time=".concat(i)),a&&o.push("g0.range_input=".concat(t)),"".concat(We.home,"?").concat(o.join("&"))})(e,t),e.timeRange=t}))})),e),Dm=e=>{let{topN:t,maxLifetime:n}=e;const{serverUrl:a}=Mt(),{setSearchParamsFromKeys:o}=ao(),[i,l]=(0,r.useState)(null),[s,c]=(0,r.useState)(!1),[u,d]=(0,r.useState)(),h=(0,r.useMemo)((()=>((e,t,n)=>"".concat(e,"/api/v1/status/top_queries?topN=").concat(t||"","&maxLifetime=").concat(n||""))(a,t,n)),[a,t,n]);return{data:i,error:u,loading:s,fetch:async()=>{c(!0),o({topN:t,maxLifetime:n});try{const e=await fetch(h),t=await e.json();l(e.ok?Rm(t):null),d(String(t.error||""))}catch(Tp){Tp instanceof Error&&"AbortError"!==Tp.name&&d("".concat(Tp.name,": ").concat(Tp.message))}c(!1)}}},zm=e=>{let{rows:t,columns:n,defaultOrderBy:a}=e;const o=pl(),[i,l]=(0,r.useState)(a||"count"),[s,c]=(0,r.useState)("desc"),u=(0,r.useMemo)((()=>Sm(t,xm(s,i))),[t,i,s]),d=e=>()=>{var t;t=e,c((e=>"asc"===e&&i===t?"desc":"asc")),l(t)},h=e=>{let{query:t}=e;return async()=>{await o(t,"Query has been copied")}};return Nt("table",{className:"vm-table",children:[Nt("thead",{className:"vm-table-header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>Nt("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:d(e.sortBy||e.key),children:Nt("div",{className:"vm-table-cell__content",children:[e.title||e.key,Nt("div",{className:kr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":i===e.key,"vm-table__sort-icon_desc":"desc"===s&&i===e.key}),children:Nt(Hn,{})})]})},e.key))),Nt("th",{className:"vm-table-cell vm-table-cell_header"})," "]})}),Nt("tbody",{className:"vm-table-body",children:u.map(((e,t)=>Nt("tr",{className:"vm-table__row",children:[n.map((t=>Nt("td",{className:"vm-table-cell",children:e[t.key]||"-"},t.key))),Nt("td",{className:"vm-table-cell vm-table-cell_no-padding",children:Nt("div",{className:"vm-top-queries-panels__table-actions",children:[e.url&&Nt(ha,{title:"Execute query",children:Nt(Re,{to:e.url,target:"_blank",rel:"noreferrer","aria-disabled":!0,children:Nt(ta,{variant:"text",size:"small",startIcon:Nt(Yn,{}),ariaLabel:"execute query"})})}),Nt(ha,{title:"Copy query",children:Nt(ta,{variant:"text",size:"small",startIcon:Nt(rr,{}),onClick:h(e),ariaLabel:"copy query"})})]})})]},t)))})]})},Fm=["table","JSON"].map(((e,t)=>({value:String(t),label:e,icon:Nt(0===t?Kn:Qn,{})}))),jm=e=>{let{rows:t,title:n,columns:a,defaultOrderBy:o}=e;const{isMobile:i}=Br(),[l,s]=(0,r.useState)(0);return Nt("div",{className:kr()({"vm-top-queries-panel":!0,"vm-block":!0,"vm-block_mobile":i}),children:[Nt("div",{className:kr()({"vm-top-queries-panel-header":!0,"vm-section-header":!0,"vm-top-queries-panel-header_mobile":i}),children:[Nt("h5",{className:kr()({"vm-section-header__title":!0,"vm-section-header__title_mobile":i}),children:n}),Nt("div",{className:"vm-section-header__tabs",children:Nt(Nr,{activeItem:String(l),items:Fm,onChange:e=>{s(+e)}})})]}),Nt("div",{className:kr()({"vm-top-queries-panel__table":!0,"vm-top-queries-panel__table_mobile":i}),children:[0===l&&Nt(zm,{rows:t,columns:a,defaultOrderBy:o}),1===l&&Nt(Bh,{data:t})]})]})},Hm=()=>{const{isMobile:e}=Br(),[t,n]=ym(10,"topN"),[a,i]=ym("10m","maxLifetime"),{data:l,error:s,loading:c,fetch:u}=Dm({topN:t,maxLifetime:a}),d=(0,r.useMemo)((()=>{const e=a.trim().split(" ").reduce(((e,t)=>{const n=Kt(t);return n?{...e,...n}:{...e}}),{});return!!o().duration(e).asMilliseconds()}),[a]),h=(0,r.useMemo)((()=>!!t&&t<1),[t]),m=(0,r.useMemo)((()=>h?"Number must be bigger than zero":""),[h]),p=(0,r.useMemo)((()=>d?"":"Invalid duration value"),[d]),f=e=>{if(!l)return e;const t=l[e];return"number"===typeof t?$d(t,t,t):t||e},v=e=>{"Enter"===e.key&&u()};return(0,r.useEffect)((()=>{l&&(t||n(+l.topN),a||i(l.maxLifetime))}),[l]),(0,r.useEffect)((()=>(u(),window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)})),[]),Nt("div",{className:kr()({"vm-top-queries":!0,"vm-top-queries_mobile":e}),children:[c&&Nt(bl,{containerStyles:{height:"500px"}}),Nt("div",{className:kr()({"vm-top-queries-controls":!0,"vm-block":!0,"vm-block_mobile":e}),children:[Nt("div",{className:"vm-top-queries-controls-fields",children:[Nt("div",{className:"vm-top-queries-controls-fields__item",children:Nt(Ha,{label:"Max lifetime",value:a,error:p,helperText:"For example ".concat("30ms, 15s, 3d4h, 1y2w"),onChange:e=>{i(e)},onKeyDown:v})}),Nt("div",{className:"vm-top-queries-controls-fields__item",children:Nt(Ha,{label:"Number of returned queries",type:"number",value:t||"",error:m,onChange:e=>{n(+e)},onKeyDown:v})})]}),Nt("div",{className:kr()({"vm-top-queries-controls-bottom":!0,"vm-top-queries-controls-bottom_mobile":e}),children:[Nt("div",{className:"vm-top-queries-controls-bottom__info",children:["VictoriaMetrics tracks the last\xa0",Nt(ha,{title:"search.queryStats.lastQueriesCount",children:Nt("b",{children:f("search.queryStats.lastQueriesCount")})}),"\xa0queries with durations at least\xa0",Nt(ha,{title:"search.queryStats.minQueryDuration",children:Nt("b",{children:f("search.queryStats.minQueryDuration")})})]}),Nt("div",{className:"vm-top-queries-controls-bottom__button",children:Nt(ta,{startIcon:Nt(qn,{}),onClick:u,children:"Execute"})})]})]}),s&&Nt(Yr,{variant:"error",children:s}),l&&Nt(Ct.FK,{children:Nt("div",{className:"vm-top-queries-panels",children:[Nt(jm,{rows:l.topBySumDuration,title:"Queries with most summary time to execute",columns:[{key:"query"},{key:"sumDurationSeconds",title:"sum duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"sumDurationSeconds"}),Nt(jm,{rows:l.topByAvgDuration,title:"Most heavy queries",columns:[{key:"query"},{key:"avgDurationSeconds",title:"avg duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"avgDurationSeconds"}),Nt(jm,{rows:l.topByCount,title:"Most frequently executed queries",columns:[{key:"query"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}]})]})})]})},Vm={"color-primary":"#589DF6","color-secondary":"#316eca","color-error":"#e5534b","color-warning":"#c69026","color-info":"#539bf5","color-success":"#57ab5a","color-background-body":"#22272e","color-background-block":"#2d333b","color-background-tooltip":"rgba(22, 22, 22, 0.8)","color-text":"#cdd9e5","color-text-secondary":"#768390","color-text-disabled":"#636e7b","box-shadow":"rgba(0, 0, 0, 0.16) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.2) 0px 2px 8px 0px","border-divider":"1px solid rgba(99, 110, 123, 0.5)","color-hover-black":"rgba(0, 0, 0, 0.12)","color-log-hits-bar":"rgba(255, 255, 255, 0.18)"},$m={"color-primary":"#3F51B5","color-secondary":"#E91E63","color-error":"#FD080E","color-warning":"#FF8308","color-info":"#03A9F4","color-success":"#4CAF50","color-background-body":"#FEFEFF","color-background-block":"#FFFFFF","color-background-tooltip":"rgba(80,80,80,0.9)","color-text":"#110f0f","color-text-secondary":"#706F6F","color-text-disabled":"#A09F9F","box-shadow":"rgba(0, 0, 0, 0.08) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.1) 0px 2px 8px 0px","border-divider":"1px solid rgba(0, 0, 0, 0.15)","color-hover-black":"rgba(0, 0, 0, 0.06)","color-log-hits-bar":"rgba(0, 0, 0, 0.18)"},Um=()=>{const[e,t]=(0,r.useState)(_t()),n=e=>{t(e.matches)};return(0,r.useEffect)((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)");return e.addEventListener("change",n),()=>e.removeEventListener("change",n)}),[]),e},Bm=["primary","secondary","error","warning","info","success"],qm=e=>{let{onLoaded:t}=e;const n=Qe(),{palette:a={}}=Ke(),{theme:o}=Mt(),i=Um(),l=Tt(),s=Er(),[c,u]=(0,r.useState)({[ft.dark]:Vm,[ft.light]:$m,[ft.system]:_t()?Vm:$m}),d=()=>{const{innerWidth:e,innerHeight:t}=window,{clientWidth:n,clientHeight:r}=document.documentElement;yt("scrollbar-width","".concat(e-n,"px")),yt("scrollbar-height","".concat(t-r,"px")),yt("vh","".concat(.01*t,"px"))},h=()=>{Bm.forEach(((e,n)=>{const r=(e=>{let t=e.replace("#","").trim();if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6!==t.length)throw new Error("Invalid HEX color.");return(299*parseInt(t.slice(0,2),16)+587*parseInt(t.slice(2,4),16)+114*parseInt(t.slice(4,6),16))/1e3>=128?"#000000":"#FFFFFF"})(gt("color-".concat(e)));yt("".concat(e,"-text"),r),n===Bm.length-1&&(l({type:"SET_DARK_THEME"}),t(!0))}))},m=()=>{const e=et("THEME")||ft.system,t=c[e];Object.entries(t).forEach((e=>{let[t,n]=e;yt(t,n)})),h(),n&&(Bm.forEach((e=>{const t=a[e];t&&yt("color-".concat(e),t)})),h())};return(0,r.useEffect)((()=>{d(),m()}),[c]),(0,r.useEffect)(d,[s]),(0,r.useEffect)((()=>{const e=_t()?Vm:$m;c[ft.system]!==e?u((t=>({...t,[ft.system]:e}))):m()}),[o,i]),(0,r.useEffect)((()=>{n&&l({type:"SET_THEME",payload:ft.light})}),[]),null},Ym=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(!1),o=(0,r.useRef)(document.body),i=e=>{e.preventDefault(),e.stopPropagation(),"dragenter"===e.type||"dragover"===e.type?a(!0):"dragleave"===e.type&&a(!1)};return Cr("dragenter",i,o),Cr("dragleave",i,o),Cr("dragover",i,o),Cr("drop",(e=>{var n;e.preventDefault(),e.stopPropagation(),a(!1),null!==e&&void 0!==e&&null!==(n=e.dataTransfer)&&void 0!==n&&n.files&&e.dataTransfer.files[0]&&(e=>{const n=Array.from(e||[]);t(n)})(e.dataTransfer.files)}),o),Cr("paste",(e=>{var n;const r=null===(n=e.clipboardData)||void 0===n?void 0:n.items;if(!r)return;const a=Array.from(r).filter((e=>"application/json"===e.type)).map((e=>e.getAsFile())).filter((e=>null!==e));t(a)}),o),{files:e,dragging:n}},Wm=e=>{let{onOpenModal:t,onChange:n}=e;return Nt("div",{className:"vm-upload-json-buttons",children:[Nt(ta,{variant:"outlined",onClick:t,children:"Paste JSON"}),Nt(ta,{children:["Upload Files",Nt("input",{id:"json",type:"file",accept:"application/json",multiple:!0,title:" ",onChange:n})]})]})},Km=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)([]),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=ra(!1),c=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";a((n=>[{filename:t,text:": ".concat(e.message)},...n]))},u=(e,n)=>{try{const r=JSON.parse(e),a=r.trace||r;if(!a.duration_msec)return void c(new Error(pt.traceNotFound),n);const o=new Sl(a,n);t((e=>[o,...e]))}catch(Tp){Tp instanceof Error&&c(Tp,n)}},d=e=>{e.map((e=>{const t=new FileReader,n=(null===e||void 0===e?void 0:e.name)||"";t.onload=e=>{var t;const r=String(null===(t=e.target)||void 0===t?void 0:t.result);u(r,n)},t.readAsText(e)}))},h=e=>{a([]);const t=Array.from(e.target.files||[]);d(t),e.target.value=""},m=e=>()=>{(e=>{a((t=>t.filter(((t,n)=>n!==e))))})(e)},{files:p,dragging:f}=Ym();return(0,r.useEffect)((()=>{d(p)}),[p]),Nt("div",{className:"vm-trace-page",children:[Nt("div",{className:"vm-trace-page-header",children:[Nt("div",{className:"vm-trace-page-header-errors",children:n.map(((e,t)=>Nt("div",{className:"vm-trace-page-header-errors-item",children:[Nt(Yr,{variant:"error",children:[Nt("b",{className:"vm-trace-page-header-errors-item__filename",children:e.filename}),Nt("span",{children:e.text})]}),Nt(ta,{className:"vm-trace-page-header-errors-item__close",startIcon:Nt(In,{}),variant:"text",color:"error",onClick:m(t)})]},"".concat(e,"_").concat(t))))}),Nt("div",{children:o&&Nt(Wm,{onOpenModal:l,onChange:h})})]}),o&&Nt("div",{children:Nt(jl,{jsonEditor:!0,traces:e,onDeleteClick:n=>{const r=e.filter((e=>e.idValue!==n.idValue));t([...r])}})}),!o&&Nt("div",{className:"vm-trace-page-preview",children:[Nt("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain tracing information in JSON format.","\n","In order to use tracing please refer to the doc:\xa0",Nt("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/#query-tracing",target:"_blank",rel:"help noreferrer",children:"https://docs.victoriametrics.com/#query-tracing"}),"\n","Tracing graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Nt(Wm,{onOpenModal:l,onChange:h})]}),i&&Nt(da,{title:"Paste JSON",onClose:s,children:Nt(Fl,{editable:!0,displayTitle:!0,defaultTile:"JSON ".concat(e.length+1),onClose:s,onUpload:u})}),f&&Nt("div",{className:"vm-trace-page__dropzone"})]})},Qm=e=>{const{serverUrl:t}=Mt(),{period:n}=fn(),[a,o]=(0,r.useState)([]),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)(),u=(0,r.useMemo)((()=>((e,t,n)=>{const r="{job=".concat(JSON.stringify(n),"}");return"".concat(e,"/api/v1/label/instance/values?match[]=").concat(encodeURIComponent(r),"&start=").concat(t.start,"&end=").concat(t.end)})(t,n,e)),[t,n,e]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{l(!0);try{const e=await fetch(u),t=await e.json(),n=t.data||[];o(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?c(void 0):c("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Tp){Tp instanceof Error&&c("".concat(Tp.name,": ").concat(Tp.message))}l(!1)})().catch(console.error)}),[u]),{instances:a,isLoading:i,error:s}},Zm=(e,t)=>{const{serverUrl:n}=Mt(),{period:a}=fn(),[o,i]=(0,r.useState)([]),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>((e,t,n,r)=>{const a=Object.entries({job:n,instance:r}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))})).join(","),o="{".concat(a,"}");return"".concat(e,"/api/v1/label/__name__/values?match[]=").concat(encodeURIComponent(o),"&start=").concat(t.start,"&end=").concat(t.end)})(n,a,e,t)),[n,a,e,t]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{s(!0);try{const e=await fetch(d),t=await e.json(),n=t.data||[];i(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Tp){Tp instanceof Error&&u("".concat(Tp.name,": ").concat(Tp.message))}s(!1)})().catch(console.error)}),[d]),{names:o,isLoading:l,error:c}},Gm=e=>{let{name:t,job:n,instance:a,rateEnabled:o,isBucket:i,height:l}=e;const{isMobile:s}=Br(),{customStep:c,yaxis:u}=Hr(),{period:d}=fn(),h=Vr(),m=vn(),p=Zt(d.end-d.start),f=Qt(c),v=en(10*f*1e3),[g,y]=(0,r.useState)(!1),[_,b]=(0,r.useState)(!1),w=g&&c===p?v:c,k=(0,r.useMemo)((()=>{const e=Object.entries({job:n,instance:a}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))}));e.push("__name__=".concat(JSON.stringify(t))),"node_cpu_seconds_total"==t&&e.push('mode!="idle"');const r="{".concat(e.join(","),"}");if(i)return"sum(rate(".concat(r,")) by (vmrange, le)");const l=o?"rollup_rate(".concat(r,")"):"rollup(".concat(r,")");return"\nwith (q = ".concat(l,') (\n alias(min(label_match(q, "rollup", "min")), "min"),\n alias(max(label_match(q, "rollup", "max")), "max"),\n alias(avg(label_match(q, "rollup", "avg")), "avg"),\n)')}),[t,n,a,o,i]),{isLoading:x,graphData:S,error:C,queryErrors:E,warning:N,isHistogram:A}=Ml({predefinedQuery:[k],visible:!0,customStep:w,showAllSeries:_});return(0,r.useEffect)((()=>{y(A)}),[A]),Nt("div",{className:kr()({"vm-explore-metrics-graph":!0,"vm-explore-metrics-graph_mobile":s}),children:[x&&Nt(bl,{}),C&&Nt(Yr,{variant:"error",children:C}),E[0]&&Nt(Yr,{variant:"error",children:E[0]}),N&&Nt(Vl,{warning:N,query:[k],onChange:b}),S&&d&&Nt(Fh,{data:S,period:d,customStep:w,query:[k],yaxis:u,setYaxisLimits:e=>{h({type:"SET_YAXIS_LIMITS",payload:e})},setPeriod:e=>{let{from:t,to:n}=e;m({type:"SET_PERIOD",payload:{from:t,to:n}})},showLegend:!1,height:l,isHistogram:A})]})},Jm=e=>{let{name:t,index:n,length:r,isBucket:a,rateEnabled:o,onChangeRate:i,onRemoveItem:l,onChangeOrder:s}=e;const{isMobile:c}=Br(),{value:u,setTrue:d,setFalse:h}=ra(!1),m=()=>{l(t)},p=()=>{s(t,n,n+1)},f=()=>{s(t,n,n-1)};return Nt("div",c?{className:"vm-explore-metrics-item-header vm-explore-metrics-item-header_mobile",children:[Nt("div",{className:"vm-explore-metrics-item-header__name",children:t}),Nt(ta,{variant:"text",size:"small",startIcon:Nt(ur,{}),onClick:d,ariaLabel:"open panel settings"}),u&&Nt(da,{title:t,onClose:h,children:Nt("div",{className:"vm-explore-metrics-item-header-modal",children:[Nt("div",{className:"vm-explore-metrics-item-header-modal-order",children:[Nt(ta,{startIcon:Nt(Jn,{}),variant:"outlined",onClick:f,disabled:0===n,ariaLabel:"move graph up"}),Nt("p",{children:["position:",Nt("span",{className:"vm-explore-metrics-item-header-modal-order__index",children:["#",n+1]})]}),Nt(ta,{endIcon:Nt(Gn,{}),variant:"outlined",onClick:p,disabled:n===r-1,ariaLabel:"move graph down"})]}),!a&&Nt("div",{className:"vm-explore-metrics-item-header-modal__rate",children:[Nt(ul,{label:Nt("span",{children:["enable ",Nt("code",{children:"rate()"})]}),value:o,onChange:i,fullWidth:!0}),Nt("p",{children:"calculates the average per-second speed of metrics change"})]}),Nt(ta,{startIcon:Nt(In,{}),color:"error",variant:"outlined",onClick:m,fullWidth:!0,children:"Remove graph"})]})})]}:{className:"vm-explore-metrics-item-header",children:[Nt("div",{className:"vm-explore-metrics-item-header-order",children:[Nt(ha,{title:"move graph up",children:Nt(ta,{className:"vm-explore-metrics-item-header-order__up",startIcon:Nt(jn,{}),variant:"text",color:"gray",size:"small",onClick:f,ariaLabel:"move graph up"})}),Nt("div",{className:"vm-explore-metrics-item-header__index",children:["#",n+1]}),Nt(ha,{title:"move graph down",children:Nt(ta,{className:"vm-explore-metrics-item-header-order__down",startIcon:Nt(jn,{}),variant:"text",color:"gray",size:"small",onClick:p,ariaLabel:"move graph down"})})]}),Nt("div",{className:"vm-explore-metrics-item-header__name",children:t}),!a&&Nt("div",{className:"vm-explore-metrics-item-header__rate",children:Nt(ha,{title:"calculates the average per-second speed of metric's change",children:Nt(ul,{label:Nt("span",{children:["enable ",Nt("code",{children:"rate()"})]}),value:o,onChange:i})})}),Nt("div",{className:"vm-explore-metrics-item-header__close",children:Nt(ha,{title:"close graph",children:Nt(ta,{startIcon:Nt(In,{}),variant:"text",color:"gray",size:"small",onClick:m,ariaLabel:"close graph"})})})]})},Xm=e=>{let{name:t,job:n,instance:a,index:o,length:i,size:l,onRemoveItem:s,onChangeOrder:c}=e;const u=(0,r.useMemo)((()=>/_sum?|_total?|_count?/.test(t)),[t]),d=(0,r.useMemo)((()=>/_bucket?/.test(t)),[t]),[h,m]=(0,r.useState)(u),p=Er(),f=(0,r.useMemo)(l.height,[l,p]);return(0,r.useEffect)((()=>{m(u)}),[n]),Nt("div",{className:"vm-explore-metrics-item vm-block vm-block_empty-padding",children:[Nt(Jm,{name:t,index:o,length:i,isBucket:d,rateEnabled:h,size:l.id,onChangeRate:m,onRemoveItem:s,onChangeOrder:c}),Nt(Gm,{name:t,job:n,instance:a,rateEnabled:h,isBucket:d,height:f},"".concat(t,"_").concat(n,"_").concat(a,"_").concat(h))]})},ep=e=>{let{values:t,onRemoveItem:n}=e;const{isMobile:r}=Br();return r?Nt("span",{className:"vm-select-input-content__counter",children:["selected ",t.length]}):Nt(Ct.FK,{children:t.map((e=>{return Nt("div",{className:"vm-select-input-content__selected",children:[Nt("span",{children:e}),Nt("div",{onClick:(t=e,e=>{n(t),e.stopPropagation()}),children:Nt(In,{})})]},e);var t}))})},tp=e=>{let{value:t,list:n,label:a,placeholder:o,noOptionsText:i,clearable:l=!1,searchable:s=!1,autofocus:c,disabled:u,onChange:d}=e;const{isDarkTheme:h}=Mt(),{isMobile:m}=Br(),[p,f]=(0,r.useState)(""),v=(0,r.useRef)(null),[g,y]=(0,r.useState)(null),[_,b]=(0,r.useState)(!1),w=(0,r.useRef)(null),k=Array.isArray(t),x=Array.isArray(t)?t:void 0,S=m&&k&&!(null===x||void 0===x||!x.length),C=(0,r.useMemo)((()=>_?p:Array.isArray(t)?"":t),[t,p,_,k]),E=(0,r.useMemo)((()=>_?p||"(.+)":""),[p,_]),N=()=>{w.current&&w.current.blur()},A=()=>{b(!1),N()},M=e=>{f(""),d(e),k||A(),k&&w.current&&w.current.focus()};return(0,r.useEffect)((()=>{f(""),_&&w.current&&w.current.focus(),_||N()}),[_,w]),(0,r.useEffect)((()=>{c&&w.current&&!m&&w.current.focus()}),[c,w]),Cr("keyup",(e=>{w.current!==e.target&&b(!1)})),ea(v,A,g),Nt("div",{className:kr()({"vm-select":!0,"vm-select_dark":h,"vm-select_disabled":u}),children:[Nt("div",{className:"vm-select-input",onClick:e=>{e.target instanceof HTMLInputElement||u||b((e=>!e))},ref:v,children:[Nt("div",{className:"vm-select-input-content",children:[!(null===x||void 0===x||!x.length)&&Nt(ep,{values:x,onRemoveItem:M}),!S&&Nt("input",{value:C,type:"text",placeholder:o,onInput:e=>{f(e.target.value)},onFocus:()=>{u||b(!0)},onBlur:()=>{n.includes(p)&&d(p)},ref:w,readOnly:m||!s})]}),a&&Nt("span",{className:"vm-text-field__label",children:a}),l&&t&&Nt("div",{className:"vm-select-input__icon",onClick:(e=>t=>{M(e),t.stopPropagation()})(""),children:Nt(In,{})}),Nt("div",{className:kr()({"vm-select-input__icon":!0,"vm-select-input__icon_open":_}),children:Nt(Hn,{})})]}),Nt(Io,{label:a,value:E,options:n.map((e=>({value:e}))),anchor:v,selected:x,minLength:1,fullWidth:!0,noOptionsText:i,onSelect:M,onOpenAutocomplete:b,onChangeWrapperRef:y})]})},np=st.map((e=>e.id)),rp=e=>{let{jobs:t,instances:n,names:a,job:o,instance:i,size:l,selectedMetrics:s,onChangeJob:c,onChangeInstance:u,onToggleMetric:d,onChangeSize:h}=e;const m=(0,r.useMemo)((()=>o?"":"No instances. Please select job"),[o]),p=(0,r.useMemo)((()=>o?"":"No metric names. Please select job"),[o]),{isMobile:f}=Br(),{value:v,toggle:g,setFalse:y}=ra("false"!==et("EXPLORE_METRICS_TIPS"));return(0,r.useEffect)((()=>{Xe("EXPLORE_METRICS_TIPS","".concat(v))}),[v]),Nt(Ct.FK,{children:[Nt("div",{className:kr()({"vm-explore-metrics-header":!0,"vm-explore-metrics-header_mobile":f,"vm-block":!0,"vm-block_mobile":f}),children:[Nt("div",{className:"vm-explore-metrics-header__job",children:Nt(tp,{value:o,list:t,label:"Job",placeholder:"Please select job",onChange:c,autofocus:!o&&!!t.length&&!f,searchable:!0})}),Nt("div",{className:"vm-explore-metrics-header__instance",children:Nt(tp,{value:i,list:n,label:"Instance",placeholder:"Please select instance",onChange:u,noOptionsText:m,clearable:!0,searchable:!0})}),Nt("div",{className:"vm-explore-metrics-header__size",children:[Nt(tp,{label:"Size graphs",value:l,list:np,onChange:h}),Nt(ha,{title:"".concat(v?"Hide":"Show"," tip"),children:Nt(ta,{variant:"text",color:v?"warning":"gray",startIcon:Nt(hr,{}),onClick:g,ariaLabel:"visibility tips"})})]}),Nt("div",{className:"vm-explore-metrics-header-metrics",children:Nt(tp,{label:"Metrics",value:s,list:a,placeholder:"Search metric name",onChange:d,noOptionsText:p,clearable:!0,searchable:!0})})]}),v&&Nt(Yr,{variant:"warning",children:Nt("div",{className:"vm-explore-metrics-header-description",children:[Nt("p",{children:["Please note: this page is solely designed for exploring Prometheus metrics. Prometheus metrics always contain ",Nt("code",{children:"job"})," and ",Nt("code",{children:"instance"})," labels (see ",Nt("a",{className:"vm-link vm-link_colored",href:"https://prometheus.io/docs/concepts/jobs_instances/",children:"these docs"}),"), and this page relies on them as filters. ",Nt("br",{}),"Please use this page for Prometheus metrics only, in accordance with their naming conventions."]}),Nt(ta,{variant:"text",size:"small",startIcon:Nt(In,{}),onClick:y,ariaLabel:"close tips"})]})})]})},ap=ut("job",""),op=ut("instance",""),ip=ut("metrics",""),lp=ut("size",""),sp=st.find((e=>lp?e.id===lp:e.isDefault))||st[0],cp=()=>{const[e,t]=(0,r.useState)(ap),[n,a]=(0,r.useState)(op),[o,i]=(0,r.useState)(ip?ip.split("&"):[]),[l,s]=(0,r.useState)(sp);(e=>{let{job:t,instance:n,metrics:a,size:o}=e;const{duration:i,relativeTime:l,period:{date:s}}=fn(),{customStep:c}=Hr(),{setSearchParamsFromKeys:u}=ao(),d=()=>{const e=om({"g0.range_input":i,"g0.end_input":s,"g0.step_input":c,"g0.relative_time":l,size:o,job:t,instance:n,metrics:a});u(e)};(0,r.useEffect)(d,[i,l,s,c,t,n,a,o]),(0,r.useEffect)(d,[])})({job:e,instance:n,metrics:o.join("&"),size:l.id});const{jobs:c,isLoading:u,error:d}=(()=>{const{serverUrl:e}=Mt(),{period:t}=fn(),[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)(!1),[l,s]=(0,r.useState)(),c=(0,r.useMemo)((()=>((e,t)=>"".concat(e,"/api/v1/label/job/values?start=").concat(t.start,"&end=").concat(t.end))(e,t)),[e,t]);return(0,r.useEffect)((()=>{(async()=>{i(!0);try{const e=await fetch(c),t=await e.json(),n=t.data||[];a(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?s(void 0):s("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Tp){Tp instanceof Error&&s("".concat(Tp.name,": ").concat(Tp.message))}i(!1)})().catch(console.error)}),[c]),{jobs:n,isLoading:o,error:l}})(),{instances:h,isLoading:m,error:p}=Qm(e),{names:f,isLoading:v,error:g}=Zm(e,n),y=(0,r.useMemo)((()=>u||m||v),[u,m,v]),_=(0,r.useMemo)((()=>d||p||g),[d,p,g]),b=e=>{i(e?t=>t.includes(e)?t.filter((t=>t!==e)):[...t,e]:[])},w=(e,t,n)=>{const r=n>o.length-1;n<0||r||i((e=>{const r=[...e],[a]=r.splice(t,1);return r.splice(n,0,a),r}))};return(0,r.useEffect)((()=>{n&&h.length&&!h.includes(n)&&a("")}),[h,n]),Nt("div",{className:"vm-explore-metrics",children:[Nt(rp,{jobs:c,instances:h,names:f,job:e,size:l.id,instance:n,selectedMetrics:o,onChangeJob:t,onChangeSize:e=>{const t=st.find((t=>t.id===e));t&&s(t)},onChangeInstance:a,onToggleMetric:b}),y&&Nt(bl,{}),_&&Nt(Yr,{variant:"error",children:_}),!e&&Nt(Yr,{variant:"info",children:"Please select job to see list of metric names."}),e&&!o.length&&Nt(Yr,{variant:"info",children:"Please select metric names to see the graphs."}),Nt("div",{className:"vm-explore-metrics-body",children:o.map(((t,r)=>Nt(Xm,{name:t,job:e,instance:n,index:r,length:o.length,size:l,onRemoveItem:b,onChangeOrder:w},t)))})]})},up=()=>{const t=pl();return Nt("div",{className:"vm-preview-icons",children:Object.entries(e).map((e=>{let[n,r]=e;return Nt("div",{className:"vm-preview-icons-item",onClick:(a=n,async()=>{await t("<".concat(a,"/>"),"<".concat(a,"/> has been copied"))}),children:[Nt("div",{className:"vm-preview-icons-item__svg",children:r()}),Nt("div",{className:"vm-preview-icons-item__name",children:"<".concat(n,"/>")})]},n);var a}))})};var dp=function(e){return e.copy="Copy",e.copied="Copied",e}(dp||{});const hp=e=>{let{code:t}=e;const[n,a]=(0,r.useState)(dp.copy);return(0,r.useEffect)((()=>{let e=null;return n===dp.copied&&(e=setTimeout((()=>a(dp.copy)),1e3)),()=>{e&&clearTimeout(e)}}),[n]),Nt("code",{className:"vm-code-example",children:[t,Nt("div",{className:"vm-code-example__copy",children:Nt(ha,{title:n,children:Nt(ta,{size:"small",variant:"text",onClick:()=>{navigator.clipboard.writeText(t),a(dp.copied)},startIcon:Nt(rr,{}),ariaLabel:"close"})})})]})},mp=()=>Nt("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/MetricsQL.html",target:"_blank",rel:"help noreferrer",children:"MetricsQL"}),pp=()=>Nt("a",{className:"vm-link vm-link_colored",href:"https://grafana.com/grafana/dashboards/1860-node-exporter-full/",target:"_blank",rel:"help noreferrer",children:"Node Exporter Full"}),fp=()=>Nt("section",{className:"vm-with-template-tutorial",children:[Nt("h2",{className:"vm-with-template-tutorial__title",children:["Tutorial for WITH expressions in ",Nt(mp,{})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Let's look at the following real query from ",Nt(pp,{})," dashboard:"]}),Nt(hp,{code:'(\n (\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n -\n node_memory_MemFree_bytes{instance=~"$node:$port", job=~"$job"}\n )\n /\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n) * 100'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"It is clear the query calculates the percentage of used memory for the given $node, $port and $job. Isn't it? :)"})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"What's wrong with this query? Copy-pasted label filters for distinct timeseries which makes it easy to mistype these filters during modification. Let's simplify the query with WITH expressions:"}),Nt(hp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n node_memory_MemTotal_bytes{commonFilters}\n -\n node_memory_MemFree_bytes{commonFilters}\n)\n /\nnode_memory_MemTotal_bytes{commonFilters} * 100'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Now label filters are located in a single place instead of three distinct places. The query mentions node_memory_MemTotal_bytes metric twice and ","{commonFilters}"," three times. WITH expressions may improve this:"]}),Nt(hp,{code:'WITH (\n my_resource_utilization(free, limit, filters) = (limit{filters} - free{filters}) / limit{filters} * 100\n)\nmy_resource_utilization(\n node_memory_MemFree_bytes,\n node_memory_MemTotal_bytes,\n {instance=~"$node:$port",job=~"$job"},\n)'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Now the template function my_resource_utilization() may be used for monitoring arbitrary resources - memory, CPU, network, storage, you name it."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Let's take another nice query from ",Nt(pp,{})," dashboard:"]}),Nt(hp,{code:'(\n (\n (\n count(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',instance=~"$node:$port",job=~"$job"}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n)'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Do you understand what does this mess do? Is it manageable? :) WITH expressions are happy to help in a few iterations."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"1. Extract common filters used in multiple places into a commonFilters variable:"}),Nt(hp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n (\n (\n count(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n)'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:'2. Extract "count(count(...) by (cpu))" into cpuCount variable:'}),Nt(hp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu))\n)\n(\n (\n cpuCount\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n) / cpuCount'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"3. Extract rate(...) part into cpuIdle variable, since it is clear now that this part calculates the number of idle CPUs:"}),Nt(hp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu)),\n cpuIdle = sum(rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["4. Put node_cpu_seconds_total","{commonFilters}"," into its own varialbe with the name cpuSeconds:"]}),Nt(hp,{code:'WITH (\n cpuSeconds = node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(cpuSeconds) by (cpu)),\n cpuIdle = sum(rate(cpuSeconds{mode=\'idle\'}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Now the query became more clear comparing to the initial query."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"WITH expressions may be nested and may be put anywhere. Try expanding the following query:"}),Nt(hp,{code:"WITH (\n f(a, b) = WITH (\n f1(x) = b-x,\n f2(x) = x+x\n ) f1(a)*f2(b)\n) f(foo, with(x=bar) x)"})]})]}),vp=()=>{const{serverUrl:e}=Mt(),[t,n]=He(),[a,o]=(0,r.useState)(""),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)();return{data:a,error:s,loading:i,expand:async r=>{t.set("expr",r),n(t);const a=((e,t)=>"".concat(e,"/expand-with-exprs?query=").concat(encodeURIComponent(t),"&format=json"))(e,r);l(!0);try{const e=await fetch(a),t=await e.json();o((null===t||void 0===t?void 0:t.expr)||""),c(String(t.error||""))}catch(Tp){Tp instanceof Error&&"AbortError"!==Tp.name&&c("".concat(Tp.name,": ").concat(Tp.message))}l(!1)}}},gp=()=>{const[e]=He(),{data:t,loading:n,error:a,expand:o}=vp(),[i,l]=(0,r.useState)(e.get("expr")||""),s=()=>{o(i)};return(0,r.useEffect)((()=>{i&&o(i)}),[]),Nt("section",{className:"vm-with-template",children:[n&&Nt(bl,{}),Nt("div",{className:"vm-with-template-body vm-block",children:[Nt("div",{className:"vm-with-template-body__expr",children:Nt(Ha,{type:"textarea",label:"MetricsQL query with optional WITH expressions",value:i,error:a,autofocus:!0,onEnter:s,onChange:e=>{l(e)}})}),Nt("div",{className:"vm-with-template-body__result",children:Nt(Ha,{type:"textarea",label:"MetricsQL query after expanding WITH expressions and applying other optimizations",value:t,disabled:!0})}),Nt("div",{className:"vm-with-template-body-top",children:Nt(ta,{variant:"contained",onClick:s,startIcon:Nt(qn,{}),children:"Expand"})})]}),Nt("div",{className:"vm-block",children:Nt(fp,{})})]})},yp=()=>{const{serverUrl:e}=Mt(),[t,n]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1),[i,l]=(0,r.useState)();return{data:t,error:i,loading:a,fetchData:async(t,r)=>{const a=((e,t,n)=>{const r=["format=json","relabel_configs=".concat(encodeURIComponent(t)),"metric=".concat(encodeURIComponent(n))];return"".concat(e,"/metric-relabel-debug?").concat(r.join("&"))})(e,t,r);o(!0);try{const e=await fetch(a),t=await e.json();n(t.error?null:t),l(String(t.error||""))}catch(Tp){Tp instanceof Error&&"AbortError"!==Tp.name&&l("".concat(Tp.name,": ").concat(Tp.message))}o(!1)}}},_p={config:'- if: \'{bar_label=~"b.*"}\'\n source_labels: [foo_label, bar_label]\n separator: "_"\n target_label: foobar\n- action: labeldrop\n regex: "foo_.*"\n- target_label: job\n replacement: "my-application-2"',labels:'{__name__="my_metric", bar_label="bar", foo_label="foo", job="my-application", instance="192.168.0.1"}'},bp=()=>{const[e,t]=He(),{data:n,loading:a,error:o,fetchData:i}=yp(),[l,s]=ym("","config"),[c,u]=ym("","labels"),d=(0,r.useCallback)((()=>{i(l,c),e.set("config",l),e.set("labels",c),t(e)}),[l,c]);return(0,r.useEffect)((()=>{const t=e.get("config")||"",n=e.get("labels")||"";(n||t)&&(i(t,n),s(t),u(n))}),[]),Nt("section",{className:"vm-relabeling",children:[a&&Nt(bl,{}),Nt("div",{className:"vm-relabeling-header vm-block",children:[Nt("div",{className:"vm-relabeling-header-configs",children:Nt(Ha,{type:"textarea",label:"Relabel configs",value:l,autofocus:!0,onChange:e=>{s(e||"")},onEnter:d})}),Nt("div",{className:"vm-relabeling-header__labels",children:Nt(Ha,{type:"textarea",label:"Labels",value:c,onChange:e=>{u(e||"")},onEnter:d})}),Nt("div",{className:"vm-relabeling-header-bottom",children:[Nt("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/relabeling.html",rel:"help noreferrer",children:[Nt(On,{}),"Relabeling cookbook"]}),Nt("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/vmagent.html#relabeling",rel:"help noreferrer",children:[Nt(ir,{}),"Documentation"]}),Nt(ta,{variant:"text",onClick:()=>{const{config:n,labels:r}=_p;s(n),u(r),i(n,r),e.set("config",n),e.set("labels",r),t(e)},children:"Try example"}),Nt(ta,{variant:"contained",onClick:d,startIcon:Nt(qn,{}),children:"Submit"})]})]}),o&&Nt(Yr,{variant:"error",children:o}),n&&Nt("div",{className:"vm-relabeling-steps vm-block",children:[n.originalLabels&&Nt("div",{className:"vm-relabeling-steps-item",children:Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Original labels:"}),Nt("code",{dangerouslySetInnerHTML:{__html:n.originalLabels}})]})}),n.steps.map(((e,t)=>Nt("div",{className:"vm-relabeling-steps-item",children:[Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Step:"}),t+1]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Relabeling Rule:"}),Nt("code",{children:Nt("pre",{children:e.rule})})]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Input Labels:"}),Nt("code",{children:Nt("pre",{dangerouslySetInnerHTML:{__html:e.inLabels}})})]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Output labels:"}),Nt("code",{children:Nt("pre",{dangerouslySetInnerHTML:{__html:e.outLabels}})})]})]},t))),n.resultingLabels&&Nt("div",{className:"vm-relabeling-steps-item",children:Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Resulting labels:"}),Nt("code",{dangerouslySetInnerHTML:{__html:n.resultingLabels}})]})})]})]})},wp=e=>{let{rows:t,columns:n,defaultOrderBy:a,copyToClipboard:o,paginationOffset:i}=e;const[l,s]=(0,r.useState)(a),[c,u]=(0,r.useState)("desc"),[d,h]=(0,r.useState)(null),m=(0,r.useMemo)((()=>{const{startIndex:e,endIndex:n}=i;return Sm(t,xm(c,l)).slice(e,n)}),[t,l,c,i]),p=(e,t)=>async()=>{if(d!==t)try{await navigator.clipboard.writeText(String(e)),h(t)}catch(Tp){console.error(Tp)}};return(0,r.useEffect)((()=>{if(null===d)return;const e=setTimeout((()=>h(null)),2e3);return()=>clearTimeout(e)}),[d]),Nt("table",{className:"vm-table",children:[Nt("thead",{className:"vm-table-header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>{return Nt("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:(t=e.key,()=>{u((e=>"asc"===e&&l===t?"desc":"asc")),s(t)}),children:Nt("div",{className:"vm-table-cell__content",children:[Nt("div",{children:String(e.title||e.key)}),Nt("div",{className:kr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":l===e.key,"vm-table__sort-icon_desc":"desc"===c&&l===e.key}),children:Nt(Hn,{})})]})},String(e.key));var t})),o&&Nt("th",{className:"vm-table-cell vm-table-cell_header"})]})}),Nt("tbody",{className:"vm-table-body",children:m.map(((e,t)=>Nt("tr",{className:"vm-table__row",children:[n.map((t=>Nt("td",{className:kr()({"vm-table-cell":!0,["".concat(t.className)]:t.className}),children:e[t.key]||"-"},String(t.key)))),o&&Nt("td",{className:"vm-table-cell vm-table-cell_right",children:e[o]&&Nt("div",{className:"vm-table-cell__content",children:Nt(ha,{title:d===t?"Copied":"Copy row",children:Nt(ta,{variant:"text",color:d===t?"success":"gray",size:"small",startIcon:Nt(d===t?Xn:rr,{}),onClick:p(e[o],t),ariaLabel:"copy row"})})})})]},t)))})]})},kp=()=>{const{isMobile:e}=Br(),{timezone:t}=fn(),{data:n,lastUpdated:a,isLoading:i,error:l,fetchData:s}=(()=>{const{serverUrl:e}=Mt(),[t,n]=(0,r.useState)([]),[a,i]=(0,r.useState)(o()().format(Ot)),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>"".concat(e,"/api/v1/status/active_queries")),[e]),h=async()=>{s(!0);try{const e=await fetch(d),t=await e.json();n(t.data),i(o()().format("HH:mm:ss:SSS")),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Tp){Tp instanceof Error&&u("".concat(Tp.name,": ").concat(Tp.message))}s(!1)};return(0,r.useEffect)((()=>{h().catch(console.error)}),[d]),{data:t,lastUpdated:a,isLoading:l,error:c,fetchData:h}})(),c=(0,r.useMemo)((()=>n.map((e=>{const t=o()(e.start).tz().format(Pt),n=o()(e.end).tz().format(Pt);return{duration:e.duration,remote_addr:e.remote_addr,query:e.query,args:"".concat(t," to ").concat(n,", step=").concat(Wt(e.step)),data:JSON.stringify(e,null,2)}}))),[n,t]),u=(0,r.useMemo)((()=>{if(null===c||void 0===c||!c.length)return[];const e=Object.keys(c[0]),t={remote_addr:"client address"},n=["data"];return e.filter((e=>!n.includes(e))).map((e=>({key:e,title:t[e]||e})))}),[c]);return Nt("div",{className:"vm-active-queries",children:[i&&Nt(bl,{}),Nt("div",{className:"vm-active-queries-header",children:[!c.length&&!l&&Nt(Yr,{variant:"info",children:"There are currently no active queries running"}),l&&Nt(Yr,{variant:"error",children:l}),Nt("div",{className:"vm-active-queries-header-controls",children:[Nt(ta,{variant:"contained",onClick:async()=>{s().catch(console.error)},startIcon:Nt(Fn,{}),children:"Update"}),Nt("div",{className:"vm-active-queries-header__update-msg",children:["Last updated: ",a]})]})]}),!!c.length&&Nt("div",{className:kr()({"vm-block":!0,"vm-block_mobile":e}),children:Nt(wp,{rows:c,columns:u,defaultOrderBy:"duration",copyToClipboard:"data",paginationOffset:{startIndex:0,endIndex:1/0}})})]})},xp=e=>{let{onClose:t,onUpload:n}=e;const{isMobile:a}=Br(),[o,i]=(0,r.useState)(""),[l,s]=(0,r.useState)(""),c=(0,r.useMemo)((()=>{try{return JSON.parse(o),""}catch(Tp){return Tp instanceof Error?Tp.message:"Unknown error"}}),[o]),u=()=>{s(c),c||(n(o),t())};return Nt("div",{className:kr()({"vm-json-form vm-json-form_one-field":!0,"vm-json-form_mobile vm-json-form_one-field_mobile":a}),children:[Nt(Ha,{value:o,label:"JSON",type:"textarea",error:l,autofocus:!0,onChange:e=>{s(""),i(e)},onEnter:u}),Nt("div",{className:"vm-json-form-footer",children:Nt("div",{className:"vm-json-form-footer__controls vm-json-form-footer__controls_right",children:[Nt(ta,{variant:"outlined",color:"error",onClick:t,children:"Cancel"}),Nt(ta,{variant:"contained",onClick:u,children:"apply"})]})})]})},Sp=e=>{let{data:t,period:n}=e;const{isMobile:a}=Br(),{tableCompact:o}=Rr(),i=Dr(),[l,s]=(0,r.useState)([]),[c,u]=(0,r.useState)(),[d,h]=(0,r.useState)(),[m,p]=(0,r.useState)(!1),[f,v]=(0,r.useState)([]),[g,y]=(0,r.useState)(),_=(0,r.useMemo)((()=>qh(d||[]).map((e=>e.key))),[d]),b=(0,r.useMemo)((()=>{const e=t.some((e=>"matrix"===e.data.resultType));return t.some((e=>"vector"===e.data.resultType))&&e?Ar:e?Ar.filter((e=>"chart"===e.value)):Ar.filter((e=>"chart"!==e.value))}),[t]),[w,k]=(0,r.useState)(b[0].value),{yaxis:x,spanGaps:S}=Hr(),C=Vr(),E=e=>{C({type:"SET_YAXIS_LIMITS",payload:e})};return(0,r.useEffect)((()=>{const e="chart"===w?"matrix":"vector",n=t.filter((t=>t.data.resultType===e&&t.trace)).map((e=>{var t,n;return e.trace?new Sl(e.trace,(null===e||void 0===e||null===(t=e.vmui)||void 0===t||null===(n=t.params)||void 0===n?void 0:n.query)||"Query"):null}));s(n.filter(Boolean))}),[t,w]),(0,r.useEffect)((()=>{const e=[],n=[],r=[];t.forEach(((t,a)=>{const o=t.data.result.map((e=>{var n,r,o;return{...e,group:Number(null!==(n=null===(r=t.vmui)||void 0===r||null===(o=r.params)||void 0===o?void 0:o.id)&&void 0!==n?n:a)+1}}));var i,l;"matrix"===t.data.resultType?(n.push(...o),e.push((null===(i=t.vmui)||void 0===i||null===(l=i.params)||void 0===l?void 0:l.query)||"Query")):r.push(...o)})),v(e),u(n),h(r)}),[t]),(0,r.useEffect)((()=>{p(!!c&&Nl(c))}),[c]),Nt("div",{className:kr()({"vm-query-analyzer-view":!0,"vm-query-analyzer-view_mobile":a}),children:[!!l.length&&Nt(jl,{traces:l,onDeleteClick:e=>{s((t=>t.filter((t=>t.idValue!==e.idValue))))}}),Nt("div",{className:kr()({"vm-block":!0,"vm-block_mobile":a}),children:[Nt("div",{className:"vm-custom-panel-body-header",children:[Nt("div",{className:"vm-custom-panel-body-header__tabs",children:Nt(Nr,{activeItem:w,items:b,onChange:e=>{k(e)}})}),Nt("div",{className:"vm-custom-panel-body-header__graph-controls",children:["chart"===w&&Nt(ga,{}),"chart"===w&&Nt($h,{yaxis:x,setYaxisLimits:E,toggleEnableLimits:()=>{C({type:"TOGGLE_ENABLE_YAXIS_LIMITS"})},spanGaps:{value:S,onChange:e=>{C({type:"SET_SPAN_GAPS",payload:e})}}}),"table"===w&&Nt(Zh,{columns:_,defaultColumns:g,onChangeColumns:y,tableCompact:o,toggleTableCompact:()=>{i({type:"TOGGLE_TABLE_COMPACT"})}})]})]}),c&&n&&"chart"===w&&Nt(Fh,{data:c,period:n,customStep:n.step||"1s",query:f,yaxis:x,setYaxisLimits:E,setPeriod:()=>null,height:a?.5*window.innerHeight:500,isHistogram:m,spanGaps:S}),d&&"code"===w&&Nt(Bh,{data:d}),d&&"table"===w&&Nt(Wh,{data:d,displayColumns:g})]})]})},Cp=e=>{var t,n;let{data:a,period:i}=e;const l=(0,r.useMemo)((()=>a.filter((e=>e.stats&&"matrix"===e.data.resultType))),[a]),s=(0,r.useMemo)((()=>{var e,t;return null===(e=a.find((e=>{var t;return null===e||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment})))||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment}),[a]),c=(0,r.useMemo)((()=>{if(!i)return"";const e=o()(1e3*i.start).tz().format(Pt),t=o()(1e3*i.end).tz().format(Pt);return"".concat(e," - ").concat(t)}),[i]),{value:u,setTrue:d,setFalse:h}=ra(!1);return Nt(Ct.FK,{children:[Nt("div",{className:"vm-query-analyzer-info-header",children:[Nt(ta,{startIcon:Nt(On,{}),variant:"outlined",color:"warning",onClick:d,children:"Show report info"}),i&&Nt(Ct.FK,{children:[Nt("div",{className:"vm-query-analyzer-info-header__period",children:[Nt(or,{})," step: ",i.step]}),Nt("div",{className:"vm-query-analyzer-info-header__period",children:[Nt(Vn,{})," ",c]})]})]}),u&&Nt(da,{title:"Report info",onClose:h,children:Nt("div",{className:"vm-query-analyzer-info",children:[s&&Nt("div",{className:"vm-query-analyzer-info-item vm-query-analyzer-info-item_comment",children:[Nt("div",{className:"vm-query-analyzer-info-item__title",children:"Comment:"}),Nt("div",{className:"vm-query-analyzer-info-item__text",children:s})]}),l.map(((e,t)=>{var n;return Nt("div",{className:"vm-query-analyzer-info-item",children:[Nt("div",{className:"vm-query-analyzer-info-item__title",children:l.length>1?"Query ".concat(t+1,":"):"Stats:"}),Nt("div",{className:"vm-query-analyzer-info-item__text",children:[Object.entries(e.stats||{}).map((e=>{let[t,n]=e;return Nt("div",{children:[t,": ",null!==n&&void 0!==n?n:"-"]},t)})),"isPartial: ",String(null!==(n=e.isPartial)&&void 0!==n?n:"-")]})]},t)})),Nt("div",{className:"vm-query-analyzer-info-type",children:null!==(t=l[0])&&void 0!==t&&null!==(n=t.vmui)&&void 0!==n&&n.params?"The report was created using vmui":"The report was created manually"})]})})]})},Ep=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(""),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=ra(!1),c=(0,r.useMemo)((()=>{var t,n;if(!e)return;const r=null===(t=e[0])||void 0===t||null===(n=t.vmui)||void 0===n?void 0:n.params,a={start:+((null===r||void 0===r?void 0:r.start)||0),end:+((null===r||void 0===r?void 0:r.end)||0),step:null===r||void 0===r?void 0:r.step,date:""};if(!r){const t=e.filter((e=>"matrix"===e.data.resultType)).map((e=>e.data.result)).flat().map((e=>{var t;return e.values?null===(t=e.values)||void 0===t?void 0:t.map((e=>e[0])):[0]})).flat(),n=Array.from(new Set(t.filter(Boolean))).sort(((e,t)=>e-t));a.start=n[0],a.end=n[n.length-1],a.step=Yt((e=>{const t=e.slice(1).map(((t,n)=>t-e[n])),n={};t.forEach((e=>{const t=e.toString();n[t]=(n[t]||0)+1}));let r=0,a=0;for(const o in n)n[o]>a&&(a=n[o],r=Number(o));return r})(n))}return a.date=Jt(tn(a.end)),a}),[e]),u=e=>{try{const n=JSON.parse(e),r=Array.isArray(n)?n:[n];(e=>e.every((e=>{if("object"===typeof e&&null!==e){const t=e.data;if("object"===typeof t&&null!==t){const e=t.result,n=t.resultType;return Array.isArray(e)&&"string"===typeof n}}return!1})))(r)?t(r):a("Invalid structure - JSON does not match the expected format")}catch(Tp){Tp instanceof Error&&a("".concat(Tp.name,": ").concat(Tp.message))}},d=e=>{e.map((e=>{const t=new FileReader;t.onload=e=>{var t;const n=String(null===(t=e.target)||void 0===t?void 0:t.result);u(n)},t.readAsText(e)}))},h=e=>{a("");const t=Array.from(e.target.files||[]);d(t),e.target.value=""},{files:m,dragging:p}=Ym();return(0,r.useEffect)((()=>{d(m)}),[m]),Nt("div",{className:"vm-trace-page",children:[o&&Nt("div",{className:"vm-trace-page-header",children:[Nt("div",{className:"vm-trace-page-header-errors",children:Nt(Cp,{data:e,period:c})}),Nt("div",{children:Nt(Wm,{onOpenModal:l,onChange:h})})]}),n&&Nt("div",{className:"vm-trace-page-header-errors-item vm-trace-page-header-errors-item_margin-bottom",children:[Nt(Yr,{variant:"error",children:n}),Nt(ta,{className:"vm-trace-page-header-errors-item__close",startIcon:Nt(In,{}),variant:"text",color:"error",onClick:()=>{a("")}})]}),o&&Nt(Sp,{data:e,period:c}),!o&&Nt("div",{className:"vm-trace-page-preview",children:[Nt("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain query information in JSON format.","\n","Graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Nt(Wm,{onOpenModal:l,onChange:h})]}),i&&Nt(da,{title:"Paste JSON",onClose:s,children:Nt(xp,{onClose:s,onUpload:u})}),p&&Nt("div",{className:"vm-trace-page__dropzone"})]})},Np=()=>{const[e,t]=(0,r.useState)(!1);return Nt(Ct.FK,{children:Nt(Ie,{children:Nt(Jr,{children:Nt(Ct.FK,{children:[Nt(qm,{onLoaded:t}),e&&Nt(xe,{children:Nt(we,{path:"/",element:Nt(To,{}),children:[Nt(we,{path:We.home,element:Nt(nm,{})}),Nt(we,{path:We.metrics,element:Nt(cp,{})}),Nt(we,{path:We.cardinality,element:Nt(Om,{})}),Nt(we,{path:We.topQueries,element:Nt(Hm,{})}),Nt(we,{path:We.trace,element:Nt(Km,{})}),Nt(we,{path:We.queryAnalyzer,element:Nt(Ep,{})}),Nt(we,{path:We.dashboards,element:Nt(im,{})}),Nt(we,{path:We.withTemplate,element:Nt(gp,{})}),Nt(we,{path:We.relabel,element:Nt(bp,{})}),Nt(we,{path:We.activeQueries,element:Nt(kp,{})}),Nt(we,{path:We.icons,element:Nt(up,{})})]})})]})})})})},Ap=e=>{e&&n.e(685).then(n.bind(n,685)).then((t=>{let{getCLS:n,getFID:r,getFCP:a,getLCP:o,getTTFB:i}=t;n(e),r(e),a(e),o(e),i(e)}))},Mp=document.getElementById("root");Mp&&(0,r.render)(Nt(Np,{}),Mp),Ap()})()})(); \ No newline at end of file diff --git a/app/vmselect/vmui/static/js/main.4b213512.js.LICENSE.txt b/app/vmselect/vmui/static/js/main.ff023df1.js.LICENSE.txt similarity index 89% rename from app/vmselect/vmui/static/js/main.4b213512.js.LICENSE.txt rename to app/vmselect/vmui/static/js/main.ff023df1.js.LICENSE.txt index db76a5f622..665580a084 100644 --- a/app/vmselect/vmui/static/js/main.4b213512.js.LICENSE.txt +++ b/app/vmselect/vmui/static/js/main.ff023df1.js.LICENSE.txt @@ -5,7 +5,7 @@ */ /** - * @remix-run/router v1.15.1 + * @remix-run/router v1.17.0 * * Copyright (c) Remix Software Inc. * @@ -16,7 +16,7 @@ */ /** - * React Router DOM v6.22.1 + * React Router DOM v6.24.0 * * Copyright (c) Remix Software Inc. * @@ -27,7 +27,7 @@ */ /** - * React Router v6.22.1 + * React Router v6.24.0 * * Copyright (c) Remix Software Inc. * diff --git a/app/vmselect/vmui/static/media/MetricsQL.aaabf95f2c9bf356bde4.md b/app/vmselect/vmui/static/media/MetricsQL.3de5efa763ef6e05a579.md similarity index 95% rename from app/vmselect/vmui/static/media/MetricsQL.aaabf95f2c9bf356bde4.md rename to app/vmselect/vmui/static/media/MetricsQL.3de5efa763ef6e05a579.md index d49ccfb6e9..ba795cefe1 100644 --- a/app/vmselect/vmui/static/media/MetricsQL.aaabf95f2c9bf356bde4.md +++ b/app/vmselect/vmui/static/media/MetricsQL.3de5efa763ef6e05a579.md @@ -220,9 +220,11 @@ See also [descent_over_time](#descent_over_time). over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [median_over_time](#median_over_time). +See also [median_over_time](#median_over_time), [min_over_time](#min_over_time) and [max_over_time](#max_over_time). #### changes @@ -262,6 +264,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time), [share_eq_over_time](#share_eq_over_time) and [count_values_over_time](#count_values_over_time). #### count_gt_over_time @@ -272,6 +276,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time) and [share_gt_over_time](#share_gt_over_time). #### count_le_over_time @@ -282,6 +288,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time) and [share_le_over_time](#share_le_over_time). #### count_ne_over_time @@ -292,7 +300,9 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. -See also [count_over_time](#count_over_time). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + +See also [count_over_time](#count_over_time) and [count_eq_over_time](#count_eq_over_time). #### count_over_time @@ -313,6 +323,8 @@ The results are calculated independently per each time series returned from the Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_eq_over_time](#count_eq_over_time), [count_values](#count_values) and [distinct_over_time](#distinct_over_time) and [label_match](#label_match). #### decreases_over_time @@ -432,6 +444,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### histogram_over_time `histogram_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates @@ -443,11 +457,15 @@ For example, the following query calculates median temperature by country over t `histogram_quantile(0.5, sum(histogram_over_time(temperature[24h])) by (vmrange,country))`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### hoeffding_bound_lower `hoeffding_bound_lower(phi, series_selector[d])` is a [rollup function](#rollup-functions), which calculates lower [Hoeffding bound](https://en.wikipedia.org/wiki/Hoeffding%27s_inequality) for the given `phi` in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [hoeffding_bound_upper](#hoeffding_bound_upper). #### hoeffding_bound_upper @@ -455,6 +473,8 @@ See also [hoeffding_bound_upper](#hoeffding_bound_upper). `hoeffding_bound_upper(phi, series_selector[d])` is a [rollup function](#rollup-functions), which calculates upper [Hoeffding bound](https://en.wikipedia.org/wiki/Hoeffding%27s_inequality) for the given `phi` in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [hoeffding_bound_lower](#hoeffding_bound_lower). #### holt_winters @@ -462,8 +482,9 @@ See also [hoeffding_bound_lower](#hoeffding_bound_lower). `holt_winters(series_selector[d], sf, tf)` is a [rollup function](#rollup-functions), which calculates Holt-Winters value (aka [double exponential smoothing](https://en.wikipedia.org/wiki/Exponential_smoothing#Double_exponential_smoothing)) for [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) over the given lookbehind window `d` using the given smoothing factor `sf` and the given trend factor `tf`. -Both `sf` and `tf` must be in the range `[0...1]`. It is expected that the [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering) -returns time series of [gauge type](https://docs.victoriametrics.com/keyconcepts/#gauge). +Both `sf` and `tf` must be in the range `[0...1]`. + +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). This function is supported by PromQL. @@ -495,13 +516,14 @@ See also [deriv](#deriv). `increase(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the increase over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Unlike Prometheus, it takes into account the last sample before the given lookbehind window `d` when calculating the result. See [this article](https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e) for details. Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. See also [increase_pure](#increase_pure), [increase_prometheus](#increase_prometheus) and [delta](#delta). @@ -510,12 +532,13 @@ See also [increase_pure](#increase_pure), [increase_prometheus](#increase_promet `increase_prometheus(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the increase over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). It doesn't take into account the last sample before the given lookbehind window `d` when calculating the result in the same way as Prometheus does. See [this article](https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e) for details. Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + See also [increase_pure](#increase_pure) and [increase](#increase). #### increase_pure @@ -524,6 +547,10 @@ See also [increase_pure](#increase_pure) and [increase](#increase). of the following corner case - it assumes that [counters](https://docs.victoriametrics.com/keyconcepts/#counter) always start from 0, while [increase](#increase) ignores the first value in a series if it is too big. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [increase](#increas) and [increase_prometheus](#increase_prometheus). + #### increases_over_time `increases_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the number of [raw sample](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -540,15 +567,18 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### irate `irate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the "instant" per-second increase rate over the last two [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. See also [rate](#rate) and [rollup_rate](#rollup_rate). @@ -587,6 +617,8 @@ See also [duration_over_time](#duration_over_time) and [lag](#lag). over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [mad](#mad), [range_mad](#range_mad) and [outlier_iqr_over_time](#outlier_iqr_over_time). #### max_over_time @@ -594,9 +626,11 @@ See also [mad](#mad), [range_mad](#range_mad) and [outlier_iqr_over_time](#outli `max_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the maximum value over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [tmax_over_time](#tmax_over_time). +See also [tmax_over_time](#tmax_over_time) and [min_over_time](#min_over_time). #### median_over_time @@ -604,6 +638,8 @@ See also [tmax_over_time](#tmax_over_time). on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [avg_over_time](#avg_over_time). #### min_over_time @@ -611,9 +647,11 @@ See also [avg_over_time](#avg_over_time). `min_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the minimum value over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [tmin_over_time](#tmin_over_time). +See also [tmin_over_time](#tmin_over_time) and [max_over_time](#max_over_time). #### mode_over_time @@ -622,6 +660,8 @@ for [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). It is expected that [raw sample](https://docs.victoriametrics.com/keyconcepts/#raw-samples) values are discrete. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### outlier_iqr_over_time `outlier_iqr_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which returns the last sample on the given lookbehind window `d` @@ -632,6 +672,8 @@ if its value is either smaller than the `q25-1.5*iqr` or bigger than `q75+1.5*iq The `outlier_iqr_over_time()` is useful for detecting anomalies in gauge values based on the previous history of values. For example, `outlier_iqr_over_time(memory_usage_bytes[1h])` triggers when `memory_usage_bytes` suddenly goes outside the usual value range for the last hour. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [outliers_iqr](#outliers_iqr). #### predict_linear @@ -659,6 +701,8 @@ This function is supported by PromQL. on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). The `phi` value must be in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [quantiles_over_time](#quantiles_over_time). @@ -670,6 +714,8 @@ over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). The function returns individual series per each `phi*` with `{phiLabel="phi*"}` label. `phi*` values must be in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [quantile_over_time](#quantile_over_time). #### range_over_time @@ -680,11 +726,12 @@ E.g. it calculates `max_over_time(series_selector[d]) - min_over_time(series_sel Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### rate `rate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the average per-second increase rate over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). If the lookbehind window is skipped in square brackets, then it is automatically calculated as `max(step, scrape_interval)`, where `step` is the query arg value passed to [/api/v1/query_range](https://docs.victoriametrics.com/keyconcepts/#range-query) or [/api/v1/query](https://docs.victoriametrics.com/keyconcepts/#instant-query), @@ -703,6 +750,8 @@ See also [irate](#irate) and [rollup_rate](#rollup_rate). on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. #### resets @@ -710,10 +759,11 @@ Metric names are stripped from the resulting rollups. Add [keep_metric_names](#k `resets(series_selector[d])` is a [rollup function](#rollup-functions), which returns the number of [counter](https://docs.victoriametrics.com/keyconcepts/#counter) resets over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. #### rollup @@ -725,6 +775,10 @@ These values are calculated individually per each time series returned from the Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + +See also [rollup_rate](#rollup_rate). + #### rollup_candlestick `rollup_candlestick(series_selector[d])` is a [rollup function](#rollup-functions), which calculates `open`, `high`, `low` and `close` values (aka OHLC) @@ -736,6 +790,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Optional 2nd argument `"open"`, `"high"` or `"low"` or `"close"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### rollup_delta `rollup_delta(series_selector[d])` is a [rollup function](#rollup-functions), which calculates differences between adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -762,6 +818,8 @@ See also [label_match](#label_match). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +See also [rollup](#rollup) and [rollup_rate](#rollup_rate). + #### rollup_increase `rollup_increase(series_selector[d])` is a [rollup function](#rollup-functions), which calculates increases for adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -774,12 +832,17 @@ See also [label_match](#label_match). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. See also [rollup_delta](#rollup_delta). +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [rollup](#rollup) and [rollup_rate](#rollup_rate). + #### rollup_rate `rollup_rate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates per-second change rates for adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated per-second change rates and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. +The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). See [this article](https://valyala.medium.com/why-irate-from-prometheus-doesnt-capture-spikes-45f9896d7832) in order to understand better when to use `rollup_rate()`. @@ -787,10 +850,12 @@ when to use `rollup_rate()`. Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). -The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). - Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [rollup](#rollup) and [rollup_increase](#rollup_increase). + #### rollup_scrape_interval `rollup_scrape_interval(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the interval in seconds between @@ -824,6 +889,8 @@ This function is useful for calculating SLI and SLO. Example: `share_gt_over_tim Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [share_le_over_time](#share_le_over_time) and [count_gt_over_time](#count_gt_over_time). #### share_le_over_time @@ -838,6 +905,8 @@ the share of time series values for the last 24 hours when memory usage was belo Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [share_gt_over_time](#share_gt_over_time) and [count_le_over_time](#count_le_over_time). #### share_eq_over_time @@ -849,6 +918,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_eq_over_time](#count_eq_over_time). #### stale_samples_over_time @@ -866,6 +937,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [stdvar_over_time](#stdvar_over_time). @@ -877,6 +950,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [stddev_over_time](#stddev_over_time). @@ -888,6 +963,8 @@ values equal to `eq` on the given lookbehind window `d` per each time series ret Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_eq_over_time](#count_eq_over_time). #### sum_gt_over_time @@ -897,6 +974,8 @@ values bigger than `gt` on the given lookbehind window `d` per each time series Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_gt_over_time](#count_gt_over_time). #### sum_le_over_time @@ -906,6 +985,8 @@ values smaller or equal to `le` on the given lookbehind window `d` per each time Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_le_over_time](#count_le_over_time). #### sum_over_time @@ -915,6 +996,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. #### sum2_over_time @@ -924,6 +1007,8 @@ values on the given lookbehind window `d` per each time series returned from the Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### timestamp `timestamp(series_selector[d])` is a [rollup function](#rollup-functions), which returns the timestamp in seconds with millisecond precision @@ -1001,6 +1086,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [zscore](#zscore), [range_trim_zscore](#range_trim_zscore) and [outlier_iqr_over_time](#outlier_iqr_over_time). @@ -2230,7 +2317,8 @@ Any [rollup function](#rollup-functions) for something other than [series select Nested rollup functions can be implicit thanks to the [implicit query conversions](#implicit-query-conversions). For example, `delta(sum(m))` is implicitly converted to `delta(sum(default_rollup(m))[1i:1i])`, so it becomes a subquery, since it contains [default_rollup](#default_rollup) nested into [delta](#delta). -This behavior can be disabled or logged via cmd-line flags `-search.disableImplicitConversion` and `-search.logImplicitConversion` since v1.101.0. +This behavior can be disabled or logged via `-search.disableImplicitConversion` and `-search.logImplicitConversion` command-line flags +starting from [`v1.101.0` release](https://docs.victoriametrics.com/changelog/). VictoriaMetrics performs subqueries in the following way: @@ -2263,5 +2351,6 @@ VictoriaMetrics performs the following implicit conversions for incoming queries For example, `avg_over_time(rate(http_requests_total[5m])[1h])` is automatically converted to `avg_over_time(rate(http_requests_total[5m])[1h:1i])`. * If something other than [series selector](https://docs.victoriametrics.com/keyconcepts/#filtering) is passed to [rollup function](#rollup-functions), then a [subquery](#subqueries) with `1i` lookbehind window and `1i` step is automatically formed. - For example, `rate(sum(up))` is automatically converted to `rate((sum(default_rollup(up)))[1i:1i])`. - This behavior can be disabled or logged via cmd-line flags `-search.disableImplicitConversion` and `-search.logImplicitConversion` since v1.101.0. + For example, `rate(sum(up))` is automatically converted to `rate((sum(default_rollup(up)))[1i:1i])`. + This behavior can be disabled or logged via `-search.disableImplicitConversion` and `-search.logImplicitConversion` command-line flags + starting from [`v1.101.0` release](https://docs.victoriametrics.com/changelog/). diff --git a/app/vmui/packages/vmui/src/assets/MetricsQL.md b/app/vmui/packages/vmui/src/assets/MetricsQL.md index d49ccfb6e9..ba795cefe1 100644 --- a/app/vmui/packages/vmui/src/assets/MetricsQL.md +++ b/app/vmui/packages/vmui/src/assets/MetricsQL.md @@ -220,9 +220,11 @@ See also [descent_over_time](#descent_over_time). over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [median_over_time](#median_over_time). +See also [median_over_time](#median_over_time), [min_over_time](#min_over_time) and [max_over_time](#max_over_time). #### changes @@ -262,6 +264,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time), [share_eq_over_time](#share_eq_over_time) and [count_values_over_time](#count_values_over_time). #### count_gt_over_time @@ -272,6 +276,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time) and [share_gt_over_time](#share_gt_over_time). #### count_le_over_time @@ -282,6 +288,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_over_time](#count_over_time) and [share_le_over_time](#share_le_over_time). #### count_ne_over_time @@ -292,7 +300,9 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. -See also [count_over_time](#count_over_time). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + +See also [count_over_time](#count_over_time) and [count_eq_over_time](#count_eq_over_time). #### count_over_time @@ -313,6 +323,8 @@ The results are calculated independently per each time series returned from the Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_eq_over_time](#count_eq_over_time), [count_values](#count_values) and [distinct_over_time](#distinct_over_time) and [label_match](#label_match). #### decreases_over_time @@ -432,6 +444,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### histogram_over_time `histogram_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates @@ -443,11 +457,15 @@ For example, the following query calculates median temperature by country over t `histogram_quantile(0.5, sum(histogram_over_time(temperature[24h])) by (vmrange,country))`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### hoeffding_bound_lower `hoeffding_bound_lower(phi, series_selector[d])` is a [rollup function](#rollup-functions), which calculates lower [Hoeffding bound](https://en.wikipedia.org/wiki/Hoeffding%27s_inequality) for the given `phi` in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [hoeffding_bound_upper](#hoeffding_bound_upper). #### hoeffding_bound_upper @@ -455,6 +473,8 @@ See also [hoeffding_bound_upper](#hoeffding_bound_upper). `hoeffding_bound_upper(phi, series_selector[d])` is a [rollup function](#rollup-functions), which calculates upper [Hoeffding bound](https://en.wikipedia.org/wiki/Hoeffding%27s_inequality) for the given `phi` in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [hoeffding_bound_lower](#hoeffding_bound_lower). #### holt_winters @@ -462,8 +482,9 @@ See also [hoeffding_bound_lower](#hoeffding_bound_lower). `holt_winters(series_selector[d], sf, tf)` is a [rollup function](#rollup-functions), which calculates Holt-Winters value (aka [double exponential smoothing](https://en.wikipedia.org/wiki/Exponential_smoothing#Double_exponential_smoothing)) for [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) over the given lookbehind window `d` using the given smoothing factor `sf` and the given trend factor `tf`. -Both `sf` and `tf` must be in the range `[0...1]`. It is expected that the [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering) -returns time series of [gauge type](https://docs.victoriametrics.com/keyconcepts/#gauge). +Both `sf` and `tf` must be in the range `[0...1]`. + +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). This function is supported by PromQL. @@ -495,13 +516,14 @@ See also [deriv](#deriv). `increase(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the increase over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Unlike Prometheus, it takes into account the last sample before the given lookbehind window `d` when calculating the result. See [this article](https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e) for details. Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. See also [increase_pure](#increase_pure), [increase_prometheus](#increase_prometheus) and [delta](#delta). @@ -510,12 +532,13 @@ See also [increase_pure](#increase_pure), [increase_prometheus](#increase_promet `increase_prometheus(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the increase over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). It doesn't take into account the last sample before the given lookbehind window `d` when calculating the result in the same way as Prometheus does. See [this article](https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e) for details. Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + See also [increase_pure](#increase_pure) and [increase](#increase). #### increase_pure @@ -524,6 +547,10 @@ See also [increase_pure](#increase_pure) and [increase](#increase). of the following corner case - it assumes that [counters](https://docs.victoriametrics.com/keyconcepts/#counter) always start from 0, while [increase](#increase) ignores the first value in a series if it is too big. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [increase](#increas) and [increase_prometheus](#increase_prometheus). + #### increases_over_time `increases_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the number of [raw sample](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -540,15 +567,18 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### irate `irate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the "instant" per-second increase rate over the last two [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. See also [rate](#rate) and [rollup_rate](#rollup_rate). @@ -587,6 +617,8 @@ See also [duration_over_time](#duration_over_time) and [lag](#lag). over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [mad](#mad), [range_mad](#range_mad) and [outlier_iqr_over_time](#outlier_iqr_over_time). #### max_over_time @@ -594,9 +626,11 @@ See also [mad](#mad), [range_mad](#range_mad) and [outlier_iqr_over_time](#outli `max_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the maximum value over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [tmax_over_time](#tmax_over_time). +See also [tmax_over_time](#tmax_over_time) and [min_over_time](#min_over_time). #### median_over_time @@ -604,6 +638,8 @@ See also [tmax_over_time](#tmax_over_time). on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [avg_over_time](#avg_over_time). #### min_over_time @@ -611,9 +647,11 @@ See also [avg_over_time](#avg_over_time). `min_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the minimum value over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. -See also [tmin_over_time](#tmin_over_time). +See also [tmin_over_time](#tmin_over_time) and [max_over_time](#max_over_time). #### mode_over_time @@ -622,6 +660,8 @@ for [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). It is expected that [raw sample](https://docs.victoriametrics.com/keyconcepts/#raw-samples) values are discrete. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### outlier_iqr_over_time `outlier_iqr_over_time(series_selector[d])` is a [rollup function](#rollup-functions), which returns the last sample on the given lookbehind window `d` @@ -632,6 +672,8 @@ if its value is either smaller than the `q25-1.5*iqr` or bigger than `q75+1.5*iq The `outlier_iqr_over_time()` is useful for detecting anomalies in gauge values based on the previous history of values. For example, `outlier_iqr_over_time(memory_usage_bytes[1h])` triggers when `memory_usage_bytes` suddenly goes outside the usual value range for the last hour. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [outliers_iqr](#outliers_iqr). #### predict_linear @@ -659,6 +701,8 @@ This function is supported by PromQL. on the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). The `phi` value must be in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [quantiles_over_time](#quantiles_over_time). @@ -670,6 +714,8 @@ over [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). The function returns individual series per each `phi*` with `{phiLabel="phi*"}` label. `phi*` values must be in the range `[0...1]`. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [quantile_over_time](#quantile_over_time). #### range_over_time @@ -680,11 +726,12 @@ E.g. it calculates `max_over_time(series_selector[d]) - min_over_time(series_sel Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### rate `rate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the average per-second increase rate over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). If the lookbehind window is skipped in square brackets, then it is automatically calculated as `max(step, scrape_interval)`, where `step` is the query arg value passed to [/api/v1/query_range](https://docs.victoriametrics.com/keyconcepts/#range-query) or [/api/v1/query](https://docs.victoriametrics.com/keyconcepts/#instant-query), @@ -703,6 +750,8 @@ See also [irate](#irate) and [rollup_rate](#rollup_rate). on the given lookbehind window `d`. The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. #### resets @@ -710,10 +759,11 @@ Metric names are stripped from the resulting rollups. Add [keep_metric_names](#k `resets(series_selector[d])` is a [rollup function](#rollup-functions), which returns the number of [counter](https://docs.victoriametrics.com/keyconcepts/#counter) resets over the given lookbehind window `d` per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). -It is expected that the `series_selector` returns time series of [counter type](https://docs.victoriametrics.com/keyconcepts/#counter). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + This function is supported by PromQL. #### rollup @@ -725,6 +775,10 @@ These values are calculated individually per each time series returned from the Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + +See also [rollup_rate](#rollup_rate). + #### rollup_candlestick `rollup_candlestick(series_selector[d])` is a [rollup function](#rollup-functions), which calculates `open`, `high`, `low` and `close` values (aka OHLC) @@ -736,6 +790,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Optional 2nd argument `"open"`, `"high"` or `"low"` or `"close"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### rollup_delta `rollup_delta(series_selector[d])` is a [rollup function](#rollup-functions), which calculates differences between adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -762,6 +818,8 @@ See also [label_match](#label_match). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +See also [rollup](#rollup) and [rollup_rate](#rollup_rate). + #### rollup_increase `rollup_increase(series_selector[d])` is a [rollup function](#rollup-functions), which calculates increases for adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) @@ -774,12 +832,17 @@ See also [label_match](#label_match). Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. See also [rollup_delta](#rollup_delta). +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [rollup](#rollup) and [rollup_rate](#rollup_rate). + #### rollup_rate `rollup_rate(series_selector[d])` is a [rollup function](#rollup-functions), which calculates per-second change rates for adjacent [raw samples](https://docs.victoriametrics.com/keyconcepts/#raw-samples) on the given lookbehind window `d` and returns `min`, `max` and `avg` values for the calculated per-second change rates and returns them in time series with `rollup="min"`, `rollup="max"` and `rollup="avg"` additional labels. +The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). See [this article](https://valyala.medium.com/why-irate-from-prometheus-doesnt-capture-spikes-45f9896d7832) in order to understand better when to use `rollup_rate()`. @@ -787,10 +850,12 @@ when to use `rollup_rate()`. Optional 2nd argument `"min"`, `"max"` or `"avg"` can be passed to keep only one calculation result and without adding a label. See also [label_match](#label_match). -The calculations are performed individually per each time series returned from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#filtering). - Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [counters](https://docs.victoriametrics.com/keyconcepts/#counter). + +See also [rollup](#rollup) and [rollup_increase](#rollup_increase). + #### rollup_scrape_interval `rollup_scrape_interval(series_selector[d])` is a [rollup function](#rollup-functions), which calculates the interval in seconds between @@ -824,6 +889,8 @@ This function is useful for calculating SLI and SLO. Example: `share_gt_over_tim Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [share_le_over_time](#share_le_over_time) and [count_gt_over_time](#count_gt_over_time). #### share_le_over_time @@ -838,6 +905,8 @@ the share of time series values for the last 24 hours when memory usage was belo Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [share_gt_over_time](#share_gt_over_time) and [count_le_over_time](#count_le_over_time). #### share_eq_over_time @@ -849,6 +918,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [count_eq_over_time](#count_eq_over_time). #### stale_samples_over_time @@ -866,6 +937,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [stdvar_over_time](#stdvar_over_time). @@ -877,6 +950,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. See also [stddev_over_time](#stddev_over_time). @@ -888,6 +963,8 @@ values equal to `eq` on the given lookbehind window `d` per each time series ret Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_eq_over_time](#count_eq_over_time). #### sum_gt_over_time @@ -897,6 +974,8 @@ values bigger than `gt` on the given lookbehind window `d` per each time series Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_gt_over_time](#count_gt_over_time). #### sum_le_over_time @@ -906,6 +985,8 @@ values smaller or equal to `le` on the given lookbehind window `d` per each time Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [sum_over_time](#sum_over_time) and [count_le_over_time](#count_le_over_time). #### sum_over_time @@ -915,6 +996,8 @@ on the given lookbehind window `d` per each time series returned from the given Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + This function is supported by PromQL. #### sum2_over_time @@ -924,6 +1007,8 @@ values on the given lookbehind window `d` per each time series returned from the Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + #### timestamp `timestamp(series_selector[d])` is a [rollup function](#rollup-functions), which returns the timestamp in seconds with millisecond precision @@ -1001,6 +1086,8 @@ from the given [series_selector](https://docs.victoriametrics.com/keyconcepts/#f Metric names are stripped from the resulting rollups. Add [keep_metric_names](#keep_metric_names) modifier in order to keep metric names. +This function is usually applied to [gauges](https://docs.victoriametrics.com/keyconcepts/#gauge). + See also [zscore](#zscore), [range_trim_zscore](#range_trim_zscore) and [outlier_iqr_over_time](#outlier_iqr_over_time). @@ -2230,7 +2317,8 @@ Any [rollup function](#rollup-functions) for something other than [series select Nested rollup functions can be implicit thanks to the [implicit query conversions](#implicit-query-conversions). For example, `delta(sum(m))` is implicitly converted to `delta(sum(default_rollup(m))[1i:1i])`, so it becomes a subquery, since it contains [default_rollup](#default_rollup) nested into [delta](#delta). -This behavior can be disabled or logged via cmd-line flags `-search.disableImplicitConversion` and `-search.logImplicitConversion` since v1.101.0. +This behavior can be disabled or logged via `-search.disableImplicitConversion` and `-search.logImplicitConversion` command-line flags +starting from [`v1.101.0` release](https://docs.victoriametrics.com/changelog/). VictoriaMetrics performs subqueries in the following way: @@ -2263,5 +2351,6 @@ VictoriaMetrics performs the following implicit conversions for incoming queries For example, `avg_over_time(rate(http_requests_total[5m])[1h])` is automatically converted to `avg_over_time(rate(http_requests_total[5m])[1h:1i])`. * If something other than [series selector](https://docs.victoriametrics.com/keyconcepts/#filtering) is passed to [rollup function](#rollup-functions), then a [subquery](#subqueries) with `1i` lookbehind window and `1i` step is automatically formed. - For example, `rate(sum(up))` is automatically converted to `rate((sum(default_rollup(up)))[1i:1i])`. - This behavior can be disabled or logged via cmd-line flags `-search.disableImplicitConversion` and `-search.logImplicitConversion` since v1.101.0. + For example, `rate(sum(up))` is automatically converted to `rate((sum(default_rollup(up)))[1i:1i])`. + This behavior can be disabled or logged via `-search.disableImplicitConversion` and `-search.logImplicitConversion` command-line flags + starting from [`v1.101.0` release](https://docs.victoriametrics.com/changelog/).