From d93315b22cd568eb02ffa980c260f0f3dcfdd7b5 Mon Sep 17 00:00:00 2001 From: les Date: Tue, 9 Feb 2021 12:17:39 +0100 Subject: [PATCH] start prometheus metrics --- nuxt.config.js | 23 ++++++++++++++++++++++- package.json | 28 ++++++++++++++++------------ server/api/controller/metrics.js | 7 +++++++ server/metrics.js | 9 +++++++++ server/routes.js | 5 +++++ 5 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 server/api/controller/metrics.js create mode 100644 server/metrics.js diff --git a/nuxt.config.js b/nuxt.config.js index 7a428010..f8889f8f 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,7 +1,9 @@ const conf = require('config') +const { format, transports } = require('winston') module.exports = { telemetry: false, + modern: (process.env.NODE_ENV === 'production') && 'client', /* ** Headers of the page */ @@ -60,8 +62,27 @@ module.exports = { ['nuxt-express-module', { expressPath: 'server/', routesPath: 'server/routes' }], // Doc: https://axios.nuxtjs.org/usage '@nuxtjs/axios', - '@nuxtjs/auth' + '@nuxtjs/auth', + 'nuxt-winston-log' ], + + // configure nuxt-winston-log module + winstonLog: { + skipRequestMiddlewareHandler: true, + useDefaultLogger: false, + loggerOptions: { + transports: process.env.NODE_ENV !== 'production' + ? [new transports.Console( + { level: 'debug', format: format.combine(format.simple(), format.errors({ stack: true })) } + )] + : [new transports.File( + { + filename: 'gancio.log', + format: format.combine(format.simple(), format.errors({ stack: true })) + } + )] + } + }, /* ** Axios module configuration * See https://github.com/nuxt-community/axios-module#options diff --git a/package.json b/package.json index 4d6e2ba7..f5a52ef8 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,14 @@ "scripts": { "build": "nuxt build", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", - "dev": "cross-env DEBUG=*,-babel*,-preview-email,-i18n:debug,-email-templates,-follow-redirects,-send,-body-parser:*,-express:*,-connect:*,-sequelize:* NODE_ENV=development node server/index.js", - "dev:nuxt": "cross-env NODE_ENV=development nuxt dev", + "dev": "NODE_ENV=development node server/index.js", + "dev:nuxt": "cross-env NODE_ENV=development nuxt dev --modern", "doc": "cd docs && bundle exec jekyll b", "doc:dev": "cd docs && bundle exec jekyll s --drafts", "migrate": "NODE_ENV=production sequelize db:migrate", "migrate:dev": "sequelize db:migrate", - "start": "cross-env DEBUG=*,-babel*,-preview-email,-i18n:debug,-email-templates,-follow-redirects,-send,-body-parser:*,-express:*,-connect:*,-sequelize:* NODE_ENV=production node server/cli.js" + "start:debug": "cross-env DEBUG=* NODE_ENV=production node server/cli.js", + "start": "NODE_ENV=production node server/cli.js" }, "files": [ "server/", @@ -44,6 +45,7 @@ "email-templates": "^8.0.3", "express": "^4.17.1", "express-oauth-server": "^2.0.0", + "express-prom-bundle": "^6.3.1", "fs": "^0.0.1-security", "http-signature": "^1.3.5", "ical.js": "^1.4.0", @@ -51,7 +53,7 @@ "inquirer": "^7.3.3", "jsdom": "^16.4.0", "jsonwebtoken": "^8.5.1", - "less": "^4.1.0", + "less": "^4.1.1", "linkifyjs": "^2.1.9", "lodash": "^4.17.20", "microformat-node": "^2.0.1", @@ -61,16 +63,18 @@ "multer": "^1.4.2", "nuxt": "^2.14.12", "nuxt-express-module": "^0.0.11", + "nuxt-winston-log": "^1.2.0", "pg": "^8.5.1", - "sequelize": "^6.4.0", + "prom-client": "^13.1.0", + "sequelize": "^6.5.0", "sequelize-cli": "^6.2.0", - "sharp": "^0.27.0", + "sharp": "^0.27.1", "sqlite3": "^5.0.1", - "tiptap": "^1.31.0", - "tiptap-extensions": "^1.34.0", + "tiptap": "^1.32.0", + "tiptap-extensions": "^1.35.0", "to-ico": "^1.1.5", "url": "^0.11.0", - "v-calendar": "^2.2.1", + "v-calendar": "^2.2.2", "vue-clipboard2": "^0.3.1", "vue-i18n": "^8.22.4", "yargs": "^16.1.1" @@ -80,7 +84,7 @@ "@nuxtjs/eslint-config": "^5.0.0", "@nuxtjs/vuetify": "^1.11.3", "babel-eslint": "^10.1.0", - "eslint": "^7.18.0", + "eslint": "^7.19.0", "eslint-config-prettier": "^7.2.0", "eslint-config-standard": "^16.0.2", "eslint-loader": "^4.0.2", @@ -97,8 +101,8 @@ "pug-plain-loader": "^1.1.0", "sass": "^1.32.5", "sass-loader": "^10.1.1", - "vue-cli-plugin-vuetify": "~2.0.9", - "vuetify-loader": "^1.3.0", + "vue-cli-plugin-vuetify": "~2.1.0", + "vuetify-loader": "^1.7.1", "webpack-cli": "^4.4.0" }, "resolutions": { diff --git a/server/api/controller/metrics.js b/server/api/controller/metrics.js new file mode 100644 index 00000000..f4b5ec08 --- /dev/null +++ b/server/api/controller/metrics.js @@ -0,0 +1,7 @@ +const User = require('../models/user') + +const metrics = { + +} + +module.exports = metrics diff --git a/server/metrics.js b/server/metrics.js new file mode 100644 index 00000000..92e3054a --- /dev/null +++ b/server/metrics.js @@ -0,0 +1,9 @@ +// const promClient = require('prom-client') + +// promClient.Gauge({ +// name: '' +// }) + +// module.exports = { + +// } \ No newline at end of file diff --git a/server/routes.js b/server/routes.js index acf16be6..e1fa68f3 100644 --- a/server/routes.js +++ b/server/routes.js @@ -13,6 +13,9 @@ const debug = require('debug')('routes') const exportController = require('./api/controller/export') const eventController = require('./api/controller/event') const announceController = require('./api/controller/announce') +// const metricsController = require('./metrics') +const promBundle = require('express-prom-bundle') +const metricsMiddleware = promBundle({ includeMethod: true }) const helpers = require('./helpers') const app = express() @@ -20,6 +23,8 @@ const app = express() // ignore unimplemented ping url from fediverse app.use(spamFilter) +app.use(metricsMiddleware) + app.use((req, res, next) => { debug(req.method, req.path) next()