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

legman-logstash

v1.0.0

Published

A writeable stream build for sending messages from a Legman stream into a Logstash instance

Downloads

4

Readme

Legman-Logstash

Legman-Logstash is a writeable stream build for sending messages from a Legman stream into a Logstash instance.

How to use in NodeJS

At first you have to install this module and Legman into your application:

npm i --save legman legman-logstash
# OR
yarn add legman legman-logstash

After that you can import and use LegmanLogstash in your code.

Using Legman with Logstash in TypeScript

import Legman from "legman";
import LegmanLogstash from "legman-logstash";

const logstashPort: number = 9500;
const logstashHostname: string | undefined = "logstash";
const logstash = new LegmanLogstash(logstashPort, logstashHostname);

const loggerLeg = new Legman({app: "Identifier for my application"});
loggerLeg
    .filter((message) => ["error", "warn", "info"].includes(message.loglevel)) // pre-filter messages for Logstash
    .pipe(logstash);
const httpLogger = loggerLeg.influx({context: "http"}, true);

app.get("/example", (req, res, next) => {
    httpLogger.write({
        msg: "Incoming request",
        loglevel: "info",
        path: req.url,
        method: req.method,
    });
    // ...
});

Using Legman with Logstash in JavaScript

const Legman = require("legman");
const LegmanLogstash = require("legman-logstash");

const logstashPort = 9500;
const logstashHostname = "logstash";
const logstash = new LegmanLogstash(logstashPort, logstashHostname);

const loggerLeg = new Legman({app: "Identifier for my application"});
loggerLeg
    .filter((message) => ["error", "warn", "info"].includes(message.loglevel)) // pre-filter messages for Logstash
    .pipe(logstash);
const httpLogger = loggerLeg.influx({context: "http"}, true);

app.get("/example", (req, res, next) => {
    httpLogger.write({
        msg: "Incoming request",
        loglevel: "info",
        path: req.url,
        method: req.method,
    });
    // ...
});

How to configure Logstash

Logstash should use the tcp input with json_lines codec. Take a look at the example and the docker-compose.yml.

Example configuration:

input { tcp { port => 9500 codec => json_lines } } output { elasticsearch { index => "example" hosts => ["elasticsearch:9200"] } }

Example

You can run a full integrated example with the ELK complete stack by running npm run docker:example. After that you can open Kibana with your browser on its default port 5601 on your docker host.

On your first visit you have to create an index for Elasticsearch with the help of Kibana. Click on Management and take the link to Index Patterns on the Kibana tab. Input example as index pattern and click next step. Select a timestamp from the dropdown menu. @timestamp is the one from Logstash and timestamp is the one from your application. I would recommend the timestamp property, because it is the timestamp when the message was emitted and not the timestamp when the message was received by Logstash.

The example will log random messages from NodeJS to Logstash to ElasticSearch to Kibana. The source code of the example is located at the ./example folder.

Script tasks

  • transpile: Transpiles the library from TypeScript into JavaScript with type declarations
  • lint: Lints your code against the recommend TSLint ruleset.
  • test: Transpiles, lints and runs software-tests with coverage.
  • leakage: Transpiles, lints and runs software-tests with leakage tests.
  • docker:lint: Runs the lint task in a docker environment.
  • docker:test: Runs the test task in a docker environment.
  • docker:leakage: Runs the leakage task in a docker environment.
  • docker:example: Runs an example within the docker environment.

License

This module is under ISC license copyright 2018 by Arne Schubert