Git Product home page Git Product logo

pg-monitor's People

Contributors

alenjoseph avatar cone56 avatar dave-gray101 avatar greenkeeper[bot] avatar mauriciovigolo avatar ravinggenius avatar vitaly-t avatar vlindhol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pg-monitor's Issues

Milliseconds in timestamp

This is an awesome module.
Would it be possible to add an option to display the milliseconds in the timestamp? During debugging it sometimes comes in handy.
I added it as a default to my fork. However, when I tried figuring out how to add it as an option. I got stuck.
Thank you!

BigInt Support

With reference to #657 in pg-promise, which now supports BigInt, this module needs to be updated.

It uses JSON.stringify on query-formatting values in a few places, which does not support BigInt type, and will bomb out when you supply such values.

Get duration of a statement

I'm using this awesome module with massive.js. I'm wondering if it is possible to get a duration of a specific statement? Now I get event info displayed in this form:

14:59:07 connect(playground@playground)
14:59:07 SELECT COUNT(1) FROM "users"
WHERE TRUE LIMIT 1
14:59:07 disconnect(playground@playground)
14:59:07 connect(playground@playground)
14:59:07 SELECT * FROM "users"
WHERE "id" = 1 ORDER BY "id" LIMIT 10
14:59:07 disconnect(playground@playground)
14:59:07 connect(playground@playground)
14:59:07 SELECT * FROM "books"
WHERE "user_id" = 1 ORDER BY "id"
14:59:07 disconnect(playground@playground)

Typescript - needless module declaration

@vitaly-t, today I tried the recent version of pg-monitor, after the last commit - typescript 2 support.

I had problems to import the library because of the module declaration. In the way it is, it's happening the following:

import * as pgMonitor from 'pg-monitor';

pgMonitor.pgMonitor.attach(options); .. 

This situation is described in typescript - namespaces and modules doc.


Complementing, I tried to use as:

import { pgMonitor } from 'pg-monitor';

pgMonitor.attach(options); .. 

This will result an exception during runtime - "TypeError: Cannot read property 'attach' of undefined"

I will open a PR, ok?

extend setLog to allow disabling removeColors call

We really like the way logs are formatted by pg-monitor, but we also need to customize the logger. Currently, if you provide a custom log function, it will always call removeColors before it passes the message in. We want the colors though! We just also want to customize logging.

I played around with some options, and I wanted to get your thoughts to see if I should submit a PR.

I could change setLog to allow it to take either of:

  • log: function(msg, info) Current
  • options: { log: function(msg, info), removeColors: Boolean } New!

Setting options.removeColors to false could result in either:

  • msg is colored -but- info.text is plain
  • msg is colored -and- info.text is colored

Already, the two are slightly different in that info.text has .trim() called on the string, whereas msg does not; so, I'm not sure if you think they should also be differentiated in this way as well.

Usage would change to be able to look like this:

monitor.setLog({
    removeColors: false,
    log(msg, info) { /* ... */ }
});

This allows the best of both worlds, with output like this:
image

What do you think?

output not showing up in console

I've already been through the previous question #3.

I have the configurations setup according to the documentation, but I don't see any output to the console.

This is what I'm using right now

import pg from 'pg-promise';
import monitor from 'pg-monitor';

const options = {
  user: process.env.dbUser,
  database: process.env.dbName,
  password: process.env.dbPassword,
  port: process.env.dbPort,
  max: process.env.dbMaxClient,
  idleTimeoutMillis: process.env.dbIdleTimeout
};

const db = pg()(options);

monitor.attach(options);

Rewrite in TypeScript

This library was written as an addition to one of the earliest versions of pg-promise. At the time it was done a bit in a rush, and today its code looks a bit dated and messy.

I have done TypeScript conversion for a number of other modules, but this one was left for last, because its primary function is that of a development dependency, plus it has no bugs, hence the lower priority.

This will also create an opportunity for some breaking changes to improve the protocol.

Tagging queries without transactions?

Hi @vitaly-t

I was wondering if there is a way to tag a query that is not a task or transaction? I would like to provider a context id so that I know what http request has caused the query execution when I log it with pg-monitor. For example:

db.none('UPDATE ...', 'my-http-request-id')

... 


const log = (msg, info) => {
  logger.debug(`${info.event}: ${info.text}`, {
    sql: true,
    event: info.event,
    requestId: info.tag,
  });
  info.display = false;
};

Thanks in advance

can't seem to get output from pg-monitor

Sorry, I'm a total newbie at node.js - any help you can give would be appreciated.
I'm using express with massive.js, and wanted to use pg-monitor. I installed it and added these lines to app.js:

const monitor = require('pg-monitor');
monitor.attach({});

However, nothing appears on the console (or anywhere else that I can see) when I execute a query via massive. I've tried a few different things, but no luck. Is there a step I'm missing?

Thanks!

Add license?

Please consider adding a license to your code, so that developers looking to use it know the terms of that use.

A popular and common license you could consider would be: https://mit-license.org/

Pass custom logger

can i pass cutom logger we have customized bunyan logger and using it in all the application need to pass that logger to pg-monitor to log.info all the queries passed to pg promise

Disable Timestamp Support

Thank you for this amazing library. I was trying to do a diff between two outputs and every line conflicted due to timestamps. I wanted to know if there was a way to disable the timestamp and possibly duration.

Screen Shot 2021-03-10 at 9 07 39 AM

How to ignore unique constraint error messages?

Hello! I want to get rid of these messages from my errors.log:

05:58:40 error: duplicate key value violates unique constraint "usernames_pkey"
         task: INSERT INTO "usernames" ("username", "email") VALUES
         ('profile-creation-0', '[email protected]')

This how I handle the error in my controller:

try {
  await t.none(sql.usernames.insert, { username, email });
} catch (err) {
  if (typeof err === 'object'
      && err.code == '23505'
      && err.table == 'usernames'
      && err.constraint == 'usernames_pkey') {
    return ({
      error: {
        type: 'validation',
        username: 'Username taken.'
      }
    });
  }
  throw err;
}

This is my diagnostics.js:

const stack = require('callsite');
const os = require('os');
const fs = require('fs');
const path = require('path');
const monitor = require('pg-monitor');

module.exports = ({ mode, logFile }, initOptions) => {
  const $DEV = mode === 'development';

  const dirname = path.dirname(stack()[3].getFileName());
  logFile = path.resolve(dirname, logFile);

  monitor.setTheme('matrix');

  monitor.setLog((msg, info) => {

    // In a PROD environment we will only receive event 'error',
    // because this is how we set it up below.

    // And the check below is for DEV environment only, as we want to log
    // errors only, or else the file will grow out of proportion in no time.

    if (info.event === 'error') {
      let logText = os.EOL + msg; // line break + next error message;
      if (info.time) {
        // If it is a new error being reported,
        // and not an additional error line;
        logText = os.EOL + logText; // add another line break in front;
      }
      fs.appendFileSync(logFile, logText); // add error handling as required;
    }

    // We absolutely must not let the monitor write anything into the console
    // while in a PROD environment, and not just because nobody will be able
    // to see it there, but mainly because the console is incredibly slow and
    // hugely resource-consuming, suitable only for debugging.

    if (!$DEV) {
      // If it is not a DEV environment:
      info.display = false; // display nothing;
    }
  });

  if ($DEV) {
    // In a DEV environment, we attach to all supported events:
    monitor.attach(initOptions);
  } else {
    // In a PROD environment we should only attach to the type of events
    // that we intend to log. And we are only logging event 'error' here:
    monitor.attach(initOptions, ['error']);
  }
}

Thanks in advance. I'm loving pg-promise, pg-monitor and pg-minify. Great work!

add a general prefix

It would be great if there was an option to add a general prefix to the output. For instance:

var monitor = require("pg-monitor");
monitor.setPrefix("postgres: ");
monitor.attach();
// proceed with the call to pgpLib

Instead of

15:46:35 connect(clima@150601)
15:46:35 select * from maps_create('[{"id":1,"code":"energia_centrais"}]')
15:46:35 disconnect(clima@150601)

the output would be

15:46:35 postgres: connect(clima@150601)
15:46:35 postgres: select * from maps_create('[{"id":1,"code":"energia_centrais"}]')
15:46:35 postgres: disconnect(clima@150601)

Even better: allow simple customization of the date format:

monitor.setDateFormat("YYMMDD HH:MM:SS");
monitor.setDateFormat("HH:MM:SS");

etc

Display tags that are numbers.

In light of the soon-coming version 8.x of pg-promise, add displaying tags when they are numbers.

Currently, only strings are displayed. But tags can be simple numbers sometimes also.

output not showing up in console

Here is the code I am using to initialize pg-monitor:

    // postgres setup
    const pg_options = {
        host: 'localhost',
        port: 5432,
        database: 'test',
        user: 'dm',
        password: 'asdfasdf'
    };

    global.db = pgp(pg_options);

    // postgres monitoring
    require("pg-monitor").attach(pg_options);

Is there something that I am doing wrong?

no console output with Express?

I'm a bit stumped on how to get output from pg-monitor. I initialize pg-promise and pg-monitor and then use the db connection in Express.js route handlers. However, there is no console output. An example:

const pgp = require('pg-promise');
const monitor = require('pg-monitor');
const express = require('express');

const db = pgp()({ /* connection parameters */});
monitor.attach({});

const app = express();

app.use(/* routes using db.any etc to query the database */);

app.listen(8080, () => console.log('listening on 8080'));

// outputs "listening on 8080" and then nothing, even if HTTP requests are made and DB activity occurs

Is app.listen somehow blocking the output from pg-monitor or am I missing something else? I've been reading and re-reading the docs but I can't find anything obviously wrong ๐Ÿ˜…

default for white screen

None of defaults works in white bg screen. Ex. matrix white => black works fine. I have used over 20 years white bg and black fg. I'm sure I'm not only who has got enough dark bg and green or amber fg.

Of course you can make own theme, but it would be nice if some of defaults is usable also this kind of screens.

Ability to prevent console.log when custom logger provided

To prevent console.log when custom logger provided, I must mutate incoming config to prevent default behaviour. It isnt documented and wery stange setup method

monitor.setLog((msg, info) => {
    const { time, event, ...args } = info
    info.display = false
    logger.debug(event, args)
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.