소스 검색

alloy template updates

xcad 9 달 전
부모
커밋
5becc93ab9

+ 1 - 0
AGENTS.md

@@ -78,6 +78,7 @@ metadata:
   description: "A template for a simple Nginx service."
   version: "0.1.0"
   author: "Christian Lempa"
+  date: "2024-10-01"
 spec:
   general:
     vars:

+ 0 - 1
GEMINI.md

@@ -1 +0,0 @@
-AGENTS.md

+ 31 - 0
library/compose/alloy.docker-logs/config/config.alloy.j2

@@ -0,0 +1,31 @@
+discovery.docker "dockerlogs" {
+  host = "unix:///var/run/docker.sock"
+}
+
+discovery.relabel "dockerlogs" {
+      targets = []
+  
+      rule {
+          source_labels = ["__meta_docker_container_name"]
+          regex = "/(.*)"
+          target_label = "service_name"
+      }
+
+  }
+
+loki.source.docker "default" {
+  host       = "unix:///var/run/docker.sock"
+  targets    = discovery.docker.dockerlogs.targets
+  labels     = {"platform" = "docker"}
+  relabel_rules = discovery.relabel.dockerlogs.rules
+  forward_to = [loki.write.default.receiver]
+}
+
+/* Targets: define remote endpoints used by these fragments */
+
+loki.write "default" {
+  endpoint {
+    url = "{{ loki_url }}"
+  }
+  external_labels = {}
+}

+ 13 - 0
library/compose/alloy.docker-logs/template.yaml

@@ -0,0 +1,13 @@
+---
+kind: compose
+metadata:
+  name: Alloy - Docker Logs
+  description: Minimal fragment to collect Docker container logs for Alloy.
+  version: 0.0.1
+  author: Christian Lempa
+  date: '2025-09-30'
+spec:
+  general:
+    vars: {}
+
+---

+ 18 - 0
library/compose/alloy.docker-metrics/config/config.alloy.j2

@@ -0,0 +1,18 @@
+/* Targets: define remote write endpoint(s) used by these fragments */
+
+prometheus.remote_write "default" {
+  endpoint {
+    url = "{{ prometheus_url }}"
+  }
+}
+
+prometheus.exporter.cadvisor "dockermetrics" {
+  docker_host = "unix:///var/run/docker.sock"
+  storage_duration = "5m"
+}
+
+prometheus.scrape "dockermetrics" {
+  targets    = prometheus.exporter.cadvisor.dockermetrics.targets
+  forward_to = [ prometheus.remote_write.default.receiver ]
+  scrape_interval = "10s"
+}

+ 17 - 0
library/compose/alloy.docker-metrics/template.yaml

@@ -0,0 +1,17 @@
+---
+kind: compose
+metadata:
+  name: Alloy - Docker Metrics
+  description: Minimal fragment to collect Docker metrics (cAdvisor) for Alloy.
+  version: 0.0.1
+  author: Christian Lempa
+  date: '2025-09-30'
+spec:
+  general:
+    vars:
+      prometheus_url:
+        type: url
+        description: Prometheus remote write endpoint (http or https)
+        default: "http://prometheus:9090/api/v1/write"
+
+---

+ 53 - 0
library/compose/alloy.system-logs/config/config.alloy.j2

@@ -0,0 +1,53 @@
+/* Targets: define remote endpoints used by these fragments */
+
+loki.write "default" {
+  endpoint {
+    url = "{{ loki_url }}"
+  }
+  external_labels = {}
+}
+
+// SECTION: SYSTEM LOGS & JOURNAL
+
+loki.source.journal "journal" {
+  max_age       = "24h0m0s"
+  relabel_rules = discovery.relabel.journal.rules
+  forward_to    = [loki.write.default.receiver]
+  labels        = {component = string.format("%s-journal", constants.hostname)}
+  // NOTE: This is important to fix https://github.com/grafana/alloy/issues/924
+  path          = "/var/log/journal"
+}
+
+local.file_match "system" {
+  path_targets = [{
+    __address__ = "localhost",
+    __path__    = "/var/log/{syslog,messages,*.log}",
+    instance    = constants.hostname,
+    job         = string.format("%s-logs", constants.hostname),
+  }]
+}
+
+discovery.relabel "journal" {
+  targets = []
+  rule {
+    source_labels = ["__journal__systemd_unit"]
+    target_label  = "unit"
+  }
+  rule {
+    source_labels = ["__journal__boot_id"]
+    target_label  = "boot_id"
+  }
+  rule {
+    source_labels = ["__journal__transport"]
+    target_label  = "transport"
+  }
+  rule {
+    source_labels = ["__journal_priority_keyword"]
+    target_label  = "level"
+  }
+}
+
+loki.source.file "system" {
+  targets    = local.file_match.system.targets
+  forward_to = [loki.write.default.receiver]
+}

+ 18 - 0
library/compose/alloy.system-logs/template.yaml

@@ -0,0 +1,18 @@
+---
+kind: compose
+metadata:
+  name: Alloy - System Logs & Journal
+  description: Minimal fragment to collect system logs and journal for Alloy.
+  version: 0.0.1
+  author: Christian Lempa
+  date: '2025-09-30'
+spec:
+  general:
+    vars:
+      loki_url:
+        type: url
+        description: URL for Loki write endpoint (http or https)
+        default: "http://loki:3100/loki/api/v1/push"
+
+
+---

+ 41 - 0
library/compose/alloy.system-metrics/config/config.alloy.j2

@@ -0,0 +1,41 @@
+/* Targets: define remote write endpoint(s) used by these fragments */
+
+prometheus.remote_write "default" {
+  endpoint {
+    url = "{{ prometheus_url }}"
+  }
+}
+
+discovery.relabel "metrics" {
+  targets = prometheus.exporter.unix.metrics.targets
+  rule {
+    target_label = "instance"
+    replacement  = constants.hostname
+  }
+  rule {
+    target_label = "job"
+    replacement = string.format("%s-metrics", constants.hostname)
+  }
+}
+
+prometheus.exporter.unix "metrics" {
+  disable_collectors = ["ipvs", "btrfs", "infiniband", "xfs", "zfs"]
+  enable_collectors = ["meminfo"]
+  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})$"
+  }
+}
+
+prometheus.scrape "metrics" {
+scrape_interval = "15s"
+  targets    = discovery.relabel.metrics.output
+  forward_to = [prometheus.remote_write.default.receiver]
+}

+ 17 - 0
library/compose/alloy.system-metrics/template.yaml

@@ -0,0 +1,17 @@
+---
+kind: compose
+metadata:
+  name: Alloy - System Metrics
+  description: Minimal fragment to collect system (node) metrics for Alloy.
+  version: 0.0.1
+  author: Christian Lempa
+  date: '2025-09-30'
+spec:
+  general:
+    vars:
+      prometheus_url:
+        type: url
+        description: Prometheus remote write endpoint (http or https)
+        default: "http://prometheus:9090/api/v1/write"
+
+---

+ 2 - 2
library/compose/alloy/compose.yaml.j2

@@ -5,12 +5,12 @@ services:
     hostname: {{ container_hostname }}
     command:
       - run
-      - --server.http.listen-addr=0.0.0.0:12345
+      - --server.http.listen-addr=0.0.0.0:{{ ports_main | default("12345") }}
       - --storage.path=/var/lib/alloy/data
       - /etc/alloy/config.alloy
     {% if ports_enabled %}
     ports:
-      - "12345:12345"
+      - "{{ ports_main | default("12345") }}:12345"
     {% endif %}
     volumes:
       - ./config/config.alloy:/etc/alloy/config.alloy

+ 12 - 144
library/compose/alloy/config/config.alloy

@@ -1,148 +1,16 @@
 /* Grafana Alloy Configuration Examples
  * ---
  * LINK: For more details, visit https://github.com/grafana/alloy-scenarios
-*/
 
-// SECTION: TARGETS
-
-loki.write "default" {
-	endpoint {
-		url = "http://loki:3100/loki/api/v1/push"
-	}
-	external_labels = {}
-}
-
-prometheus.remote_write "default" {
-  endpoint {
-    url = "http://prometheus:9090/api/v1/write"
-  }
-}
-
-// !SECTION
-
-// SECTION: SYSTEM LOGS & JOURNAL
-
-loki.source.journal "journal" {
-  max_age       = "24h0m0s"
-  relabel_rules = discovery.relabel.journal.rules
-  forward_to    = [loki.write.default.receiver]
-  labels        = {component = string.format("%s-journal", constants.hostname)}
-  // NOTE: This is important to fix https://github.com/grafana/alloy/issues/924
-  path          = "/var/log/journal" 
-}
-
-local.file_match "system" {
-  path_targets = [{
-    __address__ = "localhost",
-    __path__    = "/var/log/{syslog,messages,*.log}",
-    instance    = constants.hostname,
-    job         = string.format("%s-logs", constants.hostname),
-  }]
-}
-
-discovery.relabel "journal" {
-  targets = []
-  rule {
-    source_labels = ["__journal__systemd_unit"]
-    target_label  = "unit"
-  }
-  rule {
-    source_labels = ["__journal__boot_id"]
-    target_label  = "boot_id"
-  }
-  rule {
-    source_labels = ["__journal__transport"]
-    target_label  = "transport"
-  }
-  rule {
-    source_labels = ["__journal_priority_keyword"]
-    target_label  = "level"
-  }
-}
-
-loki.source.file "system" {
-  targets    = local.file_match.system.targets
-  forward_to = [loki.write.default.receiver]
-}
-
-// !SECTION
-
-// SECTION: SYSTEM METRICS
-
-discovery.relabel "metrics" {
-  targets = prometheus.exporter.unix.metrics.targets
-  rule {
-    target_label = "instance"
-    replacement  = constants.hostname
-  }
-  rule {
-    target_label = "job"
-    replacement = string.format("%s-metrics", constants.hostname)
-  }
-}
-
-prometheus.exporter.unix "metrics" {
-  disable_collectors = ["ipvs", "btrfs", "infiniband", "xfs", "zfs"]
-  enable_collectors = ["meminfo"]
-  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})$"
-  }
-}
-
-prometheus.scrape "metrics" {
-scrape_interval = "15s"
-  targets    = discovery.relabel.metrics.output
-  forward_to = [prometheus.remote_write.default.receiver]
-}
-
-// !SECTION
-
-// SECTION: DOCKER METRICS
-
-prometheus.exporter.cadvisor "dockermetrics" {
-  docker_host = "unix:///var/run/docker.sock"
-  storage_duration = "5m"
-}
-
-prometheus.scrape "dockermetrics" {
-  targets    = prometheus.exporter.cadvisor.dockermetrics.targets
-  forward_to = [ prometheus.remote_write.default.receiver ]
-  scrape_interval = "10s"
-}
-
-//!SECTION
-
-// SECTION: DOCKER LOGS
-
-discovery.docker "dockerlogs" {
-  host = "unix:///var/run/docker.sock"
-}
-
-discovery.relabel "dockerlogs" {
-      targets = []
-  
-      rule {
-          source_labels = ["__meta_docker_container_name"]
-          regex = "/(.*)"
-          target_label = "service_name"
-      }
-
-  }
-
-loki.source.docker "default" {
-  host       = "unix:///var/run/docker.sock"
-  targets    = discovery.docker.dockerlogs.targets
-  labels     = {"platform" = "docker"}
-  relabel_rules = discovery.relabel.dockerlogs.rules
-  forward_to = [loki.write.default.receiver]
-}
-
-// !SECTION
+ * This file intentionally contains no pipeline/function definitions.
+ * Use the sub-templates to generate specific configuration fragments:
+ * - alloy.system-logs
+ * - alloy.system-metrics
+ * - alloy.docker-metrics
+ * - alloy.docker-logs
+ *
+ * When generating a full configuration you can concatenate the generated
+ * fragments into `config/config.alloy` or manage them as separate files.
+ */
+
+// Minimal placeholder - no functions here by design.

+ 10 - 1
library/compose/alloy/template.yaml

@@ -3,7 +3,10 @@ kind: compose
 metadata:
   name: Grafana Alloy
   description: |
-    Open-source telemetry collector and a distribution of the OpenTelemetry Collector, designed to gather and process logs, metrics, traces, and profiles from your applications and infrastructure. It integrates features from the OpenTelemetry Collector and Prometheus, offering programmable pipelines with a rich, expression-based syntax and support for multiple observability ecosystems. Alloy functions as a powerful, high-performance, and vendor-neutral tool for observability, acting as a successor to the Grafana Agent and providing enhanced features for scaling and managing telemetry data.
+    Grafana Alloy is an open telemetry collector distribution that gathers and
+    processes logs, metrics, traces and profiles. It combines features from the
+    OpenTelemetry Collector and Prometheus and provides programmable pipelines
+    and high-performance, vendor-neutral observability.
 
     Project: https://grafana.com/docs/alloy/
     Source: https://github.com/grafana/alloy
@@ -19,4 +22,10 @@ spec:
     vars:
       container_hostname:
         extra: This is needed because when alloy runs in a container, it doesn't know the hostname of the docker host.
+  ports:
+    vars:
+      ports_main:
+        type: int
+        description: Main port for Alloy HTTP server
+        default: 12345
 ---