ansible-collection/roles/common/templates/etc/alloy/config.alloy
GregoryDosh ec8ad4311a
All checks were successful
Update Version / Update Version (push) Successful in 7s
chore(logging): drop some unused labels from default alloy config
2024-12-25 15:45:00 -06:00

303 lines
9.7 KiB
Text

// Ansible Roles for managing Auengun.net Infrastructure & Testing/Learning.
// Source available at git.auengun.net/homelab/ansible-collection
// Copyright (C) 2023 GregoryDosh
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2023 GregoryDosh
/* ************* */
/* Common Config */
/* ************* */
// Adapted from reference examples:
// https://grafana.com/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/
// https://grafana.com/docs/alloy/latest/reference/config-blocks/logging/
logging {
level = "warn"
}
{% if GRAFANA_ALLOY_EXTRA_CONFIG %}
/* *************************** */
/* Extra Alloy Config via Host */
/* *************************** */
{{ GRAFANA_ALLOY_EXTRA_CONFIG }}
{% endif %}
/* ******************** */
/* Prometheus (Metrics) */
/* ******************** */
// {% if GRAFANA_ALLOY_OBSERVE_ALLOY | bool -%}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.self/
prometheus.exporter.self "alloy_prometheus" {
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.scrape/
prometheus.scrape "alloy" {
targets = prometheus.exporter.self.alloy_prometheus.targets
forward_to = [prometheus.relabel.alloy_exporter.receiver]
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/
prometheus.relabel "alloy_exporter" {
rule {
target_label = "instance"
replacement = constants.hostname
}
rule {
target_label = "job"
replacement = "integrations/alloy"
}
forward_to = [prometheus.remote_write.homelab_mimir.receiver]
}
// {% endif %}
// https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.relabel/
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"
}
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.unix/
prometheus.exporter.unix "integrations_node_exporter" {
{% if GRAFANA_ALLOY_NODE_EXPORTER_DISABLED_COLLECTORS or GRAFANA_ALLOY_NODE_EXPORTER_ENABLED_COLLECTORS %}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.unix/#collectors-list
{% endif %}
{% if GRAFANA_ALLOY_NODE_EXPORTER_DISABLED_COLLECTORS %}
disable_collectors = [ "{{ GRAFANA_ALLOY_NODE_EXPORTER_DISABLED_COLLECTORS | join("\", \"") }}" ]
{% endif %}
{% if GRAFANA_ALLOY_NODE_EXPORTER_ENABLED_COLLECTORS %}
enable_collectors = [ "{{ GRAFANA_ALLOY_NODE_EXPORTER_ENABLED_COLLECTORS | join("\", \"") }}" ]
{% endif %}
{% if GRAFANA_ALLOY_NODE_EXPORTER_EXTRA_RULES %}
/* ******************************* */
/* Extra Alloy Node Rules via Host */
/* ******************************* */
{{ GRAFANA_ALLOY_NODE_EXPORTER_EXTRA_RULES }}
{% endif %}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.unix/#netclass-block
netclass {
ignored_devices = "^(veth.*|[a-f0-9]{15})$"
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.unix/#netdev-block
netdev {
device_exclude = "^(veth.*|[a-f0-9]{15})$"
}
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.scrape/
prometheus.scrape "integrations_node_exporter" {
targets = discovery.relabel.integrations_node_exporter.output
forward_to = [prometheus.relabel.integrations_node_exporter.receiver]
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/
prometheus.relabel "integrations_node_exporter" {
rule {
source_labels = ["__name__"]
regex = "node_scrape_collector_.+"
action = "drop"
}
forward_to = [prometheus.remote_write.homelab_mimir.receiver]
}
// {% if GRAFANA_ALLOY_OBSERVE_DOCKER | bool -%}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.cadvisor/
prometheus.exporter.cadvisor "integrations_cadvisor" {
docker_only = true
{% if GRAFANA_ALLOY_CADVISOR_DISABLED_METRICS or GRAFANA_ALLOY_CADVISOR_ENABLED_METRICS %}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.cadvisor/#arguments
{% endif %}
{% if GRAFANA_ALLOY_CADVISOR_DISABLED_METRICS %}
disabled_metrics = [ "{{ GRAFANA_ALLOY_CADVISOR_DISABLED_METRICS | join("\", \"") }}" ]
{% endif %}
{% if GRAFANA_ALLOY_CADVISOR_ENABLED_METRICS %}
enabled_metrics = [ "{{ GRAFANA_ALLOY_CADVISOR_ENABLED_METRICS | join("\", \"") }}" ]
{% endif %}
}
// https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.relabel/
discovery.relabel "integrations_cadvisor" {
targets = prometheus.exporter.cadvisor.integrations_cadvisor.targets
rule {
target_label = "instance"
replacement = constants.hostname
}
rule {
target_label = "job"
replacement = "integrations/docker"
}
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.scrape/
prometheus.scrape "docker" {
targets = discovery.relabel.integrations_cadvisor.output
forward_to = [prometheus.relabel.docker_relabel.receiver]
}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/
prometheus.relabel "docker_relabel" {
rule {
target_label = "instance"
replacement = constants.hostname
}
forward_to = [prometheus.remote_write.homelab_mimir.receiver]
}
// {% endif %}
// https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.remote_write/
prometheus.remote_write "homelab_mimir" {
endpoint {
url = "https://mimir.auengun.net/api/v1/push"
headers = {
"X-Scope-OrgID" = "{{ GRAFANA_ALLOY_ORGID }}",
}
}
}
/* *********** */
/* Loki (Logs) */
/* *********** */
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.source.journal/
loki.source.journal "logs_integrations_integrations_node_exporter_journal_scrape" {
max_age = "24h0m0s"
relabel_rules = discovery.relabel.logs_integrations_integrations_node_exporter_journal_scrape.rules
forward_to = [loki.process.final_cleanup.receiver]
}
// https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.relabel/
discovery.relabel "logs_integrations_integrations_node_exporter_journal_scrape" {
targets = []
rule {
target_label = "job"
replacement = "integrations/journal"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
}
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.file_match/
local.file_match "logs_integrations_integrations_node_exporter_direct_scrape" {
path_targets = [{
__address__ = "localhost",
__path__ = "/var/log/{syslog,messages,*.log}",
instance = constants.hostname,
job = "integrations/log",
}]
}
loki.source.file "logs_integrations_integrations_node_exporter_direct_scrape" {
targets = local.file_match.logs_integrations_integrations_node_exporter_direct_scrape.targets
forward_to = [loki.process.final_cleanup.receiver]
}
// {% if GRAFANA_ALLOY_OBSERVE_DOCKER | bool -%}
// https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.docker/
discovery.docker "containers" {
host = "unix:///var/run/docker.sock"
}
// https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.relabel/
discovery.relabel "logs_integrations_docker" {
targets = []
rule {
target_label = "job"
replacement = "integrations/docker"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.source.docker/
loki.source.docker "host" {
host = "unix:///var/run/docker.sock"
targets = discovery.docker.containers.targets
forward_to = [loki.process.docker_format.receiver]
relabel_rules = discovery.relabel.logs_integrations_docker.rules
}
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.process/
loki.process "docker_format" {
stage.docker {}
forward_to = [loki.process.final_cleanup.receiver]
}
// {% endif %}
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.process/
loki.process "final_cleanup" {
stage.drop {
source = ""
expression = ".*logging driver does not support reading.*"
drop_counter_reason = "noisy"
}
{% if GRAFANA_ALLOY_EXTRA_CLEANUP_RULES %}
/* ********************************** */
/* Extra Alloy Cleanup Rules via Host */
/* ********************************** */
{{ GRAFANA_ALLOY_EXTRA_CLEANUP_RULES }}
{% endif %}
forward_to = [loki.write.homelab_loki.receiver]
}
// https://grafana.com/docs/alloy/latest/reference/components/loki/loki.write/
loki.write "homelab_loki" {
endpoint {
url = "https://loki.auengun.net/loki/api/v1/push"
headers = {
"X-Scope-OrgID" = "{{ GRAFANA_ALLOY_ORGID }}",
}
}
}