### NATS Surveyor YAML Configuration Example Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Example of a nats-surveyor.yaml configuration file. Set flags directly in the file. ```yaml servers: nats://127.0.0.1:4222 accounts: true log-level: debug ``` -------------------------------- ### Start NATS Surveyor with survey.sh script Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Alternatively, use the survey.sh script to start the Surveyor stack by providing NATS server URL, server count, and system credentials as arguments. ```bash $ ./survey.sh usage: survey.sh ``` ```bash ./survey.sh nats://mydeployment:4222 24 /privatekeys/SYS.creds ``` -------------------------------- ### Start NATS Surveyor with Docker Compose Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Use this command to start the NATS Surveyor stack, including Prometheus and Grafana, by pulling the latest images. ```bash $ docker compose up --pull always Recreating nats-surveyor ... done Recreating prometheus ... done Recreating grafana ... done Attaching to nats-surveyor, prometheus, grafana ... ``` -------------------------------- ### NATS Surveyor JSZ Metrics Collection Example Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Example command to collect metrics from leaders only and filter specific consumer metrics. Use --jsz=all to collect all JSZ metrics. ```bash nats-surveyor --jsz=all \ --jsz-leaders-only \ --jsz-filter=consumer_num_pending,consumer_num_ack_pending,consumer_num_waiting ``` -------------------------------- ### Docker Compose Up with Username/Password Authentication Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Starts the NATS Surveyor stack using Docker Compose with username and password authentication. Ensure NATS_SURVEYOR_SERVERS points to the NATS instance. ```bash NATS_SURVEYOR_USER=system NATS_SURVEYOR_PASSWORD=s3cret NATS_SURVEYOR_SERVERS=nats://host.docker.internal:4222 docker compose up --pull always ``` -------------------------------- ### Docker Compose Up with Credential File Authentication Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Starts the NATS Surveyor stack using Docker Compose with authentication via a creds file. Ensure NATS_SURVEYOR_SERVERS points to the NATS instance. ```bash NATS_SURVEYOR_CREDS=/path/to/SYS.creds NATS_SURVEYOR_SERVERS=nats://host.docker.internal:4222 docker compose up --pull always ``` -------------------------------- ### Remove NATS Surveyor containers Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Cleans up the installation by stopping and removing all Surveyor stack containers. ```bash docker compose down ``` -------------------------------- ### Run NATS Surveyor with Credentials File Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Execute the NATS Surveyor using a credentials file for authentication. Ensure the path to the credentials file is correct. ```sh ./nats-surveyor --creds ./test/SYS.creds 2019/10/14 21:35:40 Connected to NATS Deployment: 127.0.0.1:4222 2019/10/14 21:35:40 No certificate file specified; using http. 2019/10/14 21:35:40 Prometheus exporter listening at http://0.0.0.0:7777/metrics ``` -------------------------------- ### NATS Surveyor Helper Script for Docker Compose Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md A helper script to launch NATS Surveyor with Docker Compose, specifying the NATS server, number of replicas, and credentials file. ```bash ./survey.sh nats://host.docker.internal:4222 1 ./SYS.creds ``` -------------------------------- ### Provide System Account Credentials with --creds Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Use the `--creds` option to supply a chained credentials file containing both JWT and NKey seed for system account authentication. ```sh ``` -------------------------------- ### Build Local Docker Image Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Build a local Docker image for NATS Surveyor. This command is useful for testing local changes. ```bash docker build -t natsio/nats-surveyor:latest --debug . ``` -------------------------------- ### Run NATS Surveyor with Token File Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Use a token file for authentication by specifying the path to the file containing the token. This is often used in containerized environments. ```sh ./nats-surveyor --user sys --token-file /var/run/secrets/tokens/ 2025/08/29 22:14:20 Connected to NATS Deployment: 127.0.0.1:4222 2025/08/29 22:14:20 Prometheus exporter listening at http://0.0.0.0:7777/metrics ``` -------------------------------- ### Run Local Docker Compose Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Run NATS Surveyor using Docker Compose against a local NATS cluster. Set environment variables for authentication and server address. ```bash NATS_SURVEYOR_USER=system NATS_SURVEYOR_PASSWORD=s3cret NATS_SURVEYOR_SERVERS=nats://host.docker.internal:4222 docker compose up ``` -------------------------------- ### Service Observation Configuration Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Use this JSON format to configure service observations. Place the file in the 'observations' directory with a .json extension. Only one authentication method is required. ```json { "name": "my service", "topic": "email.subscribe.வுகளை", "jwt": "jwt portion of creds, must include seed also", "seed": "seed portion of creds, must include jwt also", "credential": "/path/to/file.creds", "nkey": "nkey seed", "token": "token", "username": "username, must include password also", "password": "password, must include user also", "tls_ca": "/path/to/ca.pem, defaults to surveyor's ca if one exists", "tls_cert": "/path/to/cert.pem, defaults to surveyor's cert if one exists", "tls_key": "/path/to/key.pem, defaults to surveyor's key if one exists" } ``` -------------------------------- ### NATS JSZ Filter Options for Consumers Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md A list of available metrics for consumers that can be used with the --jsz-filter flag to reduce cardinality. ```text consumer_delivered_consumer_seq consumer_delivered_stream_seq consumer_ack_floor_consumer_seq consumer_ack_floor_stream_seq consumer_num_ack_pending consumer_num_pending consumer_num_redelivered consumer_num_waiting ``` -------------------------------- ### NATS Surveyor Command-Line Flags Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Lists all available command-line flags for the NATS Surveyor tool, including server URLs, authentication methods, discovery timeouts, and metric export options. Use these flags to configure the surveyor's behavior. ```text Usage: nats-surveyor [flags] Flags: -s, --servers string NATS Cluster url(s) (NATS_SURVEYOR_SERVERS) (default "nats://127.0.0.1:4222") -c, --count int Expected number of servers (-1 for undefined). (NATS_SURVEYOR_COUNT) (default 1) --timeout duration Polling timeout (NATS_SURVEYOR_TIMEOUT) (default 3s) --server-discovery-timeout duration Maximum wait time between responses from servers during server discovery. Use in conjunction with -count=-1. (NATS_SURVEYOR_SERVER_DISCOVERY_TIMEOUT) (default 500ms) --creds string Credentials File (NATS_SURVEYOR_CREDS) --nkey string Nkey Seed File (NATS_SURVEYOR_NKEY) --jwt string User JWT. Use in conjunction with --seed (NATS_SURVEYOR_JWT) --seed string Private key (nkey seed). Use in conjunction with --jwt (NATS_SURVEYOR_SEED) --user string NATS user name or token (NATS_SURVEYOR_USER) --password string NATS user password (NATS_SURVEYOR_PASSWORD) --token-file string Path to a file with a bearer token (NATS_SURVEYOR_TOKEN_FILE) --tlscert string Client certificate file for NATS connections. (NATS_SURVEYOR_TLSCERT) --tlskey string Client private key for NATS connections. (NATS_SURVEYOR_TLSKEY) --tlscacert string Client certificate CA on NATS connections. (NATS_SURVEYOR_TLSCACERT) --tlsfirst Whether to use TLS First connections. (NATS_SURVEYOR_TLSFIRST) -p, --port int Port to listen on. (NATS_SURVEYOR_PORT) (default 7777) -a, --addr string Network host to listen on. (NATS_SURVEYOR_ADDR) (default "0.0.0.0") --http-tlscert string Server certificate file (Enables HTTPS). (NATS_SURVEYOR_HTTP_TLSCERT) --http-tlskey string Private key for server certificate (used with HTTPS). (NATS_SURVEYOR_HTTP_TLSKEY) --http-tlscacert string Client certificate CA for verification (used with HTTPS). (NATS_SURVEYOR_HTTP_TLSCACERT) --http-user string Enable basic auth and set user name for HTTP scrapes. (NATS_SURVEYOR_HTTP_USER) --http-pass string Set the password for HTTP scrapes. NATS bcrypt supported. (NATS_SURVEYOR_HTTP_PASS) --prefix string Replace the default prefix for all the metrics. (NATS_SURVEYOR_PREFIX) --observe string Listen for observation statistics based on config files in a directory. (NATS_SURVEYOR_OBSERVE) --jetstream string Listen for JetStream Advisories based on config files in a directory. (NATS_SURVEYOR_JETSTREAM) --accounts Export per-account metrics (NATS_SURVEYOR_ACCOUNTS) --accounts-detailed Export granular per-account bytes and message metrics (NATS_SURVEYOR_ACCOUNTS_DETAILED) --gatewayz Export gateway metrics (NATS_SURVEYOR_GATEWAYZ) --raftz Export metalayer Raft group metrics from raftz endpoint (NATS_SURVEYOR_RAFTZ) --jsz string Export jsz metrics optionally, one of: all|streams|consumers (NATS_SURVEYOR_JSZ) --jsz-limit int Limit the number of returned account jsz metrics (NATS_SURVEYOR_JSZ_LIMIT) (default 1024) --jsz-leaders-only Fetch jsz metrics from stream and consumer leaders only (NATS_SURVEYOR_JSZ_LEADERS_ONLY) --jsz-filter jsz-filter Fetch selected jsz metrics only(comma separated list). Metrics: stream_total_messages,stream_total_bytes,stream_first_seq,stream_last_seq,stream_consumer_count,stream_subject_count,consumer_delivered_consumer_seq,consumer_delivered_stream_seq,consumer_ack_floor_consumer_seq,consumer_ack_floor_stream_seq,consumer_num_ack_pending,consumer_num_pending,consumer_num_redelivered,consumer_num_waiting (NATS_SURVEYOR_JSZ_FILTER) (default []) --sys-req-prefix string Subject prefix for system requests ($SYS.REQ) (NATS_SURVEYOR_SYS_REQ_PREFIX) (default "$SYS.REQ") --log-level string Log level, one of: trace|debug|info|warn|error|fatal|panic (NATS_SURVEYOR_LOG_LEVEL) (default "info") --config string config file (default is ./nats-surveyor.yaml) -h, --help help for nats-surveyor -v, --version version for nats-surveyor ``` -------------------------------- ### Run NATS Surveyor with User and Password Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Authenticate using a username and password. This is a common authentication method for NATS deployments. ```sh ./nats-surveyor --user --password ``` -------------------------------- ### JetStream Observation Configuration Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Use this JSON format to configure JetStream observations. Place the file in the 'jetstream' directory with a .json extension. Ensure the user has access to the '$JS.EVENT.>' subject. Only one authentication method is required. ```json { "name": "my account", "jwt": "jwt portion of creds, must include seed also", "seed": "seed portion of creds, must include jwt also", "credential": "/path/to/file.creds", "nkey": "nkey seed", "token": "token", "username": "username, must include password also", "password": "password, must include user also", "tls_ca": "/path/to/ca.pem, defaults to surveyor's ca if one exists", "tls_cert": "/path/to/cert.pem, defaults to surveyor's cert if one exists", "tls_key": "/path/to/key.pem, defaults to surveyor's key if one exists" } ``` -------------------------------- ### Run NATS Surveyor with JWT and NKey Seed Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Authenticate using a user JWT and NKey seed directly provided via environment variables. This method is useful for programmatic authentication. ```sh ./nats-surveyor --jwt $NATS_USER_JWT --seed $NATS_NKEY_SEED 2019/10/14 21:35:40 Connected to NATS Deployment: 127.0.0.1:4222 2019/10/14 21:35:40 No certificate file specified; using http. 2019/10/14 21:35:40 Prometheus exporter listening at http://0.0.0.0:7777/metrics ``` -------------------------------- ### Configure Prometheus user as root in docker-compose.yml Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md As an alternative, sets the Prometheus container user to 'root'. This may pose a security risk. ```yaml prometheus: image: prom/prometheus:${PROMETHEUS_DOCKER_TAG} user: root ``` -------------------------------- ### Configure Prometheus user in docker-compose.yml Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Sets the user for the Prometheus container to '1000:1000' to resolve 'Unable to create mmap-ed active query log' errors. ```yaml prometheus: image: prom/prometheus:${PROMETHEUS_DOCKER_TAG} user: "1000:1000" ``` -------------------------------- ### NATS Surveyor Environment Variable Configuration Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Environment variables prefixed with NATS_SURVEYOR_ are read. Flag names are converted to uppercase with dashes replaced by underscores. ```bash NATS_SURVEYOR_SERVERS=nats://127.0.0.1:4222 NATS_SURVEYOR_ACCOUNTS=true NATS_SURVEYOR_LOG_LEVEL=debug NATS_SURVEYOR_USER=myuser NATS_SURVEYOR_PASSWORD=mypassword ``` -------------------------------- ### Restart NATS Surveyor stack Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Restarts the Surveyor stack after it has been stopped. ```bash docker compose up ``` -------------------------------- ### Stop NATS Surveyor containers Source: https://github.com/nats-io/nats-surveyor/blob/main/README.md Stops the running Surveyor stack containers without removing them. ```bash docker compose stop ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.