remove node exporter and add alloy for metrics

This commit is contained in:
Your Name
2025-03-19 10:06:48 +00:00
parent 0046ff0f07
commit 32b4d8ba43
4 changed files with 45 additions and 134 deletions
+28 -61
View File
@@ -1,71 +1,38 @@
// File log collection for application.log
local.file_match "application_logs" {
path_targets = [{"__path__" = "/var/log/application.log"}]
}
loki.source.file "app_logs" {
targets = local.file_match.application_logs.targets
forward_to = [loki.process.application_logs.receiver]
}
// Process application logs
loki.process "application_logs" {
// Extract log levels with regex
stage.regex {
expression = "(?i)(?P<level>error|warn|info|debug)"
prometheus.exporter.unix "host_metrics" {
// Enable specific collectors that would provide the missing metrics
enable_collectors = [
"cpu", "pressure", "netdev", "netstat", "diskstats",
"meminfo", "loadavg", "softnet", "stat", "thermal_zone",
]
// Set paths for accessing host metrics when running in a container
procfs_path = "/host/proc"
sysfs_path = "/host/sys"
rootfs_path = "/rootfs"
// Configure filesystem collector
filesystem {
mount_points_exclude = "^/(sys|proc|dev|host|etc)($$|/)"
}
// Add extracted level as a label
stage.labels {
values = {
level = "",
}
}
// Add a source label to distinguish from container logs
stage.static_labels {
values = {
source = "file",
}
}
forward_to = [loki.write.loki_gateway.receiver]
}
// Container log collection - KEEPING THIS AS IT WORKS
discovery.docker "containers" {
host = "unix:///var/run/docker.sock"
}
discovery.relabel "containers" {
targets = discovery.docker.containers.targets
rule {
source_labels = ["__meta_docker_container_name"]
target_label = "container"
}
rule {
source_labels = ["__meta_docker_container_id"]
target_label = "container_id"
}
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
target_label = "service"
}
rule {
replacement = "container"
target_label = "source"
// Configure netdev collector
netdev {
// Include all network devices for network traffic metrics
device_exclude = ""
}
}
loki.source.docker "container_log_collector" {
host = "unix:///var/run/docker.sock"
targets = discovery.relabel.containers.output
forward_to = [loki.write.loki_gateway.receiver]
// Make sure we scrape the host metrics
prometheus.scrape "host_metrics" {
targets = prometheus.exporter.unix.host_metrics.targets
forward_to = [prometheus.remote_write.prometheus.receiver]
scrape_interval = "15s"
scrape_timeout = "10s"
job_name = "node"
}
// Send all logs to Loki
loki.write "loki_gateway" {
prometheus.remote_write "prometheus" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
url = "http://prometheus:9090/api/v1/write"
}
}