node_exporter

Based on the template at https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-linux-node/.

Changes:

  1. Add netstat block to collect additional metrics.

TODOs:

  1. Similar to https://github.com/prometheus/node_exporter/pull/2867, propose adding AttemptFails to the default collector.netstat.fields. EstabResets might be worth adding too.
  2. Restore Alloy configuration to the template if the proposed node_exporter changes are merged to Alloy.
discovery.relabel "integrations_node_exporter" {
  targets = prometheus.exporter.unix.integrations_node_exporter.targets

  rule {
    target_label = "instance"
    replacement  = constants.hostname
  }

  rule {
    target_label = "job"
    replacement = "integrations/node_exporter"
  }
}

prometheus.exporter.unix "integrations_node_exporter" {
  disable_collectors = ["ipvs", "btrfs", "infiniband", "xfs", "zfs"]

  filesystem {
    fs_types_exclude     = "^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|tmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$"
    mount_points_exclude = "^/(dev|proc|run/credentials/.+|sys|var/lib/docker/.+)($|/)"
    mount_timeout        = "5s"
  }

  netclass {
    ignored_devices = "^(veth.*|cali.*|[a-f0-9]{15})$"
  }

  netdev {
    device_exclude = "^(veth.*|cali.*|[a-f0-9]{15})$"
  }

  netstat {
    fields = ""^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*|TCPSynRetrans|TCPTimeouts)|Tcp_(ActiveOpens|AttemptFails|InSegs|OutSegs|OutRsts|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts|RcvbufErrors|SndbufErrors))$""
  }
}

prometheus.scrape "integrations_node_exporter" {
  targets    = discovery.relabel.integrations_node_exporter.output
  forward_to = [prometheus.relabel.integrations_node_exporter.receiver]
}

prometheus.relabel "integrations_node_exporter" {
  forward_to = [prometheus.remote_write.metrics_service.receiver]

  rule {
    source_labels = ["__name__"]
    regex         = "node_scrape_collector_.+"
    action        = "drop"
  }
}

Docker Compose multi-container

For Supabase on Pigsty modifications with PGRST_ADMIN_SERVER_PORT in rest’s env set to <admin port>:

discovery.docker "postgrest" {
  host = "unix:///var/run/docker.sock" /* run alloy as root or add it to docker group */

  filter {
    name = "label"
    values = [
      "com.docker.compose.project=supabase",
      "com.docker.compose.service=rest"
    ]
  }
}

discovery.relabel "postgrest" {
  target = discovery.docker.postgrest.targets

  rule {
    source_labels = ["__meta_docker_network_ip"]
    regex = "(.*)"
    target_label = "__address__"
    replacement = "$1:<admin port>"
  }

  rule {
    source_label = ["__meta_docker_container_name"]
    regex = "/(.*)"
    target_label = "container_name"
  }

  rule {
    target_label = "instance"
    replacement = constants.hostname
  }

  rule {
    target_label = "job"
    replacement = "integrations/supabase-self-hosted"
  }
}

// use default `/metrics` path
prometheus.scrape "postgrest" {
  targets = discovery.relabel.postgrest.output
  forward_to = [prometheus.remote_write.metrics_service.receiver]
}

In discovery.relabel filters, label values are matched with MatchKVList in Docker Engine API, which returns true if all the pairs in sources exist as key=value pairs in the mapping at key.