@mantiq/heartbeat 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -136,6 +136,17 @@ export class HeartbeatMiddleware implements Middleware {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// Attach debug stats header: duration;memory;status;queries
|
|
140
|
+
if (process.env.APP_DEBUG === 'true' && response!) {
|
|
141
|
+
try {
|
|
142
|
+
const mem = (Math.abs(process.memoryUsage().rss - startMemory) / 1024 / 1024).toFixed(1)
|
|
143
|
+
const headers = new Headers(response!.headers)
|
|
144
|
+
headers.set('X-Heartbeat', `${Math.round(duration)}ms;${mem}MB;${response!.status};0q`)
|
|
145
|
+
headers.set('Access-Control-Expose-Headers', [headers.get('Access-Control-Expose-Headers'), 'X-Heartbeat'].filter(Boolean).join(', '))
|
|
146
|
+
response = new Response(response!.body, { status: response!.status, statusText: response!.statusText, headers })
|
|
147
|
+
} catch { /* ignore */ }
|
|
148
|
+
}
|
|
149
|
+
|
|
139
150
|
// Flush entries (fire-and-forget)
|
|
140
151
|
this.heartbeat.flush()
|
|
141
152
|
}
|
|
@@ -67,6 +67,41 @@ export function renderWidget(data: {
|
|
|
67
67
|
</div>
|
|
68
68
|
</div>
|
|
69
69
|
</div>
|
|
70
|
-
<script>
|
|
70
|
+
<script>
|
|
71
|
+
(function(){
|
|
72
|
+
document.addEventListener('keydown',function(e){if(e.key==='Escape')document.getElementById('__mw_panel').style.display='none'});
|
|
73
|
+
|
|
74
|
+
// Intercept fetch to read X-Heartbeat header and update widget
|
|
75
|
+
var _fetch=window.fetch;
|
|
76
|
+
window.fetch=function(){
|
|
77
|
+
return _fetch.apply(this,arguments).then(function(res){
|
|
78
|
+
var h=res.headers.get('X-Heartbeat');
|
|
79
|
+
if(h)updateWidget(h);
|
|
80
|
+
return res;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function updateWidget(header){
|
|
85
|
+
// Format: 15ms;1.6MB;200;0q
|
|
86
|
+
var p=header.split(';');
|
|
87
|
+
if(p.length<4)return;
|
|
88
|
+
var dur=p[0],mem=p[1],status=parseInt(p[2]),queries=p[3];
|
|
89
|
+
var sc=status>=500?'#f87171':status>=400?'#fbbf24':'#34d399';
|
|
90
|
+
|
|
91
|
+
// Update pill
|
|
92
|
+
var pill=document.getElementById('__mw_stats');
|
|
93
|
+
if(pill)pill.innerHTML='<span id="__mw_dot" style="width:5px;height:5px;border-radius:50%;background:'+sc+';flex-shrink:0"></span><b style="color:#fafafa;font-weight:600">'+dur+'</b><span id="__mw_sep" style="color:#27272a">·</span><span>'+mem+'</span><span id="__mw_sep" style="color:#27272a">·</span><span>'+queries+'</span>';
|
|
94
|
+
|
|
95
|
+
// Update panel grid
|
|
96
|
+
var cells=document.querySelectorAll('#__mw_grid .cell .val');
|
|
97
|
+
if(cells.length>=4){
|
|
98
|
+
cells[0].innerHTML=dur.replace('ms','')+'<small>ms</small>';
|
|
99
|
+
cells[1].innerHTML=mem.replace('MB','')+'<small>MB</small>';
|
|
100
|
+
cells[2].innerHTML=status;cells[2].style.color=sc;
|
|
101
|
+
cells[3].innerHTML=queries.replace('q','');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
</script>
|
|
71
106
|
<!-- /mantiq:heartbeat-widget -->`
|
|
72
107
|
}
|