@@ -3,10 +3,29 @@ const config = require('config');
3
3
const { Mutex, withTimeout, E_TIMEOUT } = require ( 'async-mutex' ) ;
4
4
const apiKeys = require ( './apiKey' ) ;
5
5
const path = require ( "path" ) ;
6
+ const opentelemetry = require ( "@opentelemetry/api" ) ;
6
7
const logger = require ( '../logger' ) . logger ;
7
8
8
9
const GET_LOCATIONS = 'http://www.webpagetest.org/getLocations.php?f=json' ;
9
10
11
+ const WstMeter = opentelemetry . metrics . getMeter ( 'default' ) ;
12
+ const locationMetrics = {
13
+ total : WstMeter . createGauge ( 'location.total' ) ,
14
+ lastUpdate : WstMeter . createGauge ( 'location.last_update' ) ,
15
+ ratio : WstMeter . createGauge ( 'location.ratio' ) ,
16
+ score : WstMeter . createGauge ( 'location.score' ) ,
17
+ selected : WstMeter . createGauge ( 'location.selected' ) ,
18
+ agent : {
19
+ total : WstMeter . createGauge ( 'location.agent.total' ) ,
20
+ idle : WstMeter . createGauge ( 'location.agent.idle' ) ,
21
+ queued : WstMeter . createGauge ( 'location.agent.queued' ) ,
22
+ highprio : WstMeter . createGauge ( 'location.agent.highprio' ) ,
23
+ lowprio : WstMeter . createGauge ( 'location.agent.lowprio' ) ,
24
+ testing : WstMeter . createGauge ( 'location.agent.testing' ) ,
25
+ blocking : WstMeter . createGauge ( 'location.agent.blocking' )
26
+ } ,
27
+ } ;
28
+
10
29
class LocationSelector {
11
30
constructor ( ) {
12
31
if ( ! LocationSelector . instance ) {
@@ -111,6 +130,26 @@ class LocationSelector {
111
130
this . location = this . getBestLocationId ( filtered ) ;
112
131
this . cachedAllLocations = filtered ;
113
132
this . lastUpdated = Date . now ( ) ;
133
+
134
+ // telemetry
135
+ locationMetrics . total . record ( this . cachedAllLocations . length ) ;
136
+ locationMetrics . lastUpdate . record ( this . lastUpdated ) ;
137
+ this . cachedAllLocations . forEach ( ( loc ) => {
138
+ let labels = { location : loc . location } ;
139
+
140
+ locationMetrics . ratio . record ( loc . PendingTests . TestAgentRatio , labels ) ;
141
+ locationMetrics . score . record ( loc . score , labels ) ;
142
+
143
+ locationMetrics . selected . record ( loc . location === this . location ? 1 : 0 , labels ) ;
144
+
145
+ locationMetrics . agent . total . record ( loc . PendingTests . Total , labels ) ;
146
+ locationMetrics . agent . idle . record ( loc . PendingTests . Idle , labels ) ;
147
+ locationMetrics . agent . queued . record ( loc . PendingTests . Queued , labels ) ;
148
+ locationMetrics . agent . highprio . record ( loc . PendingTests . HighPriority , labels ) ;
149
+ locationMetrics . agent . lowprio . record ( loc . PendingTests . LowPriority , labels ) ;
150
+ locationMetrics . agent . testing . record ( loc . PendingTests . Testing , labels ) ;
151
+ locationMetrics . agent . blocking . record ( loc . PendingTests . Blocking , labels ) ;
152
+ } ) ;
114
153
} ;
115
154
116
155
async getLocation ( ) {
0 commit comments