@platformos/pos-cli
Version:
Manage your platformOS application
2 lines (1 loc) • 1.87 kB
JavaScript
const r={get:async(t={})=>{const o=typeof window<"u"&&window.location.port!=="4173"&&window.location.port!=="5173"?`http://localhost:${parseInt(window.location.port)}/api/logsv2`:"http://localhost:3333/api/logsv2";if(t.stream_name=t.stream_name??"requests",t.aggregate==="http_request_path"&&(t.aggregate=" GROUP BY http_request_path, http_request_method"),t.start_time){let e=new Date(t.start_time);e.setHours(23,59,59),t.end_time=Math.floor(e.getTime()*1e3),t.start_time=Math.floor(e.getTime()-2592e5)}t.lb_status_codes&&(t.lb_status_codes=` lb_status_code IN (${t.lb_status_codes}) `);let _={},a="";t.lb_status_codes&&(a=" WHERE "),t.order_by&&(t.order=` ORDER BY ${t.order_by} ${t.order} `),t.sql||(_.filters="SELECT lb_status_code, count(lb_status_code) as count FROM query GROUP BY lb_status_code ORDER BY count DESC"),t.sql||(t.aggregate?_.results=`SELECT http_request_path, count(http_request_path) as count, http_request_method, approx_percentile_cont(target_processing_time, 0.5) as median_target_processing_time, avg(target_processing_time) as avg_target_processing_time, min(target_processing_time) as min_target_processing_time, max(target_processing_time) as max_target_processing_time FROM query ${a} ${t.lb_status_codes??""} ${t.aggregate} ${t.order}`:_.results=`SELECT _timestamp, http_request_url, http_request_path, http_request_method, lb_status_code, client, user_agent, request_processing_time, target_processing_time, sent_bytes FROM query ${a} ${t.lb_status_codes??""} ${t.order} LIMIT 150`);const s={aggs:{..._},query:{sql:t.sql||`SELECT * FROM ${t.stream_name}`,from:t.from??0,size:t.size??150,start_time:t.start_time||0,end_time:t.end_time||0}};return fetch(`${o}`,{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}}).then(e=>e.ok?e.json():Promise.reject(e)).then(e=>e).catch(e=>({error:e}))}};export{r as n};