@@ -3,9 +3,23 @@ package cdn
3
3
import (
4
4
"context"
5
5
"net/http"
6
+ "sync"
6
7
8
+ "go.opencensus.io/stats"
9
+ "go.opencensus.io/tag"
10
+
11
+ "github.com/ovh/cds/engine/api/observability"
7
12
"github.com/ovh/cds/engine/service"
8
13
"github.com/ovh/cds/sdk"
14
+ "github.com/ovh/cds/sdk/log"
15
+ )
16
+
17
+ var (
18
+ onceMetrics sync.Once
19
+ Errors * stats.Int64Measure
20
+ Hits * stats.Int64Measure
21
+ WorkerLogReceived * stats.Int64Measure
22
+ ServiceLogReceived * stats.Int64Measure
9
23
)
10
24
11
25
func (s * Service ) statusHandler () service.Handler {
@@ -22,3 +36,39 @@ func (s *Service) Status(ctx context.Context) sdk.MonitoringStatus {
22
36
m .Lines = append (m .Lines , sdk.MonitoringStatusLine {Component : "CDN" , Value : status , Status : status })
23
37
return m
24
38
}
39
+
40
+ func (s * Service ) InitMetrics () error {
41
+ var err error
42
+ onceMetrics .Do (func () {
43
+ Errors = stats .Int64 (
44
+ "cdn/tcp/router_errors" ,
45
+ "number of errors" ,
46
+ stats .UnitDimensionless )
47
+ Hits = stats .Int64 (
48
+ "cdn/tcp/router_hits" ,
49
+ "number of hits" ,
50
+ stats .UnitDimensionless )
51
+ WorkerLogReceived = stats .Int64 (
52
+ "cdn/tcp/worker/log/count" ,
53
+ "Number of worker log received" ,
54
+ stats .UnitDimensionless )
55
+ ServiceLogReceived = stats .Int64 (
56
+ "cdn/tcp/service/log/count" ,
57
+ "Number of service log received" ,
58
+ stats .UnitDimensionless )
59
+
60
+ tagServiceType := observability .MustNewKey (observability .TagServiceType )
61
+ tagServiceName := observability .MustNewKey (observability .TagServiceName )
62
+
63
+ err = observability .RegisterView (
64
+ observability .NewViewCount ("cdn/tcp/router/router_errors" , Errors , []tag.Key {tagServiceType , tagServiceName }),
65
+ observability .NewViewCount ("cdn/tcp/router/router_hits" , Hits , []tag.Key {tagServiceType , tagServiceName }),
66
+ observability .NewViewCount ("cdn/tcp/worker/log/count" , WorkerLogReceived , []tag.Key {tagServiceType , tagServiceName }),
67
+ observability .NewViewCount ("cdn/tcp/service/log/count" , ServiceLogReceived , []tag.Key {tagServiceType , tagServiceName }),
68
+ )
69
+ })
70
+
71
+ log .Debug ("cdn> Stats initialized" )
72
+
73
+ return err
74
+ }
0 commit comments