|
| 1 | +/* jshint globalstrict:false, strict:false, maxlen: 200 */ |
| 2 | +/* global assertEqual, assertTrue */ |
| 3 | + |
| 4 | +// ////////////////////////////////////////////////////////////////////////////// |
| 5 | +// / DISCLAIMER |
| 6 | +// / |
| 7 | +// / Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 8 | +// / |
| 9 | +// / Licensed under the Apache License, Version 2.0 (the "License") <
A3D4
/code> |
| 10 | +// / you may not use this file except in compliance with the License. |
| 11 | +// / You may obtain a copy of the License at |
| 12 | +// / |
| 13 | +// / http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// / |
| 15 | +// / Unless required by applicable law or agreed to in writing, software |
| 16 | +// / distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// / See the License for the specific language governing permissions and |
| 19 | +// / limitations under the License. |
| 20 | +// / |
| 21 | +// / Copyright holder is triAGENS GmbH, Cologne, Germany |
| 22 | +// / |
| 23 | +// / @author Jan Steemann |
| 24 | +// ////////////////////////////////////////////////////////////////////////////// |
| 25 | + |
| 26 | +let jsunity = require('jsunity'); |
| 27 | +let internal = require('internal'); |
| 28 | +const request = require('@arangodb/request'); |
| 29 | + |
| 30 | +function getEndpointsByType(type) { |
| 31 | + const isType = (d) => (d.role.toLowerCase() === type); |
| 32 | + const toEndpoint = (d) => (d.endpoint); |
| 33 | + const endpointToURL = (endpoint) => { |
| 34 | + if (endpoint.substr(0, 6) === 'ssl://') { |
| 35 | + return 'https://' + endpoint.substr(6); |
| 36 | + } |
| 37 | + let pos = endpoint.indexOf('://'); |
| 38 | + if (pos === -1) { |
| 39 | + return 'http://' + endpoint; |
| 40 | + } |
| 41 | + return 'http' + endpoint.substr(pos); |
| 42 | + }; |
| 43 | + |
| 44 | + const instanceInfo = JSON.parse(internal.env.INSTANCEINFO); |
| 45 | + return instanceInfo.arangods.filter(isType) |
| 46 | + .map(toEndpoint) |
| 47 | + .map(endpointToURL); |
| 48 | +} |
| 49 | + |
| 50 | +function getMetric(endpoint, name) { |
| 51 | + let res = request.get({ |
| 52 | + url: endpoint + '/_admin/metrics', |
| 53 | + }); |
| 54 | + let re = new RegExp("^" + name); |
| 55 | + let matches = res.body.split('\n').filter((line) => !line.match(/^#/)).filter((line) => line.match(re)); |
| 56 | + if (!matches.length) { |
| 57 | + throw "Metric " + name + " not found"; |
| 58 | + } |
| 59 | + return Number(matches[0].replace(/^.*? (\d+(\.\d+)?)$/, '$1')); |
| 60 | +} |
| 61 | + |
| 62 | +function processMetricsSuite() { |
| 63 | + 'use strict'; |
| 64 | + |
| 65 | + const metrics = [ |
| 66 | + "arangodb_process_statistics_user_time", |
| 67 | + "arangodb_process_statistics_system_time", |
| 68 | + "arangodb_process_statistics_number_of_threads", |
| 69 | + "arangodb_process_statistics_resident_set_size", |
| 70 | + "arangodb_process_statistics_virtual_memory_size", |
| 71 | + ]; |
| 72 | + |
| 73 | + return { |
| 74 | + |
| 75 | + testMetricsOnAgent: function () { |
| 76 | + let endpoints = getEndpointsByType('agent'); |
| 77 | + assertTrue(endpoints.length > 0); |
| 78 | + |
| 79 | + endpoints.forEach((ep) => { |
| 80 | + metrics.forEach((m) => { |
| 81 | + let value = getMetric(ep, m); |
| 82 | + assertEqual("number", typeof value); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }, |
| 86 | + |
| 87 | + testMetricsOnCoordinator: function () { |
| 88 | + let endpoints = getEndpointsByType('coordinator'); |
| 89 | + assertTrue(endpoints.length > 0); |
| 90 | + |
| 91 | + endpoints.forEach((ep) => { |
| 92 | + metrics.forEach((m) => { |
| 93 | + let value = getMetric(ep, m); |
| 94 | + assertEqual("number", typeof value); |
| 95 | + }); |
| 96 | + }); |
| 97 | + }, |
| 98 | + |
| 99 | + testMetricsOnDBServer: function () { |
| 100 | + let endpoints = getEndpointsByType('dbserver'); |
| 101 | + assertTrue(endpoints.length > 0); |
| 102 | + |
| 103 | + endpoints.forEach((ep) => { |
| 104 | + metrics.forEach((m) => { |
| 105 | + let value = getMetric(ep, m); |
| 106 | + assertEqual("number", typeof value); |
| 107 | + }); |
| 108 | + }); |
| 109 | + }, |
| 110 | + |
| 111 | + }; |
| 112 | +} |
| 113 | + |
| 114 | +jsunity.run(processMetricsSuite); |
| 115 | +return jsunity.done(); |
0 commit comments