@@ -15,7 +15,20 @@ import (
1515
1616var Enabled bool
1717var registry = prometheus .NewRegistry ()
18- var nodeIdentifier string
18+ var ScrapingHandler http.Handler = nil
19+ var durationBuckets = []float64 {0.002 , 0.005 , 0.010 , 0.02 , 0.03 , 0.05 , 0.1 , 0.15 , 0.3 , 0.6 , 1.0 }
20+
21+ var (
22+ CompletedInvocations = promauto .NewCounterVec (prometheus.CounterOpts {
23+ Name : "completed_total" ,
24+ Help : "Number of completed function invocations" ,
25+ }, []string {"node" , "function" })
26+ ExecutionTimes = promauto .NewHistogramVec (prometheus.HistogramOpts {
27+ Name : "execution_time" ,
28+ Help : "Function duration" ,
29+ Buckets : durationBuckets ,
30+ }, []string {"node" , "function" })
31+ )
1932
2033func Init () {
2134 if config .GetBool (config .METRICS_ENABLED , false ) {
@@ -26,43 +39,16 @@ func Init() {
2639 return
2740 }
2841
29- nodeIdentifier = node . NodeIdentifier
30- registerGlobalMetrics ( )
42+ registry . MustRegister ( CompletedInvocations )
43+ registry . MustRegister ( ExecutionTimes )
3144
32- handler : = promhttp .HandlerFor (registry , promhttp.HandlerOpts {
45+ ScrapingHandler = promhttp .HandlerFor (registry , promhttp.HandlerOpts {
3346 EnableOpenMetrics : true })
34- http .Handle ("/metrics" , handler )
35- err := http .ListenAndServe (":2112" , nil )
36- if err != nil {
37- log .Printf ("Listen and serve terminated with error: %s\n " , err )
38- return
39- }
4047}
4148
42- // Global metrics
43- var (
44- CompletedInvocations = promauto .NewCounterVec (prometheus.CounterOpts {
45- Name : "sedge_completed_total" ,
46- Help : "The total number of completed function invocations" ,
47- }, []string {"node" , "function" })
48- ExecutionTimes = promauto .NewHistogramVec (prometheus.HistogramOpts {
49- Name : "sedge_exectime" ,
50- Help : "Function duration" ,
51- Buckets : durationBuckets ,
52- },
53- []string {"node" , "function" })
54- )
55-
56- var durationBuckets = []float64 {0.002 , 0.005 , 0.010 , 0.02 , 0.03 , 0.05 , 0.1 , 0.15 , 0.3 , 0.6 , 1.0 }
57-
5849func AddCompletedInvocation (funcName string ) {
59- CompletedInvocations .With (prometheus.Labels {"function" : funcName , "node" : nodeIdentifier }).Inc ()
50+ CompletedInvocations .With (prometheus.Labels {"function" : funcName , "node" : node . NodeIdentifier }).Inc ()
6051}
6152func AddFunctionDurationValue (funcName string , duration float64 ) {
62- ExecutionTimes .With (prometheus.Labels {"function" : funcName , "node" : nodeIdentifier }).Observe (duration )
63- }
64-
65- func registerGlobalMetrics () {
66- registry .MustRegister (CompletedInvocations )
67- registry .MustRegister (ExecutionTimes )
53+ ExecutionTimes .With (prometheus.Labels {"function" : funcName , "node" : node .NodeIdentifier }).Observe (duration )
6854}
0 commit comments