Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Latest commit

 

History

History

hec-client

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@splunkdlt/hec-client

Integration Tests

Flexible client library for Splunk HTTP Event Collector (HEC) with support for sending metrics and events, batching, compression, keep-alives and retries.

Install and Use

npm i @splunkdlt/hec-client

# or

yarn add @splunkdlt/hec-client

Example: sending some metrics to HEC:

const hec = new HecClient({
    url: 'https://http-inputs-acme.splunkcloud.com',
    token: '12345678-9999-4711-0815-C0FF33C0FFEE',
});

const mem = process.memoryUsage();
const cpu = process.cpuUsage();

hec.pushMetrics({
    time: Date.now(),
    measurements: {
        'myapp.cpu.user': cpu.user,
        'myapp.cpu.system': cpu.system,
        'myapp.mem.heapUsed': mem.heapUsed,
        'myapp.mem.heapTotal': mem.heapTotal,
    },
    fields: {
        hostname: os.hostname(),
    },
    metadata: {
        index: 'mymetrics',
        sourcetype: 'myapp:system',
        source: 'myapp',
    },
});

await hec.flush();