[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 'zone.js/dist/zone-node';
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import { enableProdMode } from '@angular/core';
|
import {enableProdMode} from '@angular/core';
|
||||||
|
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import { join } from 'path';
|
import {join} from 'path';
|
||||||
import { readFileSync } from 'fs';
|
import {readFileSync} from 'fs';
|
||||||
|
|
||||||
// Faster server renders w/ Prod mode (dev mode never needed)
|
// Faster server renders w/ Prod mode (dev mode never needed)
|
||||||
enableProdMode();
|
enableProdMode();
|
||||||
|
@ -19,14 +19,16 @@ const DIST_FOLDER = join(process.cwd(), 'dist');
|
||||||
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
|
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
|
||||||
|
|
||||||
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
|
// * 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
|
// Express Engine
|
||||||
import {ngExpressEngine, RenderOptions} from '@nguniversal/express-engine';
|
import {ngExpressEngine, RenderOptions} from '@nguniversal/express-engine';
|
||||||
// Import module map for lazy loading
|
// 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 {routes} from "./routes";
|
||||||
import * as prom from "prom-client";
|
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)
|
// 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 register = new prom.Registry();
|
||||||
|
|
||||||
const counter = new prom.Counter({
|
const responses = new prom.Counter({
|
||||||
name: 'explore',
|
name: 'portal_http_responses_total',
|
||||||
help: 'Explore Counter',
|
help: 'A counter for portal response codes for every existed or not existed pages.',
|
||||||
labelNames: ['route'],
|
labelNames: ['route', 'code'],
|
||||||
registers: [register]
|
registers: [register]
|
||||||
});
|
});
|
||||||
|
|
||||||
const histogram = new prom.Histogram({
|
const histogram = new prom.Histogram({
|
||||||
name: 'exploreLatency',
|
name: 'portal_http_request_duration_seconds',
|
||||||
help: 'Explore Histogram',
|
help: 'A Histogram for a portal. Providing information about page visits and load latency in seconds.',
|
||||||
labelNames: ['route'],
|
labelNames: ['route'],
|
||||||
registers: [register],
|
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) => {
|
app.engine('html', (_, options: any, callback) => {
|
||||||
let engine = ngExpressEngine({
|
const opts = {
|
||||||
bootstrap: AppServerModuleNgFactory,
|
document: template,
|
||||||
providers: [
|
url: options.req.url,
|
||||||
{ provide: 'request', useFactory: () => options.req, deps: [] },
|
extraProviders: [
|
||||||
provideModuleMap(LAZY_MODULE_MAP)
|
provideModuleMap(LAZY_MODULE_MAP),
|
||||||
]
|
{
|
||||||
});
|
provide: REQUEST,
|
||||||
engine(_, options, callback);
|
useValue: options.req
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: RESPONSE,
|
||||||
|
useValue: options.req.res,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
renderModuleFactory(AppServerModuleNgFactory, opts)
|
||||||
|
.then(html => callback(null, html)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.set('view engine', 'html');
|
app.set('view engine', 'html');
|
||||||
|
@ -86,16 +99,19 @@ app.get('/metrics', (req, res) => {
|
||||||
|
|
||||||
// All regular routes use the Universal engine
|
// All regular routes use the Universal engine
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
if(routes.indexOf(req.path) !== -1) {
|
if (routes.indexOf(req.path) !== -1) {
|
||||||
const end = histogram.startTimer({route: req.path});
|
const end = histogram.startTimer({route: req.path});
|
||||||
counter.inc({route: req.path});
|
res.render('index', {req});
|
||||||
res.render('index', { req });
|
res.on('finish', function () {
|
||||||
res.on('finish', function() {
|
responses.inc({route: req.path, code: res.statusCode});
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.render('index', { req });
|
res.render('index', {req});
|
||||||
}
|
res.on('finish', function () {
|
||||||
|
responses.inc({route: '**', code: res.statusCode});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start up the Node server
|
// Start up the Node server
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
"piwikSiteId" : "6",
|
"piwikSiteId" : "6",
|
||||||
"loginUrl" :"http://rudie.di.uoa.gr:8080/dnet-login/openid_connect_login",
|
"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=",
|
"logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
"cacheUrl" :"http://scoobydoo.di.uoa.gr:3000/get?url=",
|
"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",
|
"adminToolsCommunity" :"openaire",
|
||||||
"datasourcesAPI": "https://beta.services.openaire.eu/openaire/ds/search/",
|
"datasourcesAPI": "https://beta.services.openaire.eu/openaire/ds/search/",
|
||||||
|
|
Loading…
Reference in New Issue