(function(){var e={unitSuffix:"",labels:{},data:[]},t={options:{},init:function(e){if(this.options=e,!this.options.metrics_proxy_enabled)throw new Error("prometheus metrics provider currently requires the ui_config.metrics_proxy to be configured in the Consul agent.")},httpGet:function(e,t,r){if(t){var s=-1!==e.indexOf("?")?"&":"?" e=e+s+Object.keys(t).map((function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])})).join("&")}return this.options.fetch(e,{headers:r||{}}).then((function(e){if(e.ok)return e.json() var t=new Error("HTTP Error: "+e.statusText) throw t.statusCode=e.status,t}))},serviceRecentSummarySeries:function(e,t,r,s,n){var a=(new Date).getTime()/1e3 return n.start=a-900,n.end=a,this.hasL7Metrics(s)?this.fetchRequestRateSeries(e,t,r,n):this.fetchDataRateSeries(e,t,r,n)},serviceRecentSummaryStats:function(e,t,r,s,n){var a=[] return this.hasL7Metrics(s)?(a.push(this.fetchRPS(e,t,r,"service",n)),a.push(this.fetchER(e,t,r,"service",n)),a.push(this.fetchPercentile(50,e,t,r,"service",n)),a.push(this.fetchPercentile(99,e,t,r,"service",n))):(a.push(this.fetchConnRate(e,t,r,"service",n)),a.push(this.fetchServiceRx(e,t,r,"service",n)),a.push(this.fetchServiceTx(e,t,r,"service",n)),a.push(this.fetchServiceNoRoute(e,t,r,"service",n))),this.fetchStats(a)},upstreamRecentSummaryStats:function(e,t,r,s){return this.fetchRecentSummaryStats(e,t,r,"upstream",s)},downstreamRecentSummaryStats:function(e,t,r,s){return this.fetchRecentSummaryStats(e,t,r,"downstream",s)},fetchRecentSummaryStats:function(e,t,r,s,n){var a=[] return a.push(this.fetchRPS(e,t,r,s,n)),a.push(this.fetchER(e,t,r,s,n)),a.push(this.fetchPercentile(50,e,t,r,s,n)),a.push(this.fetchPercentile(99,e,t,r,s,n)),a.push(this.fetchConnRate(e,t,r,s,n)),a.push(this.fetchServiceRx(e,t,r,s,n)),a.push(this.fetchServiceTx(e,t,r,s,n)),a.push(this.fetchServiceNoRoute(e,t,r,s,n)),this.fetchStatsGrouped(a)},hasL7Metrics:function(e){return"http"===e||"http2"===e||"grpc"===e},fetchStats:function(e){return Promise.all(e).then((function(t){for(var r={stats:[]},s=0;s${c} request rate averaged over the last 15 minutes`,r,this.groupByInfix(n))},fetchER:function(e,t,s,n){var a=this.makeHTTPSelector(e,t,s,n),c=this.makeSubject(e,t,s,n),i="" "upstream"==n?i+=" by (consul_upstream_service,consul_upstream_datacenter,consul_upstream_namespace)":"downstream"==n&&(i+=" by (consul_source_service,consul_source_datacenter,consul_source_namespace)") var u=this.metricPrefixHTTP(n),o=`sum(rate(${u}_xx{${a},envoy_response_code_class="5"}[15m]))${i}/sum(rate(${u}_xx{${a}}[15m]))${i}` return this.fetchStat(o,"ER",`Percentage of ${c} requests which were 5xx status over the last 15 minutes`,(function(e){return r(e)+"%"}),this.groupByInfix(n))},fetchPercentile:function(e,t,r,n,a){var c=this.makeHTTPSelector(t,r,n,a),i=this.makeSubject(t,r,n,a),u="le" "upstream"==a?u+=",consul_upstream_service,consul_upstream_datacenter,consul_upstream_namespace":"downstream"==a&&(u+=",consul_source_service,consul_source_datacenter,consul_source_namespace") var o=`histogram_quantile(${e/100}, sum by(${u}) (rate(${this.metricPrefixHTTP(a)}_time_bucket{${c}}[15m])))` return this.fetchStat(o,"P"+e,`${i} ${e}th percentile request service time over the last 15 minutes`,s,this.groupByInfix(a))},fetchConnRate:function(e,t,s,n){var a=this.makeTCPSelector(e,t,s,n),c=this.makeSubject(e,t,s,n),i=`sum(rate(${this.metricPrefixTCP(n)}_total{${a}}[15m]))` return this.fetchStat(this.groupQuery(n,i),"CR",`${c} inbound TCP connections per second averaged over the last 15 minutes`,r,this.groupByInfix(n))},fetchServiceRx:function(e,t,s,n){var a=this.makeTCPSelector(e,t,s,n),c=this.makeSubject(e,t,s,n),i=`8 * sum(rate(${this.metricPrefixTCP(n)}_rx_bytes_total{${a}}[15m]))` return this.fetchStat(this.groupQuery(n,i),"RX",`${c} received bits per second averaged over the last 15 minutes`,r,this.groupByInfix(n))},fetchServiceTx:function(e,t,s,n){var a=this.makeTCPSelector(e,t,s,n),c=this.makeSubject(e,t,s,n),i=`8 * sum(rate(${this.metricPrefixTCP(n)}_tx_bytes_total{${a}}[15m]))` return this.fetchStat(this.groupQuery(n,i),"TX",`${c} transmitted bits per second averaged over the last 15 minutes`,r,this.groupByInfix(n))},fetchServiceNoRoute:function(e,t,s,n){var a=this.makeTCPSelector(e,t,s,n),c=this.makeSubject(e,t,s,n),i="_no_route" "downstream"==n&&(i="_connect_fail") var u=`sum(rate(${this.metricPrefixTCP(n)}${i}{${a}}[15m]))` return this.fetchStat(this.groupQuery(n,u),"NR",`${c} unroutable (failed) connections per second averaged over the last 15 minutes`,r,this.groupByInfix(n))},fetchStat:function(e,t,r,s,n){n||(e+=" OR on() vector(0)") var a={query:e,time:(new Date).getTime()/1e3} return this.httpGet("/api/v1/query",a).then((function(e){if(!n){var a=parseFloat(e.data.result[0].value[1]) return{label:t,desc:r,value:isNaN(a)?"-":s(a)}}for(var c={},i=0;i=100?e.toPrecision(3):e<1?e.toFixed(2):e.toPrecision(2)):e>=1e3&&e<1e6?+(e/1e3).toPrecision(3)+"k":e>=1e6&&e<1e9?+(e/1e6).toPrecision(3)+"m":e>=1e9&&e<1e12?+(e/1e9).toPrecision(3)+"g":e>=1e12?+(e/1e12).toFixed(0)+"t":void 0}function s(e){if(e<1e3)return Math.round(e)+"ms" var t=e/1e3 if(t<60)return t.toFixed(1)+"s" var r=t/60 if(r<60)return r.toFixed(1)+"m" var s=r/60 return s<24?s.toFixed(1)+"h":(s/24).toFixed(1)+"d"}window.consul.registerMetricsProvider("prometheus",t)})()