File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ import promClient from 'prom-client' ;
1
2
import MetricRegistry from './MetricRegistry' ;
2
3
import GaugeMetric from './metric/GaugeMetric' ;
3
4
import Transport from './transport/Transport' ;
@@ -56,9 +57,22 @@ class UMetrics {
56
57
* @return UMetrics
57
58
*/
58
59
start ( ) {
60
+ if ( this . nodejsMetricsEnabled ) {
61
+ this . enableExportingDefaultMetrics ( ) ;
62
+ }
59
63
this . transport . start ( ) ;
60
64
return this ;
61
65
}
66
+
67
+ /**
68
+ * @private
69
+ */
70
+ enableExportingDefaultMetrics ( ) {
71
+ promClient . collectDefaultMetrics ( {
72
+ prefix : this . prefix ,
73
+ timeout : this . nodejsMetricsInterval ,
74
+ } ) ;
75
+ }
62
76
}
63
77
64
78
// Конструкторы метрик, как внешний интерфейс
Original file line number Diff line number Diff line change @@ -56,4 +56,34 @@ describe('UMetrics facade', () => {
56
56
} ) ;
57
57
expect ( uMetrics . nodejsMetricsInterval ) . to . be . equals ( 7000 ) ;
58
58
} ) ;
59
+
60
+ it ( 'Should enable default metrics exports if option provided' , ( ) => {
61
+ let calledCount = 0 ;
62
+ const uMetrics = new UMetrics ( new Transport ( ) , {
63
+ port : 1111 ,
64
+ nodejsMetricsEnabled : true ,
65
+ } ) ;
66
+
67
+ uMetrics . enableExportingDefaultMetrics = ( ) => {
68
+ calledCount += 1 ;
69
+ } ;
70
+
71
+ uMetrics . start ( ) ;
72
+ expect ( calledCount ) . to . be . equals ( 1 ) ;
73
+ } ) ;
74
+
75
+ it ( 'Should not enable default metrics exports if option is not provided' , ( ) => {
76
+ let calledCount = 0 ;
77
+ const uMetrics = new UMetrics ( new Transport ( ) , {
78
+ port : 1111 ,
79
+ nodejsMetricsEnabled : false ,
80
+ } ) ;
81
+
82
+ uMetrics . enableExportingDefaultMetrics = ( ) => {
83
+ calledCount += 1 ;
84
+ } ;
85
+
86
+ uMetrics . start ( ) ;
87
+ expect ( calledCount ) . to . be . equals ( 0 ) ;
88
+ } ) ;
59
89
} ) ;
You can’t perform that action at this time.
0 commit comments