[Explore]: Change metrics base on ICM suggestions.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@57441 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
e6b5e916cd
commit
382a322100
|
@ -1,10 +1,10 @@
|
|||
import 'zone.js/dist/zone-node';
|
||||
import 'reflect-metadata';
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import {enableProdMode} from '@angular/core';
|
||||
|
||||
import * as express from 'express';
|
||||
import { join } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import {join} from 'path';
|
||||
import {readFileSync} from 'fs';
|
||||
|
||||
// Faster server renders w/ Prod mode (dev mode never needed)
|
||||
enableProdMode();
|
||||
|
@ -19,14 +19,16 @@ const DIST_FOLDER = join(process.cwd(), 'dist');
|
|||
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
|
||||
|
||||
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
|
||||
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
|
||||
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
|
||||
|
||||
// Express Engine
|
||||
import {ngExpressEngine, RenderOptions} from '@nguniversal/express-engine';
|
||||
// Import module map for lazy loading
|
||||
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
|
||||
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
|
||||
import {routes} from "./routes";
|
||||
import * as prom from "prom-client";
|
||||
import {REQUEST, RESPONSE} from "@nguniversal/express-engine/tokens";
|
||||
import {renderModuleFactory} from "@angular/platform-server";
|
||||
|
||||
/*
|
||||
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
|
||||
|
@ -41,30 +43,41 @@ app.engine('html', ngExpressEngine({
|
|||
|
||||
const register = new prom.Registry();
|
||||
|
||||
const counter = new prom.Counter({
|
||||
name: 'explore',
|
||||
help: 'Explore Counter',
|
||||
labelNames: ['route'],
|
||||
const responses = new prom.Counter({
|
||||
name: 'portal_http_responses_total',
|
||||
help: 'A counter for portal response codes for every existed or not existed pages.',
|
||||
labelNames: ['route', 'code'],
|
||||
registers: [register]
|
||||
});
|
||||
|
||||
const histogram = new prom.Histogram({
|
||||
name: 'exploreLatency',
|
||||
help: 'Explore Histogram',
|
||||
const histogram = new prom.Histogram({
|
||||
name: 'portal_http_request_duration_seconds',
|
||||
help: 'A Histogram for a portal. Providing information about page visits and load latency in seconds.',
|
||||
labelNames: ['route'],
|
||||
registers: [register],
|
||||
buckets: [0.5, 1, 2, 3, 4, 5]
|
||||
buckets: [0.1, 0.2, 0.5, 1, 2]
|
||||
});
|
||||
|
||||
app.engine('html', (_, options:RenderOptions, callback) => {
|
||||
let engine = ngExpressEngine({
|
||||
bootstrap: AppServerModuleNgFactory,
|
||||
providers: [
|
||||
{ provide: 'request', useFactory: () => options.req, deps: [] },
|
||||
provideModuleMap(LAZY_MODULE_MAP)
|
||||
]
|
||||
});
|
||||
engine(_, options, callback);
|
||||
app.engine('html', (_, options: any, callback) => {
|
||||
const opts = {
|
||||
document: template,
|
||||
url: options.req.url,
|
||||
extraProviders: [
|
||||
provideModuleMap(LAZY_MODULE_MAP),
|
||||
{
|
||||
provide: REQUEST,
|
||||
useValue: options.req
|
||||
},
|
||||
{
|
||||
provide: RESPONSE,
|
||||
useValue: options.req.res,
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
renderModuleFactory(AppServerModuleNgFactory, opts)
|
||||
.then(html => callback(null, html)
|
||||
);
|
||||
});
|
||||
|
||||
app.set('view engine', 'html');
|
||||
|
@ -86,16 +99,19 @@ app.get('/metrics', (req, res) => {
|
|||
|
||||
// All regular routes use the Universal engine
|
||||
app.get('*', (req, res) => {
|
||||
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 });
|
||||
}
|
||||
if (routes.indexOf(req.path) !== -1) {
|
||||
const end = histogram.startTimer({route: req.path});
|
||||
res.render('index', {req});
|
||||
res.on('finish', function () {
|
||||
responses.inc({route: req.path, code: res.statusCode});
|
||||
end();
|
||||
});
|
||||
} else {
|
||||
res.render('index', {req});
|
||||
res.on('finish', function () {
|
||||
responses.inc({route: '**', code: res.statusCode});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Start up the Node server
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
"piwikSiteId" : "6",
|
||||
"loginUrl" :"http://rudie.di.uoa.gr:8080/dnet-login/openid_connect_login",
|
||||
|
||||
"userInfoUrl" : "http://rudie.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
|
||||
"userInfoUrl" : "http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
|
||||
|
||||
"logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
|||
|
||||
"cacheUrl" :"http://scoobydoo.di.uoa.gr:3000/get?url=",
|
||||
|
||||
"adminToolsAPIURL" :"http://duffy.di.uoa.gr:8080/uoa-admin-tools/",
|
||||
"adminToolsAPIURL" :"http://mpagasas.di.uoa.gr:8080/uoa-admin-tools/",
|
||||
|
||||
"adminToolsCommunity" :"openaire",
|
||||
"datasourcesAPI": "https://beta.services.openaire.eu/openaire/ds/search/",
|
||||
|
|
Loading…
Reference in New Issue