Skip to content

haidarally/Azure-Data-Collector-Wrapper

 
 

Repository files navigation

Azure Log Analytics Data Collector Client

Test status

Node.JS wrapper for Azure Monitor HTTP Data Collector API.

Installation

npm install azure-log-analytics-data-collector-client

Or with yarn:

yarn add azure-log-analytics-data-collector-client

Usage

Javascript:

const {
  DataCollectorClient,
} = require("azure-log-analytics-data-collector-client");

const client = new DataCollectorClient(
  "WORKSPACE_ID",
  "PRIMARY_KEY_OR_SECONDARY_KEY"
);

client
  .send("MyLogs", [
    {
      level: "info",
      message: "server starts",
    },
  ])
  .then(console.log);

Typescript:

import { DataCollectorClient } from "azure-log-analytics-data-collector-client";

const client = new DataCollectorClient(
  "WORKSPACE_ID",
  "PRIMARY_KEY_OR_SECONDARY_KEY"
);

client
  .send("MyLogs", [
    {
      level: "info",
      message: "server starts",
    },
  ])
  .then(console.log);

To get your WORKSPACE_ID and PRIMARY_KEY_OR_SECONDARY_KEY, in your workspace go to advanced settings -> connected resources -> Agents management.

To query your logs, go to the Logs tab of your workspace and use MyLogs_CL as query table name. Sample query:

MyLogs_CL
| where TimeGenerated > ago(24h)
| limit 10

Please note that only alphanumeric and underscore can be used as table name. the - in the table name will be replaced with _.

Response Object

Property Optional Description
code no HTTP response code
status no HTTP response status
errorCode yes Error code from server
errorMsg yes Error message from server

Local Development

To run the integration test locally, grab the workspace id and the agent key and then run:

LOG_ANALYTICS_WORKSPACE_ID=<your_workspace_id> LOG_ANALYTICS_AGENT_KEY=<your_agent_key> yarn test

License

MIT

About

Node.js wrapper for Azure Log Analytics data collector API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%