Loki
Node.js Grafana API SDK (Loki, Datasources ..)
š§ 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
$ yarn add @myunisoft/loki
š Usage
import { GrafanaApi } from "@myunisoft/loki";
import { LogQL, StreamSelector } from "@sigyn/logql";
const api = new GrafanaApi({
authentication: {
type: "bearer",
token: process.env.GRAFANA_API_TOKEN!
},
remoteApiURL: "https://name.loki.com"
});
const ql = new LogQL(
new StreamSelector({ app: "serviceName", env: "production" })
);
const logs = await api.Loki.queryRange(
ql,
{
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
interface GrafanaApiOptions {
authentication?: ApiCredentialAuthorizationOptions;
userAgent?: string;
remoteApiURL: string | URL;
}
type ApiCredentialAuthorizationOptions = {
type: "bearer";
token: string;
} | {
type: "classic";
username: string;
password: string;
} | {
type: "custom";
authorization: string;
};
Sub-class
Contributors āØ

Thanks goes to these wonderful people (emoji key):
License
MIT