[Trunk|Explore]: 1. Modify prometheus usage: Remove counters and a routes variable. 2. Create a Counter and a Histogram with label route. 3. At every request of a route, counter with label the specific route is increased by 1 and latency is observed at Histogram with the same logic.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@56033 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-06-10 08:48:37 +00:00
parent d8c7ab76f7
commit e4e2758a9c
3 changed files with 70 additions and 218 deletions

View File

@ -1,200 +0,0 @@
import * as prom from 'prom-client';
export class Prometheus {
register = new prom.Registry();
counters: Map<string, prom.Counter> = new Map<string, prom.Counter>([
["/", new prom.Counter({
name: 'home',
help: 'Home Page Counter',
registers: [this.register]
})],
["/search/publication", new prom.Counter({
name: 'search_publication',
help: 'Publication Landing Page Counter',
registers: [this.register]
})],
["/search/dataset", new prom.Counter({
name: 'search_dataset',
help: 'Dataset Landing Page Counter',
registers: [this.register]
})],
["/search/software", new prom.Counter({
name: 'search_software',
help: 'Software Landing Page Counter',
registers: [this.register]
})],
["/search/other", new prom.Counter({
name: 'search_other',
help: 'Other Landing Page Counter',
registers: [this.register]
})],
["/search/project", new prom.Counter({
name: 'search_project',
help: 'Project Landing Page Counter',
registers: [this.register]
})],
["/search/dataprovider", new prom.Counter({
name: 'search_dataprovider',
help: 'DataProvider Landing Page Counter',
registers: [this.register]
})],
["/search/organization", new prom.Counter({
name: 'search_organization',
help: 'organization Landing Page Counter',
registers: [this.register]
})],
["/participate/deposit-datasets", new prom.Counter({
name: 'participate_deposit_datasets',
help: 'Participate Deposit Datasets Page Counter',
registers: [this.register]
})],
["/participate/deposit-datasets-result", new prom.Counter({
name: 'participate_deposit_datasets_result',
help: 'Participate Deposit Datasets Result Page Counter',
registers: [this.register]
})],
["/participate/deposit-subject-result", new prom.Counter({
name: 'participate_deposit_subject_result',
help: 'Participate Deposit Subject Result Page Counter',
registers: [this.register]
})],
["/participate/deposit-publications", new prom.Counter({
name: 'participate_deposit_publications',
help: 'Participate Deposit Publications Page Counter',
registers: [this.register]
})],
["/participate/deposit-publications-result", new prom.Counter({
name: 'participate_deposit_publications_result',
help: 'Participate Deposit Publications Result Page Counter',
registers: [this.register]
})],
["/search/find", new prom.Counter({
name: 'search_find',
help: 'Main Search Page Counter',
registers: [this.register]
})],
["/search/find/publications", new prom.Counter({
name: 'search_find_publications',
help: 'Publications Search Page Counter',
registers: [this.register]
})],
["/search/find/datasets", new prom.Counter({
name: 'search_find_datasets',
help: 'Datasets Search Page Counter',
registers: [this.register]
})],
["/search/find/software", new prom.Counter({
name: 'search_find_software',
help: 'Software Search Page Counter',
registers: [this.register]
})],
["/search/find/other", new prom.Counter({
name: 'search_find_other',
help: 'Other Search Page Counter',
registers: [this.register]
})],
["/search/find/projects", new prom.Counter({
name: 'search_find_projects',
help: 'Projects Search Page Counter',
registers: [this.register]
})],
["/search/find/dataproviders", new prom.Counter({
name: 'search_find_dataproviders',
help: 'DataProviders Search Page Counter',
registers: [this.register]
})],
["/search/find/organizations", new prom.Counter({
name: 'search_find_organizations',
help: 'Organizations Search Page Counter',
registers: [this.register]
})],
["/search/content-providers", new prom.Counter({
name: 'search_content_providers',
help: 'Repositories Search Page Counter',
registers: [this.register]
})],
["/search/content-providers-table", new prom.Counter({
name: 'search_content_providers_table',
help: 'Repositories Search Page Table Counter',
registers: [this.register]
})],
["/search/entity-registries", new prom.Counter({
name: 'search_entity_registries',
help: 'Registries Search Page Counter',
registers: [this.register]
})],
["/search/entity-registries-table", new prom.Counter({
name: 'search_entity_registries_table',
help: 'Registries Search Page Table Counter',
registers: [this.register]
})],
["/search/journals", new prom.Counter({
name: 'search_journals',
help: 'Journals Search Page Counter',
registers: [this.register]
})],
["/search/journals-table", new prom.Counter({
name: 'search_journals_table',
help: 'Journals Search Page Table Counter',
registers: [this.register]
})],
["/search/advanced/publications", new prom.Counter({
name: 'search_advanced_publications',
help: 'Publications Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/datasets", new prom.Counter({
name: 'search_advanced_datasets',
help: 'Datasets Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/software", new prom.Counter({
name: 'search_advanced_software',
help: 'Software Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/other", new prom.Counter({
name: 'search_advanced_other',
help: 'Other Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/projects", new prom.Counter({
name: 'search_advanced_projects',
help: 'Projects Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/dataproviders", new prom.Counter({
name: 'search_advanced_dataproviders',
help: 'DataProviders Advanced Search Page Counter',
registers: [this.register]
})],
["/search/advanced/organizations", new prom.Counter({
name: 'search_advanced_organizations',
help: 'Organizations Advanced Search Page Counter',
registers: [this.register]
})],
["/myclaims", new prom.Counter({
name: 'my_claims',
help: 'My Claims Page Counter',
registers: [this.register]
})],
["/claims", new prom.Counter({
name: 'claims',
help: 'Admin Claims Page Counter',
registers: [this.register]
})],
["/participate/claim", new prom.Counter({
name: 'participate_claim',
help: 'Linking Page Counter',
registers: [this.register]
})],
["/participate/direct-claim", new prom.Counter({
name: 'participate_direct_claim',
help: 'Direct Linking Page Counter',
registers: [this.register]
})]
]);
}

40
explore/routes.ts Normal file
View File

@ -0,0 +1,40 @@
export const routes = [
'/',
'/search/publication',
'/search/dataset',
'/search/software',
'/search/other',
'/search/project',
'/search/dataprovider',
'/search/organization',
'/participate/deposit-datasets',
'/participate/deposit-datasets-result',
'/participate/deposit-subject-result',
'/participate/deposit-publications',
'/participate/deposit-publications-result',
'/search/find',
'/search/find/publications',
'/search/find/datasets',
'/search/find/software',
'/search/find/other',
'/search/find/projects',
'/search/find/dataproviders',
'/search/find/organizations',
'/search/content-providers',
'/search/content-providers-table',
'/search/entity-registries',
'/search/entity-registries-table',
'/search/journals',
'/search/journals-table',
'/search/advanced/publications',
'/search/advanced/datasets',
'/search/advanced/software',
'/search/advanced/other',
'/search/advanced/organizations',
'/search/advanced/dataproviders',
'/search/advanced/projects',
'/myclaims',
'/claims',
'/participate/claim',
'/participate/direct-claim',
];

View File

@ -1,6 +1,5 @@
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
@ -26,8 +25,8 @@ const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/mai
import {ngExpressEngine, RenderOptions} from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import {Prometheus} from "./prometheus";
import {Counter} from "prom-client";
import {routes} from "./routes";
import * as prom from "prom-client";
/*
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
@ -40,7 +39,22 @@ app.engine('html', ngExpressEngine({
*/
// be able to get request and get domain from there
const prometheus: Prometheus = new Prometheus();
const register = new prom.Registry();
const counter = new prom.Counter({
name: 'explore',
help: 'Explore Counter',
labelNames: ['route'],
registers: [register]
});
const histogram = new prom.Histogram({
name: 'exploreLatency',
help: 'Explore Histogram',
labelNames: ['route'],
registers: [register],
buckets: [0.5, 1, 5, 10]
});
app.engine('html', (_, options:RenderOptions, callback) => {
let engine = ngExpressEngine({
@ -66,24 +80,22 @@ app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
}));
app.get('/metrics', (req, res) => {
res.set('Content-Type', prometheus.register.contentType);
res.end(prometheus.register.metrics());
res.set('Content-Type', register.contentType);
res.end(register.metrics());
});
// All regular routes use the Universal engine
app.get('*', (req, res) => {
let start = new Date();
let counter: Counter = prometheus.counters.get(req.path);
if(counter !== undefined) {
counter.inc(1, new Date());
res.render('index', { req });
// event triggers when express is done sending response
res.on('finish', function() {
// console.log(new Date().getTime() - start.getTime());
});
} else {
res.render('index', { req });
}
if(routes.indexOf(req.path) !== -1) {
const end = histogram.startTimer({route: req.path});
counter.inc({route: req.path});
res.render('index', { req });
res.on('finish', function() {
end();
});
} else {
res.render('index', { req });
}
});
// Start up the Node server