@myunisoft/loki
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

Loki

Node.js Grafana API SDK (Loki, Datasources ..)

npm version license ossf scorecard github ci workflow size

🚧 Requirements

🚀 Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn

$ npm i @myunisoft/loki
# or
$ yarn add @myunisoft/loki

📚 Usage

import { GrafanaApi } from "@myunisoft/loki";
import { LogQL, StreamSelector } from "@sigyn/logql";

const api = new GrafanaApi({
  // Note: if not provided, it will load process.env.GRAFANA_API_TOKEN
  apiToken: "...",
  remoteApiURL: "https://name.loki.com"
});

const ql = new LogQL(
  new StreamSelector({ app: "serviceName", env: "production" })
);
const logs = await api.Loki.queryRange(
  ql, // or string `{app="serviceName", env="production"}`
  {
    start: "1d",
    limit: 200
  }
);
console.log(logs);

You can also provide a Loki pattern to automatically parse logs (and infer the right type with TypeScript)

const logs = await api.Loki.queryRange(
  `{app="serviceName", env="production"}`
  {
    pattern: "<verb> <_> <endpoint>"
  }
);
for (const { verb, endpoint } of logs) {
  console.log({verb, endpoint });
}

API

GrafanaAPI

export interface GrafanaApiOptions {
  /**
   * Grafana API Token
   */
  apiToken?: string;
  /**
   * Remote Grafana root API URL
   */
  remoteApiURL: string | URL;
}s

Sub-class

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Thomas.G
Thomas.G

💻 🛡️ 📖
PierreDemailly
PierreDemailly

💻 ⚠️ 📖

License

MIT

/@myunisoft/loki/

    Package Sidebar

    Install

    npm i @myunisoft/loki

    Weekly Downloads

    129

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    34.3 kB

    Total Files

    7

    Last publish

    Collaborators

    • sabdennader
    • pierred
    • vianneyriotte
    • olllejik
    • f.ferre
    • maximevmyunisoft
    • arichardmyun
    • rossbob
    • osng
    • fraxken