| 67 | } |
| 68 | |
| 69 | function postStats(managementEndpoint, instanceId, remoteToken, report, next) { |
| 70 | const toURL = `${managementEndpoint}/${instanceId}/stats`; |
| 71 | const toOptions = { |
| 72 | json: true, |
| 73 | headers: { |
| 74 | 'content-type': 'application/json', |
| 75 | 'x-instance-authentication-token': remoteToken, |
| 76 | }, |
| 77 | body: report, |
| 78 | }; |
| 79 | const toCallback = (err, response, body) => { |
| 80 | if (err) { |
| 81 | logger.info('could not post stats', { error: err }); |
| 82 | } |
| 83 | if (response && response.statusCode !== 201) { |
| 84 | logger.info('could not post stats', { |
| 85 | body, |
| 86 | statusCode: response.statusCode, |
| 87 | }); |
| 88 | } |
| 89 | if (next) { |
| 90 | next(null, instanceId, remoteToken); |
| 91 | } |
| 92 | }; |
| 93 | return request.post(toURL, toOptions, toCallback); |
| 94 | } |
| 95 | |
| 96 | function getStats(next) { |
| 97 | const fromURL = `http://localhost:${_config.port}/_/report`; |