Better Stack Prometheus metrics

Start collecting metrics in 5 minutes

How you would like to collect your Prometheus metrics?

Forward metrics from your Prometheus instance

Collect metrics from your Prometheus instance using Vector and Prometheus Remote-Write.

1. Install

Select your platform:

Configure the Vector APT repository and install Vector:

Install Vector
bash -c "$(curl -L https://setup.vector.dev)"
apt-get install vector

2. Setup

Add a Prometheus source and a Better Stack sink to your /etc/vector/vector.yaml config:

vector.yaml vector.toml
sources:
  better_stack_prometheus_source_$SOURCE_TOKEN:
    type: "prometheus_remote_write"
    address: "0.0.0.0:9090"

transforms:
  better_stack_prometheus_log_transform_$SOURCE_TOKEN:
    type: "metric_to_log"
    inputs:
      - "better_stack_prometheus_source_$SOURCE_TOKEN"

  better_stack_prometheus_transform_$SOURCE_TOKEN:
    type: "remap"
    inputs:
      - "better_stack_prometheus_log_transform_$SOURCE_TOKEN"
    source: |
      .dt = del(.timestamp)
      string_name = string(.name) ?? ""
      if (ends_with(string_name, "_total") || ends_with(string_name, "_sum") || ends_with(string_name, "_counter")) && is_object(.gauge) {
        .counter.value = del(.gauge.value)
        del(.gauge)
      }

sinks:
  better_stack_http_sink_$SOURCE_TOKEN:
    type: "http"
    inputs:
      - "better_stack_prometheus_transform_$SOURCE_TOKEN"
    uri: "https://in.logs.betterstack.com/metrics"
    method: "post"
    encoding:
      codec: "json"
    auth:
      strategy: "bearer"
      token: "$SOURCE_TOKEN"
[sources.better_stack_prometheus_source_$SOURCE_TOKEN]
type = "prometheus_remote_write"
address = "0.0.0.0:9090"

[transforms.better_stack_prometheus_log_transform_$SOURCE_TOKEN]
type = "metric_to_log"
inputs = ["better_stack_prometheus_source_$SOURCE_TOKEN"]

[transforms.better_stack_prometheus_transform_$SOURCE_TOKEN]
type = "remap"
inputs = [ "better_stack_prometheus_log_transform_$SOURCE_TOKEN" ]
source = '''
.dt = del(.timestamp)

string_name = string(.name) ?? ""
if (ends_with(string_name, "_total") || ends_with(string_name, "_sum") || ends_with(string_name, "_counter")) && is_object(.gauge) {
  .counter.value = del(.gauge.value)
  del(.gauge)
}
'''

[sinks.better_stack_http_sink_$SOURCE_TOKEN]
type = "http"
inputs = [ "better_stack_prometheus_transform_$SOURCE_TOKEN" ]
uri = "https://in.logs.betterstack.com/metrics"
method = "post"
encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "$SOURCE_TOKEN"

Add a remote_write section to your Prometheus config file:

Prometheus config file
remote_write:
  - url: 'http://localhost:9090'

Reload the configuration of your Prometheus server:

Reload Prometheus server
ps -A | grep prometheus | tr -s ' ' | xargs | cut -f1 -d' ' | xargs kill -HUP

3. Restart

Restart Vector to reload the configuration:

Restart Vector
systemctl restart vector

You should see your metrics in the Prometheus dashboard.

Seeing unrelated debugging messages in your logs?

After a fresh install, Vector comes preconfigured with a Demo logs source. It might be useful for initial testing, but don't forget to remove it afterwards.

Forward metrics from Prometheus exporters

Forward metrics from your Prometheus exporters and applications using Vector.

1. Install

Select your platform:

Configure the Vector APT repository and install Vector:

Install Vector
bash -c "$(curl -L https://setup.vector.dev)"
apt-get install vector

2. Setup

Add a Prometheus source and a Better Stack sink to your /etc/vector/vector.yaml config.

Change endpoints in the source section to be an array of string URLs on which Vector can scrape metrics in the Prometheus format.

vector.yaml vector.toml
sources:
  better_stack_prometheus_source_$SOURCE_TOKEN:
    type: "prometheus_scrape"
    endpoints:
      - "<REPLACE_BY_URLS_FOR_SCRAPING>"
    instance_tag: "instance"
    scrape_interval_secs: 30

transforms:
  better_stack_prometheus_log_transform_$SOURCE_TOKEN:
    type: "metric_to_log"
    inputs:
      - "better_stack_prometheus_source_$SOURCE_TOKEN"

  better_stack_prometheus_transform_$SOURCE_TOKEN:
    type: "remap"
    inputs:
      - "better_stack_prometheus_log_transform_$SOURCE_TOKEN"
    source: |
      .dt = del(.timestamp)

sinks:
  better_stack_http_sink_$SOURCE_TOKEN:
    type: "http"
    inputs:
      - "better_stack_prometheus_transform_$SOURCE_TOKEN"
    uri: "https://in.logs.betterstack.com/metrics"
    method: "post"
    encoding:
      codec: "json"
    auth:
      strategy: "bearer"
      token: "$SOURCE_TOKEN"
[sources.better_stack_prometheus_source_$SOURCE_TOKEN]
type = "prometheus_scrape"
endpoints = ["<REPLACE_BY_URLS_FOR_SCRAPING>"]
instance_tag = "instance"
scrape_interval_secs = 30

[transforms.better_stack_prometheus_log_transform_$SOURCE_TOKEN]
type = "metric_to_log"
inputs = ["better_stack_prometheus_source_$SOURCE_TOKEN"]

[transforms.better_stack_prometheus_transform_$SOURCE_TOKEN]
type = "remap"
inputs = [ "better_stack_prometheus_log_transform_$SOURCE_TOKEN" ]
source = '''
.dt = del(.timestamp)
'''

[sinks.better_stack_http_sink_$SOURCE_TOKEN]
type = "http"
inputs = [ "better_stack_prometheus_transform_$SOURCE_TOKEN" ]
uri = "https://in.logs.betterstack.com/metrics"
method = "post"
encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "$SOURCE_TOKEN"

3. Restart

Restart Vector to reload the configuration:

Restart Vector
systemctl restart vector

You should see your metrics in the Prometheus dashboard.

Seeing unrelated debugging messages in your logs?

After a fresh install, Vector comes preconfigured with a Demo logs source.
It might be useful for initial testing, but don't forget to remove it afterwards.

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏