cartodb-4.42/vendor/assets/javascripts/statsc.min.js

1 line
1.4 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
(function(){var statsc={};var addr="http://localhost:8127/";statsc.connect=function(_addr){addr=_addr};statsc.increment=function(stat,sampleRate){statsc.send(["i",stat,sampleRate])};statsc.decrement=function(stat,sampleRate){statsc.send(["d",stat,sampleRate])};statsc.gauge=function(stat,value,sampleRate){statsc.send(["g",stat,value,sampleRate])};statsc.timing=function(stat,time,sampleRate){if("number"==typeof time){return statsc.send(["t",stat,time,sampleRate])}if(time instanceof Date){return statsc.send(["t",stat,fromNow(time),sampleRate])}if("function"==typeof time){var start=new Date;time();statsc.send(["t",stat,fromNow(start),sampleRate])}};statsc.timer=function(stat,sampleRate){var start=(new Date).getTime();return function(){statsc.send(["t",stat,fromNow(start),sampleRate])}};statsc.send=function(){var queue=[];var head=document.getElementsByTagName("head")[0];setInterval(function(){if(queue.length>0){for(var i=0;i<queue.length;i++){for(var j=0;j<queue[i].length;j++){if(queue[i][j]==null)queue[i].splice(j,1)}}var tag=document.createElement("script");tag.src=addr+JSON.stringify(queue);tag.onload=function(){head.removeChild(tag)};head.appendChild(tag);queue=[]}},5e3);return function(data){queue.push(data)}}();function fromNow(date){return new Date-date}if(typeof require=="function"&&typeof module!=="undefined"){module.exports=statsc}if(typeof window=="object"){window.statsc=statsc}})();