import{V as g}from"./vue.esm.01cc5dc9.js";import{l as d}from"./lodash.b33de59f.js";import{h as m,V as S}from"./moment.a3085614.js";import{B as V,f as v}from"./bootstrap-vue.81b4ee6c.js";import"./_commonjsHelpers.04e31c8c.js";var H=["y","M","w","d","h","m","s"];function A(t,e,r){if(!!t){if(m.isMoment(t))return t;if(d.exports.isDate(t))return m(t);var o,s="",u,l;return t.substring(0,3)==="now"?(r==="utc"?o=m.utc():o=m(),s=t.substring(3)):(u=t.indexOf("||"),u===-1?(l=t,s=""):(l=t.substring(0,u),s=t.substring(u+2)),o=m(l,m.ISO_8601)),s.length?U(s,o,e):o}}function N(t){var e=A(t);return e&&m.isMoment(e)?e.isValid():!1}function U(t,e,r){for(var o=e,s=0,u=t.length;s<u;){var l=t.charAt(s++),i,n,a;if(l==="/")i=0;else if(l==="+")i=1;else if(l==="-")i=2;else return;if(isNaN(t.charAt(s)))n=1;else if(t.length===2)n=t.charAt(s);else{for(var p=s;!isNaN(t.charAt(s));)if(s++,s>10)return;n=parseInt(t.substring(p,s),10)}if(i===0&&n!==1)return;if(a=t.charAt(s++),d.exports.includes(H,a))i===0?r?o.endOf(a):o.startOf(a):i===1?o.add(n,a):i===2&&o.subtract(n,a);else return}return o}const c={parse:A,isValid:N};var Z={s:{display:"second"},m:{display:"minute"},h:{display:"hour"},d:{display:"day"},w:{display:"week"},M:{display:"month"},y:{display:"year"}},B=[{from:"now/d",to:"now/d",display:"Today",section:2},{from:"now/d",to:"now",display:"Today so far",section:2},{from:"now/w",to:"now/w",display:"This week",section:2},{from:"now/w",to:"now",display:"This week so far",section:2},{from:"now/M",to:"now/M",display:"This month",section:2},{from:"now/M",to:"now",display:"This month so far",section:2},{from:"now/y",to:"now/y",display:"This year",section:2},{from:"now/y",to:"now",display:"This year so far",section:2},{from:"now-1d/d",to:"now-1d/d",display:"Yesterday",section:1},{from:"now-2d/d",to:"now-2d/d",display:"Day before yesterday",section:1},{from:"now-7d/d",to:"now-7d/d",display:"This day last week",section:1},{from:"now-1w/w",to:"now-1w/w",display:"Previous week",section:1},{from:"now-1M/M",to:"now-1M/M",display:"Previous month",section:1},{from:"now-1y/y",to:"now-1y/y",display:"Previous year",section:1},{from:"now-5m",to:"now",display:"Last 5 minutes",section:3},{from:"now-15m",to:"now",display:"Last 15 minutes",section:3},{from:"now-30m",to:"now",display:"Last 30 minutes",section:3},{from:"now-1h",to:"now",display:"Last 1 hour",section:3},{from:"now-3h",to:"now",display:"Last 3 hours",section:3},{from:"now-6h",to:"now",display:"Last 6 hours",section:3},{from:"now-12h",to:"now",display:"Last 12 hours",section:3},{from:"now-24h",to:"now",display:"Last 24 hours",section:3},{from:"now-2d",to:"now",display:"Last 2 days",section:0},{from:"now-7d",to:"now",display:"Last 7 days",section:0},{from:"now-30d",to:"now",display:"Last 30 days",section:0},{from:"now-90d",to:"now",display:"Last 90 days",section:0},{from:"now-6M",to:"now",display:"Last 6 months",section:0},{from:"now-1y",to:"now",display:"Last 1 year",section:0},{from:"now-2y",to:"now",display:"Last 2 years",section:0},{from:"now-5y",to:"now",display:"Last 5 years",section:0}],z="MMM D, YYYY HH:mm:ss",L={};d.exports.each(B,function(t){L[t.from+" to "+t.to]=t});function C(t,e){var r=d.exports.groupBy(B,function(o){return o.active=o.display===e,o.section});return r}function w(t){return t.format(z)}function Q(t){var e=t.indexOf("+")!==0;t.indexOf("now")===-1&&(t=(e?"now-":"now")+t);var r=L[t+" to now"];if(r)return r;e?r={from:t,to:"now"}:r={from:"now",to:t};var o=/^now([-+])(\d+)(\w)/.exec(t);if(o){var s=o[3],u=parseInt(o[2]),l=Z[s];l&&(r.display=e?"Last ":"Next ",r.display+=u+" "+l.display,r.section=l.section,u>1&&(r.display+="s"))}else r.display=r.from+" to "+r.to,r.invalid=!0;return r}function W(t){var e=L[t.from.toString()+" to "+t.to.toString()];if(e)return e.display;if(moment.isMoment(t.from)&&moment.isMoment(t.to))return w(t.from)+" to "+w(t.to);if(moment.isMoment(t.from)){var r=dateMath.parse(t.to,!0);return w(t.from)+" to "+r.fromNow()}if(moment.isMoment(t.to)){var o=dateMath.parse(t.from,!1);return o.fromNow()+" to "+w(t.to)}if(t.to.toString()==="now"){var s=Q(t.from);return s.display}return t.from.toString()+" to "+t.to.toString()}const k={describeTimeRange:W,getRelativeTimesList:C};var Y=`
  <div v-cloak>
    <button id="buttonPicker" class="btn btn-secondary" v-on:click="showHidePicker()">
      <i class="fa fa-clock-o"></i>
      <span v-cloak>{{ rangeString() }}</span>
    </button>
    <div class="row position-absolute bg-light border rounded card-body picker-dropdown-panel m-1 w-100 shadow" v-show="isPickerOpen" v-cloak>
      <div class="col-4">
        <h3>
          Custom range
        </h3>
        <form>
          <div class="form-group">
            <label for="inputFrom">From:</label>
            <div class="input-group">
              <input type="text" id="inputFrom" v-model="inputFrom" class="form-control">
              <div class="input-group-append" data-role="from-picker">
                <div class="input-group-text">
                  <i class="fa fa-calendar"></i>
                </div>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label for="inputTo">To:</label>
            <div class="input-group">
              <input type="text" id="inputTo" v-model="inputTo" class="form-control">
              <div class="input-group-append" data-role="to-picker">
                <div class="input-group-text">
                  <i class="fa fa-calendar"></i>
                </div>
              </div>
            </div>
          </div>
          <div>
            <button class="btn btn-primary" v-on:click.prevent="onApply">Apply</button>
          </div>
        </form>
      </div>
      <div class="col-8 pl-4">
        <h3>
          Quick ranges
        </h3>
        <div class="row">
          <ul class="list-unstyled col" v-for="section in ranges">
            <li class="shortcut" v-for="range in section">
              <a href :data-from=range.from :data-to="range.to" v-on:click.prevent="loadRangeShortcut(range)">
                {{ describeTimeRange(range) }}
              </a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="btn-group">
      <button id="buttonRefresh" class="btn btn-secondary" v-on:click="refresh()" :disabled="!isRefreshable">
        <i class="fa fa-refresh"></i>
      </button>
      <button id="buttonAutoRefresh" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" :disabled="!isRefreshable">
        <span class="text-warning" v-if="isRefreshable">
          {{ intervals[refreshInterval] }}
        </span>
      </button>
      <div class="dropdown-menu dropdown-menu-right" style="min-width: 50px;">
        <a class="dropdown-item refresh-off" href v-on:click.prevent="refreshInterval = null">Off</a>
        <div class="dropdown-divider"></div>
        <a :class='"dropdown-item refresh-" + interval' href v-on:click.prevent="refreshInterval = key" v-for="interval, key in intervals">{{ interval }}</a>
      </div>
    </div>
  </div>`,T,D,x;g.component("daterangepicker",{props:["from","to"],data:function(){return{ranges:k.getRelativeTimesList(),rangeString:function(){if(!(!this.rawFrom||!this.rawTo))return k.describeTimeRange({from:this.rawFrom,to:this.rawTo})},rawFrom:null,rawTo:null,inputFrom:null,inputTo:null,refreshInterval:null,intervals:{60:"1m",300:"5m",900:"15m"},isPickerOpen:!1}},methods:{loadRangeShortcut:E,describeTimeRange:k.describeTimeRange,showHidePicker:K,onApply:G,setFromTo:tt,notify:et,refresh:_},computed:{rawFromTo:function(){return""+this.rawFrom+this.rawTo},isRefreshable:function(){return this.rawFrom&&this.rawFrom.toString().indexOf("now")!=-1||this.rawTo&&this.rawTo.toString().indexOf("now")!=-1}},mounted:j,template:Y,watch:{rawFromTo:function(){this.$router.push({query:d.exports.assign({},this.$route.query,{start:""+this.rawFrom,end:""+this.rawTo})}),this.inputFrom=this.rawFrom,this.inputTo=this.rawTo},refreshInterval:_,$route:function(t,e){t.query.start&&(this.rawFrom=b(t.query.start)),t.query.end&&(this.rawTo=b(t.query.end)),this.refresh()}}});function j(){var t=this.$route.query.start||this.from||"now-24h",e=this.$route.query.end||this.to||"now";this.rawFrom=b(t),this.rawTo=b(e),this.notify(),J.call(this)}function b(t){const e=parseInt(t,10);return d.exports.isFinite(e)?moment(e):t}function E(t){this.rawFrom=t.from,this.rawTo=t.to,this.isPickerOpen=!1,this.refresh()}function K(){this.isPickerOpen=!this.isPickerOpen}function R(t){if(moment.isMoment(t))return t;const e=moment(new Date(t));return e.isValid()?e:t}function G(){this.isPickerOpen=!1,this.rawFrom=R(this.inputFrom),this.rawTo=R(this.inputTo),this.refresh()}var M={singleDatePicker:!0,timePicker:!0,timePicker24Hour:!0,timePickerSeconds:!1};function J(){(!T||!T.data("daterangepicker").isShowing)&&(T=$(this.$el).find("[data-role=from-picker]").daterangepicker($.extend({startDate:c.parse(this.rawFrom)},M),P.bind(this,"inputFrom"))),(!D||!D.data("daterangepicker").isShowing)&&(D=$(this.$el).find("[data-role=to-picker]").daterangepicker($.extend({startDate:c.parse(this.rawTo),minDate:c.parse(this.rawFrom)},M),P.bind(this,"inputTo")))}function X(){$(this.$el).find("[data-role=to-picker]").daterangepicker($.extend({minDate:c.parse(this.inputFrom)},M),P.bind(this,"inputTo"))}function P(t,e){this[t]=e,t==="inputFrom"&&X.call(this)}function _(){this.notify(),clearTimeout(x),this.refreshInterval&&(x=window.setTimeout(this.refresh,this.refreshInterval*1e3))}function tt(t,e){this.rawFrom=t,this.rawTo=e,this.refresh()}function et(){this.$emit("update:from",c.parse(this.rawFrom)),this.$emit("update:to",c.parse(this.rawTo,!0))}g.use(S);g.use(V);var F,q,f=new g({el:"#app",router:new S,data:{statements:[],metas:null,lastSnapshot:null,isLoading:!0,dbid:null,queryid:null,userid:null,datname:null,sortBy:"total_exec_time",filter:"",from:null,to:null,totalRows:1,currentPage:1,perPage:20},computed:{fields:rt,fromTo:function(){return""+this.from+this.to},queryidUserid:function(){return this.queryid,this.userid}},methods:{fetchData:O,highlight:it,onFiltered:ot},watch:{fromTo:O,dbid:function(){var t=d.exports.assign({},this.$route.query);this.dbid?t.dbid=this.dbid:(delete t.dbid,delete t.queryid,delete t.userid),this.$router.push({query:t}),this.fetchData()},queryidUserid:function(){var t=d.exports.assign({},this.$route.query);this.queryid?(t.dbid=this.dbid,t.queryid=this.queryid,t.userid=this.userid):(delete t.queryid,delete t.userid),this.$router.push({query:t}),this.fetchData()},$route:function(t,e){this.dbid=t.query.dbid,this.queryid=t.query.queryid,this.userid=t.query.userid}}});function O(){this.statements=[];var t=this.from,e=this.to,r=this.dbid?"/"+this.dbid:"";r+=this.queryid?"/"+this.queryid:"",r+=this.userid?"/"+this.userid:"",this.isLoading=!0,F&&F.abort(),F=$.get(apiUrl+r,{start:y(t),end:y(e),noerror:1},function(o){this.isLoading=!1,this.datname=o.datname,this.statements=o.data,this.queryid&&(this.statements[0]._showDetails=!0),this.totalRows=this.statements.length,this.metas=o.metas}.bind(this)),q&&q.abort(),q=$.get(chartApiUrl+r,{start:y(t),end:y(e),noerror:1},st)}function rt(){var t=[{key:"query",label:"Query",class:"query",sortable:!0,sortDirection:"asc"},{key:"datname",label:"DB",class:"database",sortable:!0,sortDirection:"asc"},{key:"rolname",label:"User",sortable:!0,sortDirection:"asc"},{key:"calls",label:"Calls",class:"text-right",sortable:!0},{key:"total_exec_time",label:"Total",formatter:v,class:"text-right border-left",sortable:!0},{key:"mean_time",label:"AVG",formatter:v,class:"text-right",sortable:!0},{key:"shared_blks_read",label:"Read",class:"text-right border-left",formatter:h,sortable:!0},{key:"shared_blks_hit",label:"Hit",class:"text-right",formatter:h,sortable:!0},{key:"shared_blks_dirtied",label:"Dirt.",class:"text-right",formatter:h,sortable:!0},{key:"shared_blks_written",label:"Writ.",class:"text-right",formatter:h,sortable:!0},{key:"temp_blks_read",label:"Read",class:"text-right border-left",formatter:h,sortable:!0},{key:"temp_blks_written",label:"Writ.",class:"text-right",formatter:h,sortable:!0}],e=["rolname","query"];return this.dbid&&(e=["datname"]),d.exports.filter(t,function(r){return e.indexOf(r.key)===-1})}function h(t){t*=8192;var e=["B","KB","MB","GB","TB"];if(t==0)return'<span class="text-muted">0</span>';var r=parseInt(Math.floor(Math.log(t)/Math.log(1024)));return Math.round(t/Math.pow(1024,r),2)+" "+e[r]}function it(t){return hljs.highlight("sql",t).value}function ot(t){this.totalRows=t.length,this.currentPage=1}function y(t){var e=new Date(t);return e.toISOString()}function st(t){var e=f.from,r=f.to,o={axisLabelFontSize:10,yLabelWidth:14,includeZero:!0,legend:"always",labelsKMB:!0,gridLineColor:"rgba(128, 128, 128, 0.3)",dateWindow:[new Date(e).getTime(),new Date(r).getTime()],xValueParser:function(i){var n=moment(i);return n.toDate().getTime()},zoomCallback:I,interactionModel:{mousedown:function(i,n,a){a.initializeMouseDown(i,n,a),i.shiftKey?Dygraph.startPan(i,n,a):Dygraph.startZoom(i,n,a)},mousemove:function(i,n,a){a.isPanning?Dygraph.movePan(i,n,a):a.isZooming&&Dygraph.moveZoom(i,n,a)},mouseup:function(i,n,a){if(a.isPanning){Dygraph.endPan(i,n,a);var p=n.dateWindow_;I(p[0],p[1])}else a.isZooming&&Dygraph.endZoom(i,n,a)}}};this.chart;var s=d.exports.map(t.data,function(i){return[moment.unix(i.ts).toDate(),i.calls]});new Dygraph(document.getElementById("chart1"),s,Object.assign({},o,{labels:["time","Queries per sec"],labelsDiv:"legend-chart1"}));var u=d.exports.map(t.data,function(i){return[moment.unix(i.ts).toDate(),i.load,i.avg_runtime]});new Dygraph(document.getElementById("chart2"),u,Object.assign({},o,{labels:["time","Time per sec","Avg runtime"],labelsDiv:"legend-chart2",axes:{y:{valueFormatter:v,axisLabelFormatter:v}}}));var l=d.exports.map(t.data,function(i){return[moment.unix(i.ts).toDate(),i.total_blks_hit,i.total_blks_read]});new Dygraph(document.getElementById("chart3"),l,Object.assign({},o,{labels:["time","Hit /s","Read /s"],labelsDiv:"legend-chart3",axes:{y:{valueFormatter:h,axisLabelFormatter:h}}}))}function I(t,e){f.$refs.daterangepicker.setFromTo(moment(t),moment(e))}f.dbid=f.$route.query.dbid;f.queryid=f.$route.query.queryid;f.userid=f.$route.query.userid;
