go-duck-cli 1.4.14 → 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.14",
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}}