go-duck-cli 1.4.13 → 1.4.15

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.
@@ -143,6 +143,63 @@ var globalMetrics = &AppMetrics{
143
143
  StatusCodes: make(map[int]*StatusStats),
144
144
  }
145
145
 
146
+ type MetricsBroker struct {
147
+ clients map[chan AppMetrics]bool
148
+ mu sync.Mutex
149
+ }
150
+
151
+ var GlobalMetricsBroker = &MetricsBroker{
152
+ clients: make(map[chan AppMetrics]bool),
153
+ }
154
+
155
+ func (b *MetricsBroker) AddClient(client chan AppMetrics) {
156
+ b.mu.Lock()
157
+ defer b.mu.Unlock()
158
+ b.clients[client] = true
159
+ }
160
+
161
+ func (b *MetricsBroker) RemoveClient(client chan AppMetrics) {
162
+ b.mu.Lock()
163
+ defer b.mu.Unlock()
164
+ delete(b.clients, client)
165
+ close(client)
166
+ }
167
+
168
+ func (b *MetricsBroker) Broadcast(metrics *AppMetrics) {
169
+ metrics.Mu.RLock()
170
+ safeCopy := AppMetrics{
171
+ StartTime: metrics.StartTime,
172
+ Endpoints: make(map[string]*EndpointStats),
173
+ StatusCodes: make(map[int]*StatusStats),
174
+ FailedCalls: metrics.FailedCalls,
175
+ }
176
+ for k, v := range metrics.Endpoints {
177
+ safeCopy.Endpoints[k] = &EndpointStats{Count: v.Count, MeanTime: v.MeanTime, MaxTime: v.MaxTime, TotalTime: v.TotalTime}
178
+ }
179
+ for k, v := range metrics.StatusCodes {
180
+ safeCopy.StatusCodes[k] = &StatusStats{Count: v.Count, MeanTime: v.MeanTime, MaxTime: v.MaxTime, TotalTime: v.TotalTime}
181
+ }
182
+ metrics.Mu.RUnlock()
183
+
184
+ b.mu.Lock()
185
+ defer b.mu.Unlock()
186
+ for client := range b.clients {
187
+ select {
188
+ case client <- safeCopy:
189
+ default:
190
+ }
191
+ }
192
+ }
193
+
194
+ func init() {
195
+ go func() {
196
+ for {
197
+ time.Sleep(1 * time.Second)
198
+ GlobalMetricsBroker.Broadcast(globalMetrics)
199
+ }
200
+ }()
201
+ }
202
+
146
203
  func MetricsTrackingMiddleware(cfg *config.Config) gin.HandlerFunc {
147
204
  return func(c *gin.Context) {
148
205
  start := time.Now()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-duck-cli",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
4
4
  "description": "The Ultimate Evolutionary Go Microservice Scaffolder.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2,7 +2,6 @@ package router
2
2
 
3
3
  import (
4
4
  "context"
5
- "encoding/json"
6
5
  "fmt"
7
6
  "io"
8
7
  "log"
@@ -19,8 +18,6 @@ import (
19
18
  "gorm.io/gorm"
20
19
  "gorm.io/plugin/opentelemetry/tracing"
21
20
  "github.com/prometheus/client_golang/prometheus/promhttp"
22
- "github.com/shirou/gopsutil/v3/cpu"
23
- "github.com/shirou/gopsutil/v3/mem"
24
21
  {{#if multitenancy_enabled}}
25
22
  "{{app_name}}/management"
26
23
  {{/if}}
@@ -1217,16 +1214,16 @@ func SetupRouter(appConfig *config.Config) *gin.Engine {
1217
1214
  if (threadsGrid.children.length !== sys.cpu_threads_usage.length) {
1218
1215
  let html = '';
1219
1216
  sys.cpu_threads_usage.forEach((val, idx) => {
1220
- html += `<div class="cpu-chart-container" title="Core ${idx}">
1221
- <canvas id="t-cpu-canvas-${idx}" class="cpu-chart-canvas"></canvas>
1222
- <div id="t-cpu-label-${idx}" class="cpu-chart-label">T${idx}: 0%</div>
1223
- </div>`;
1217
+ html += '<div class="cpu-chart-container" title="Core ' + idx + '">' +
1218
+ '<canvas id="t-cpu-canvas-' + idx + '" class="cpu-chart-canvas"></canvas>' +
1219
+ '<div id="t-cpu-label-' + idx + '" class="cpu-chart-label">T' + idx + ': 0%</div>' +
1220
+ '</div>';
1224
1221
  });
1225
1222
  threadsGrid.innerHTML = html;
1226
1223
 
1227
1224
  // Set internal canvas resolution to match computed CSS size for crisp rendering
1228
1225
  sys.cpu_threads_usage.forEach((val, idx) => {
1229
- const canvas = document.getElementById(`t-cpu-canvas-${idx}`);
1226
+ const canvas = document.getElementById('t-cpu-canvas-' + idx);
1230
1227
  if (canvas) {
1231
1228
  canvas.width = canvas.offsetWidth;
1232
1229
  canvas.height = canvas.offsetHeight;
@@ -1246,13 +1243,13 @@ func SetupRouter(appConfig *config.Config) *gin.Engine {
1246
1243
  }
1247
1244
 
1248
1245
  // Render Text Label
1249
- const label = document.getElementById(`t-cpu-label-${idx}`);
1246
+ const label = document.getElementById('t-cpu-label-' + idx);
1250
1247
  if (label) {
1251
- label.innerText = `T${idx}: ${val.toFixed(0)}%`;
1248
+ label.innerText = 'T' + idx + ': ' + val.toFixed(0) + '%';
1252
1249
  }
1253
1250
 
1254
1251
  // Render Canvas Sparkline
1255
- const canvas = document.getElementById(`t-cpu-canvas-${idx}`);
1252
+ const canvas = document.getElementById('t-cpu-canvas-' + idx);
1256
1253
  if (canvas) {
1257
1254
  const ctx = canvas.getContext('2d');
1258
1255
  const width = canvas.width;