Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions packages/nats/_dev/build/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The integration collects metrics from [NATS monitoring server APIs](https://docs

## Compatibility

The Nats package is tested with Nats 1.3.0, 2.0.4 and 2.1.4
The Nats package is tested with NATS 2.10.27. The `jetstream` dataset requires NATS with JetStream enabled (NATS 2.2+) and Elastic Agent 9.1+. Consumer metrics require JetStream 2.9+.
Comment thread
nikolaigut marked this conversation as resolved.
Outdated

## Logs

Expand All @@ -24,8 +24,8 @@ Please refer to the following [document](https://www.elastic.co/guide/en/ecs/cur

## Metrics

The default datasets are `stats`, `connections`, `routes` and `subscriptions` while `connection` and `route`
datasets can be enabled to collect detailed metrics per connection/route.
The default datasets are `stats`, `connections`, `routes` and `subscriptions` while `connection`, `route`
and `jetstream` datasets can be enabled to collect detailed metrics per connection/route and JetStream monitoring.

### stats

Expand Down Expand Up @@ -93,6 +93,30 @@ Please refer to the following [document](https://www.elastic.co/guide/en/ecs/cur

{{fields "connection"}}

### jetstream

This is the `jetstream` dataset of the Nats package, in charge of retrieving
JetStream metrics from a NATS server. It collects data from the [/jsz](https://docs.nats.io/learn/monitoring/monitoring-endpoints#jsz-reports-jetstream-state) monitoring endpoint.

The `jetstream` dataset supports four categories of metrics that can be enabled independently:

* `stats` — General JetStream server stats (streams, consumers, messages, memory, storage).
* `account` — Per-account JetStream metrics (memory, storage, API stats).
* `stream` — Per-stream metrics (state, config, cluster info).
* `consumer` — Per-consumer metrics (delivered, ack floor, pending, config). Requires JetStream 2.9+.

Account, stream, and consumer metrics can be filtered by name. Filters are cumulative and apply even if a category is not enabled but name filters are configured. When no names are configured, all entities are reported.

This dataset requires Elastic Agent 9.1+ and a NATS server with JetStream enabled.

{{event "jetstream"}}

**ECS Field Reference**

Please refer to the following [document](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html) for detailed information on ECS fields.

{{fields "jetstream"}}

### route

This is the `route` dataset of the Nats package, in charge of retrieving detailed
Expand Down
12 changes: 6 additions & 6 deletions packages/nats/_dev/deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
ARG NATS_VERSION=2.0.4
ARG NATS_VERSION=2.10.27
FROM nats:$NATS_VERSION

# build stage
FROM golang:1.20.2-alpine3.17 AS build-env
RUN apk --no-cache add build-base git mercurial gcc
RUN go install github.com/nats-io/nats.go/examples/nats-bench@v1.10.0
FROM golang:1.25-alpine AS build-env
RUN apk --no-cache add build-base git gcc
RUN go install github.com/nats-io/nats.go/examples/nats-bench@v1.36.0

# create an enhanced container with nc command available since nats is based
# on scratch image making healthcheck impossible
FROM alpine:3.17
FROM alpine:3.20
COPY --from=0 / /opt/nats
COPY --from=build-env /go/bin/nats-bench /nats-bench
COPY run.sh /run.sh
# Expose client, management, and cluster ports
EXPOSE 4222 8222 6222
HEALTHCHECK --interval=1s --retries=10 CMD nc -w 1 0.0.0.0 8222 </dev/null
HEALTHCHECK --interval=1s --retries=30 CMD nc -w 1 0.0.0.0 8222 </dev/null
# Run via the configuration file
CMD ["/run.sh"]
6 changes: 3 additions & 3 deletions packages/nats/_dev/deploy/docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# create logs' directory
mkdir /var/log/nats
mkdir -p /var/log/nats

# This script is used with old and new versions of nats,
# and they use different names for their binaries, detect
Expand All @@ -10,9 +10,9 @@ mkdir /var/log/nats
# NATS 2.X
if [ -x /opt/nats/nats-server ]; then
if [[ -z "${ROUTES}" ]]; then
Comment thread
nikolaigut marked this conversation as resolved.
Outdated
(/opt/nats/nats-server -DV -l /var/log/nats/nats.log --cluster nats://0.0.0.0:6222 --http_port 8222 --port 4222) &
(/opt/nats/nats-server -DV -js --server_name nats --cluster_name nats-cluster -l /var/log/nats/nats.log --cluster nats://0.0.0.0:6222 --http_port 8222 --port 4222 --routes nats://nats-routes:6222) &
else
(/opt/nats/nats-server -DV -l /var/log/nats/nats.log --cluster nats://0.0.0.0:6222 --http_port 8222 --port 4222 --routes nats://nats:6222) &
(/opt/nats/nats-server -DV -js --server_name nats-routes --cluster_name nats-cluster -l /var/log/nats/nats.log --cluster nats://0.0.0.0:6222 --http_port 8222 --port 4222 --routes nats://nats:6222) &
fi
while true; do /nats-bench -np 1 -n 100000000 -ms 16 foo; done
fi
Expand Down
6 changes: 2 additions & 4 deletions packages/nats/_dev/deploy/variants.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
variants:
v1:
SERVICE_VERSION: 1.3.0
v2:
SERVICE_VERSION: 2.1.4
default: v2
SERVICE_VERSION: 2.10.27
default: v1
5 changes: 5 additions & 0 deletions packages/nats/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# newer versions go on top
- version: "1.13.0"
changes:
- description: Add JetStream data stream for monitoring JetStream stats, accounts, streams, and consumers. Requires Elastic Agent 9.1+.
type: enhancement
link: https://github.com/elastic/integrations/issues/10748
Comment thread
nikolaigut marked this conversation as resolved.
Outdated
- version: "1.12.0"
changes:
- description: Add missing fields to `connection` and `stats` data datastreams.
Expand Down
6 changes: 6 additions & 0 deletions packages/nats/data_stream/connection/fields/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@
- name: id
type: keyword
description: A unique numeric identifier assigned by the NATS server to a connection
- name: kind
type: keyword
description: The kind of the connection (Client, Leafnode, etc.)
- name: type
type: keyword
description: The type of the connection
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vars:
hosts:
- http://{{Hostname}}:{{Port}}
data_stream:
vars: ~
33 changes: 33 additions & 0 deletions packages/nats/data_stream/jetstream/agent/stream/stream.yml.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
metricsets: ["jetstream"]
hosts:
{{#each hosts}}
- {{this}}
{{/each}}
period: {{period}}
jetstream:
stats:
enabled: {{jetstream_stats_enabled}}
account:
enabled: {{jetstream_account_enabled}}
{{#if jetstream_account_names}}
names:
{{#each jetstream_account_names}}
- {{this}}
{{/each}}
{{/if}}
stream:
enabled: {{jetstream_stream_enabled}}
{{#if jetstream_stream_names}}
names:
{{#each jetstream_stream_names}}
- {{this}}
{{/each}}
{{/if}}
consumer:
enabled: {{jetstream_consumer_enabled}}
{{#if jetstream_consumer_names}}
names:
{{#each jetstream_consumer_names}}
- {{this}}
{{/each}}
{{/if}}
20 changes: 20 additions & 0 deletions packages/nats/data_stream/jetstream/fields/base-fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- name: data_stream.type
type: constant_keyword
description: Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: Data stream namespace.
- name: '@timestamp'
type: date
description: Event timestamp.
- name: event.module
type: constant_keyword
description: Event module
value: nats
- name: event.dataset
type: constant_keyword
description: Event dataset
value: nats.jetstream
27 changes: 27 additions & 0 deletions packages/nats/data_stream/jetstream/fields/ecs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- external: ecs
name: service.address
dimension: true
- external: ecs
name: agent.id
dimension: true
- external: ecs
name: cloud.account.id
dimension: true
- external: ecs
name: cloud.region
dimension: true
- external: ecs
name: cloud.availability_zone
dimension: true
- external: ecs
name: cloud.instance.id
dimension: true
- external: ecs
name: cloud.provider
dimension: true
- external: ecs
name: container.id
dimension: true
- external: ecs
name: host.name
dimension: true
Loading
Loading