alloy works
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// 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)"
|
||||
}
|
||||
|
||||
// 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"
|
||||
}
|
||||
}
|
||||
|
||||
loki.source.docker "container_log_collector" {
|
||||
host = "unix:///var/run/docker.sock"
|
||||
targets = discovery.relabel.containers.output
|
||||
forward_to = [loki.write.loki_gateway.receiver]
|
||||
}
|
||||
|
||||
// Send all logs to Loki
|
||||
loki.write "loki_gateway" {
|
||||
endpoint {
|
||||
url = "http://loki:3100/loki/api/v1/push"
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,23 @@ services:
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- monitoring
|
||||
alloy:
|
||||
image: grafana/alloy:latest
|
||||
container_name: alloy
|
||||
volumes:
|
||||
- ./config/config.alloy:/etc/alloy/config.alloy
|
||||
- /home/container_user/logs:/var/log:ro # Read-only mount of host logs
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
command:
|
||||
- run
|
||||
- --server.http.listen-addr=0.0.0.0:12345
|
||||
- --storage.path=/var/lib/alloy/data
|
||||
- /etc/alloy/config.alloy
|
||||
ports:
|
||||
- "12345:12345" # Expose the Alloy UI
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- monitoring
|
||||
|
||||
volumes:
|
||||
grafana-data:
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
version: "3.3"
|
||||
|
||||
networks:
|
||||
loki:
|
||||
|
||||
services:
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
ports:
|
||||
- "3100:3100"
|
||||
command: -config.file=/etc/loki/local-config.yaml
|
||||
networks:
|
||||
- loki
|
||||
|
||||
promtail:
|
||||
image: grafana/promtail:latest
|
||||
volumes:
|
||||
- /var/log:/var/log
|
||||
command: -config.file=/etc/promtail/config.yml
|
||||
networks:
|
||||
- loki
|
||||
|
||||
grafana:
|
||||
environment:
|
||||
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
|
||||
- GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
||||
- GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode
|
||||
entrypoint:
|
||||
- sh
|
||||
- -euc
|
||||
- |
|
||||
mkdir -p /etc/grafana/provisioning/datasources
|
||||
cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: Loki
|
||||
type: loki
|
||||
access: proxy
|
||||
orgId: 1
|
||||
url: http://loki:3100
|
||||
basicAuth: false
|
||||
isDefault: true
|
||||
version: 1
|
||||
editable: false
|
||||
EOF
|
||||
/run.sh
|
||||
image: grafana/grafana:latest
|
||||
ports:
|
||||
- "3000:3000"
|
||||
networks:
|
||||
- loki
|
||||
Reference in New Issue
Block a user