npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@balena/logwatcher

v1.0.11

Published

Logwatcher monitors journald logs and notifies external services on matching keywords

Downloads

93

Readme

logwatcher

A tool to watch journald events and send any events that match configured keywords to Sentry or Sentry-compatible services.

Usage

To use this image, create a service in your docker-compose.yml as shown below:

version: "2.1"

services:
  logwatcher:
    image: bh.cr/logwatcher/logwatcher-armv7hl
    labels:
      io.balena.features.journal-logs: '1'
    restart: unless_stopped

Example

version: '2.1'

services:
  logwatcher:
    image: bh.cr/logwatcher/logwatcher-armv7hl
    environment:
      DEBUG: 1
      SENTRY_DSN: https://[email protected]/123456
      LW_Timeout: Schema query timeout
    labels:
      io.balena.features.journal-logs: '1'
    restart: unless-stopped
  app:
    image: balenalib/armv7hf-debian
    command: >
      /bin/bash -c 'while true; do echo "[Unhandled Server Error] Schema query timeout"; sleep 3; done'
    restart: unless-stopped

Currently, the following images are available for use:

  • bh.cr/logwatcher/logwatcher-armv7hl
  • bh.cr/logwatcher/logwatcher-amd64
  • bh.cr/logwatcher/logwatcher-aarch64

Customisation

bh.cr/gh_monarci/logwatcher can be configured via the following variables:

| Environment Variable | Default | Description | | --------------------------- | ------ | -----------------------------------------------------| | SENTRY_DSN | none | DSN for sending logs to Sentry service | | SENTRY_TRACES_SAMPLE_RATE | 1.0 | Sentry traces sample rate | | LW_LEVEL_DEFAULT | none | Default minimum log level that creates an event | | DEBUG | none | Output debug logs, 1 to enable |

Set any keywords to match with fingerprints with LW_<fingerprint> environment variables.

For example, setting LW_DatabaseError to "Failed to connect to database", would send any event messages that contain the phrase Failed to connect to database with the fingerprint DatabaseError.

You can set multiple phrases to match to the same fingerprint by separating them with commas.

Example setup

This setup causes all entries with level error to be created as Sentry issues.

LW_all=.*
LW_LEVEL_DEFAULT=error

Event grouping and deduplication

Sentry groups similar and duplicate events into issues, using a technique called 'fingerprinting'. Events with the same fingerprint are grouped together into an issue.

For each event that logwatcher retrieves from the logs it will add a fingerprint that contains:

  • fingerprint name if specified on the LW_* env vars; for example with the above definition it will add all
  • event SYSLOG_IDENTIFIER : syslog identifier string
  • event _EXE : the executable path
  • event message : event message. If the event is in docker logfmt format, this will be the value of msg. Otherwise is the full message

Error messages format

logwatcher needs to extract two basic bits of information: error message and error level. The error level is the main configurable aspect of logwatcher as it defines at which level errors are sent to Sentry/Glitch. This is done with the env var LW_LEVEL_DEFAULT.

logwatcher receives journald events which have PRIORITY and _MESSAGE properties that can be directly mapped to Sentry/Glitch event properties. Alas, most applications don't log through journalctl but simply write to stdout. logwatcher receives the logging events from other applications as journalctl events but the PRIORITY information is useless as is always INFO. So, in order to detect the intended error level logwatcher needs to parse the error message.

The good thing about logging aspects is that there are many standard formats to choose from!. Some formats are defined by the language or logging library; other applications use arbitrary logging formats.

Extracting this information is currently done by trying a set of RegEx, from most specific to more generic, until one matches. If none matches, logwatcher uses INFO.

You can check the ReExs at [./lib/eventConverter.ts]

Setting env vars

You can refer to the docs on how to set environment or service variables

Alternatively, you can set them in the docker-compose.yml or Dockerfile.template files.