1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-29 05:10:05 +02:00

fix leak<->prometheus integration

This commit is contained in:
Sérgio Ramos 2017-03-06 17:15:16 +00:00
parent 5e21ff1e64
commit f33f91988d
6 changed files with 1675 additions and 1107 deletions

View File

@ -53,7 +53,7 @@ services:
depends_on:
- plain-node
telemetry:
image: prom/prometheus
image: prom/prometheus:v1.5.2
ports:
- "9090:9090"
volumes:

View File

@ -5,63 +5,64 @@
"license": "private",
"main": "src/server/index.js",
"dependencies": {
"artillery": "^1.5.0-17",
"async": "^2.1.4",
"apr-map": "^1.0.3",
"artillery": "^1.5.2",
"async": "^2.1.5",
"build-array": "^1.0.0",
"chart.js": "^2.4.0",
"chart.js": "^2.5.0",
"date.js": "^0.3.1",
"epimetheus": "^1.0.46",
"force-array": "^3.1.0",
"good": "^7.0.2",
"good-console": "^6.3.1",
"good": "^7.1.0",
"good-console": "^6.4.0",
"good-squeeze": "^5.0.1",
"got": "^6.6.3",
"hapi": "^15.2.0",
"hapi-webpack-dev-plugin": "1.1.4",
"inert": "^4.0.2",
"got": "^6.7.1",
"hapi": "^16.1.0",
"hapi-webpack-dev-plugin": "1.2.0",
"inert": "^4.1.0",
"internet-timestamp": "^0.0.1",
"lodash.first": "^3.0.0",
"lodash.get": "^4.4.2",
"lodash.take": "^4.1.1",
"minimist": "^1.2.0",
"nes": "^6.3.1",
"nes": "^6.4.0",
"pretty-hrtime": "^1.0.3",
"prom-client": "^6.1.2",
"qs": "^6.3.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"prom-client": "^6.3.0",
"qs": "^6.4.0",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-hot-loader": "^3.0.0-beta.6",
"react-redux": "^4.4.6",
"react-redux": "^5.0.3",
"redux": "^3.6.0",
"redux-logger": "^2.7.4",
"redux-promise-middleware": "^4.1.0",
"redux-thunk": "^2.1.0",
"redux-logger": "^2.8.2",
"redux-promise-middleware": "^4.2.0",
"redux-thunk": "^2.2.0",
"relative-date": "^1.1.3",
"require-dir": "^0.3.1",
"simple-statistics": "^2.2.0"
"simple-statistics": "^2.5.0"
},
"devDependencies": {
"async": "^2.1.4",
"babel-core": "^6.18.2",
"async": "^2.1.5",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.8",
"babel-loader": "^6.4.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"diskusage": "^0.1.5",
"eslint": "^3.10.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"diskusage": "^0.2.1",
"eslint": "^3.17.0",
"eslint-config-semistandard": "^7.0.0",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-react": "^6.7.1",
"eslint-plugin-standard": "^2.0.1",
"eslint-config-standard": "^7.0.0",
"eslint-plugin-babel": "^4.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-standard": "^2.1.1",
"json-loader": "^0.5.4",
"os-utils": "^0.0.14",
"simple-statistics": "^2.2.0",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
"simple-statistics": "^2.5.0",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
}
}

View File

@ -1,17 +1,17 @@
scrape_configs:
- job_name: 'leak-fast'
scrape_interval: 1s
scrape_interval: 15s
static_configs:
- targets: ['fast-node:8000', 'another-fast-node:8000']
- job_name: 'leak-slow'
scrape_interval: 1s
scrape_interval: 15s
static_configs:
- targets: ['slow-node:8000']
- job_name: 'no-leak'
scrape_interval: 1s
scrape_interval: 15s
static_configs:
- targets: ['plain-node:8000']
- job_name: 'leak'
scrape_interval: 1s
static_configs:
- targets: ['fast-node:8000', 'another-fast-node:8000', 'slow-node:8000', 'plain-node:8000']
# - job_name: 'leak'
# scrape_interval: 1s
# static_configs:
# - targets: ['fast-node:8000', 'another-fast-node:8000', 'slow-node:8000', 'plain-node:8000']

View File

@ -1,3 +1,4 @@
const map = require('apr-map');
const forceArray = require('force-array');
const get = require('lodash.get');
const date = require('date.js');
@ -7,11 +8,7 @@ const url = require('url');
const qs = require('qs');
const transform = (res) => {
return forceArray(res).reduce((sum, r) => {
const {
data
} = JSON.parse(r.body);
return forceArray(res).reduce((sum, { data }) => {
const result = !Array.isArray(data)
? data.result
: data;
@ -33,12 +30,12 @@ const transform = (res) => {
} = metric;
const oldJob = get(sum, job, {});
const oldQuery = get(sum, `${job}.${__name__}`, {});
const oldInstance = get(sum, `${job}.${instance}`, {});
const _value = values.length ? values : value
return Object.assign(sum, {
[job]: Object.assign(oldJob, {
[instance]: Object.assign(oldQuery, {
[instance]: Object.assign(oldInstance, {
[__name__]: _value
})
})
@ -47,17 +44,17 @@ const transform = (res) => {
}, {});
};
const range = module.exports.range = ({
const range = module.exports.range = async ({
query = [],
ago = '1h ago',
step = '1s',
step = '15s',
hostname = 'localhost'
}) => {
const end = timestamp(new Date());
const start = timestamp(date(ago));
return Promise.all(query.map((query) => {
return got(url.format({
const ranges = await map(query, async (query) => {
return await got(url.format({
protocol: 'http:',
slashes: true,
port: '9090',
@ -69,17 +66,20 @@ const range = module.exports.range = ({
step,
start
}
}));
}))
.then(transform);
}))
});
return transform(
ranges.map((range) => JSON.parse(range.body))
);
};
const query = module.exports.query = ({
const query = module.exports.query = async ({
hostname = 'localhost',
query = []
}) => {
return Promise.all(query.map((query) => {
return got(url.format({
const res = await map(query, async (query) => {
return await got(url.format({
protocol: 'http:',
slashes: true,
port: '9090',
@ -88,16 +88,19 @@ const query = module.exports.query = ({
query: {
query: query
}
}));
}))
.then(transform);
}))
});
return transform(
res.map((res) => JSON.parse(res.body))
);
};
const tree = module.exports.tree = ({
const tree = module.exports.tree = async ({
hostname = 'localhost',
query = []
}) => {
return got(url.format({
const res = await got(url.format({
protocol: 'http:',
slashes: true,
port: '9090',
@ -108,8 +111,9 @@ const tree = module.exports.tree = ({
}, {
arrayFormat: 'brackets'
})
}))
.then(transform);
}));
return transform(res);
};
if (!module.parent) {
@ -120,7 +124,7 @@ if (!module.parent) {
const usage = () => {
console.error(`
Usage: node metrics.js --type={type} --query={metric} --step={step} --ago={ago}
node metrics.js --type=range --query=node_memory_heap_used_bytes --query=node_memory_heap_total_bytes
node scripts/prometheus.js --type=range --query=node_memory_heap_used_bytes --query=node_memory_heap_total_bytes
`.trim());
return process.exit(1);

View File

@ -1,8 +1,6 @@
const webpack = require('webpack');
const path = require('path');
const cfg = require('../webpack.config.js');
module.exports = [
require('inert'),
require('nes'), {
@ -21,10 +19,4 @@ module.exports = [
}, 'stdout']
}
}
}, {
register: require('hapi-webpack-dev-plugin'),
options: {
compiler: webpack(cfg),
devIndex: path.join(__dirname, '../static')
}
}];

File diff suppressed because it is too large Load Diff