initial commit

This commit is contained in:
TakuyaYagam1 committed 2026-10-05 14:23:31 +03:00
commit 88c14b627e
224 files changed
+17204

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
*.log
/.cache/
/.DS_Store
+29
View File
@@ -0,0 +1,29 @@
.DEFAULT_GOAL := help
ROOT := $(abspath ..)
DOCKER ?= docker
ALLOY_IMAGE := grafana/alloy:latest
PROMETHEUS_IMAGE := prom/prometheus:latest
LOKI_IMAGE := grafana/loki:latest
ALLOY_FILE := $(ROOT)/observability/alloy/app.alloy
.PHONY: help fmt fmt-check check
help: ## Show observability commands
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf "%-18s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
fmt: ## Format Alloy config and Grafana dashboards
$(DOCKER) run --rm -v "$(ROOT)/observability/alloy:/work" "$(ALLOY_IMAGE)" fmt --write /work/app.alloy
@python3 -c 'import json, pathlib; paths=sorted(pathlib.Path("$(ROOT)/observability/grafana/dashboards").glob("*.json")); [p.write_text(json.dumps(json.loads(p.read_text()), indent=2) + "\n") for p in paths]'
fmt-check: ## Check Alloy formatting and dashboard JSON formatting
@tmp=$$(mktemp); trap 'rm -f "$$tmp"' EXIT; \
$(DOCKER) run --rm -v "$(ROOT)/observability/alloy:/work:ro" "$(ALLOY_IMAGE)" fmt /work/app.alloy > "$$tmp"; \
diff -u "$(ALLOY_FILE)" "$$tmp"
@python3 -c 'import json, pathlib, sys; bad=[]; root=pathlib.Path("$(ROOT)/observability/grafana/dashboards"); paths=sorted(root.glob("*.json")); [(bad.append(str(p)) if p.read_text() != json.dumps(json.loads(p.read_text()), indent=2) + "\n" else None) for p in paths]; print("dashboard formatting is clean" if not bad else "dashboard JSON formatting differs: " + ", ".join(bad)); sys.exit(bool(bad))'
check: fmt-check ## Validate Prometheus, Loki, Alloy, and dashboard files
$(DOCKER) run --rm --entrypoint /bin/promtool -v "$(ROOT)/observability/prometheus:/etc/prometheus:ro" "$(PROMETHEUS_IMAGE)" check config /etc/prometheus/prometheus.yml
$(DOCKER) run --rm -v "$(ROOT)/observability/loki:/etc/loki:ro" "$(LOKI_IMAGE)" -config.file=/etc/loki/loki.yml -verify-config
$(DOCKER) run --rm -v "$(ROOT)/observability/alloy:/etc/alloy:ro" "$(ALLOY_IMAGE)" validate /etc/alloy/app.alloy
@python3 -c 'import json, pathlib; files=sorted(pathlib.Path("$(ROOT)/observability/grafana/dashboards").glob("*.json")); [json.loads(path.read_text()) for path in files]; assert files, "no Grafana dashboards found"; print(f"validated {len(files)} dashboard JSON file(s)")'
+75
View File
@@ -0,0 +1,75 @@
discovery.docker "application" {
host = "tcp://docker-socket-proxy:2375"
refresh_interval = "30s"
filter {
name = "label"
values = ["com.docker.compose.project=" + sys.env("APP_PROJECT")]
}
}
discovery.relabel "application" {
targets = discovery.docker.application.targets
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "backend|frontend|postgres"
action = "keep"
}
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
target_label = "service"
}
rule {
target_label = "environment"
replacement = "local"
}
}
loki.source.docker "application" {
host = "tcp://docker-socket-proxy:2375"
targets = discovery.relabel.application.output
labels = {"environment" = "local"}
forward_to = [loki.process.application.receiver]
}
loki.process "application" {
forward_to = [loki.write.local.receiver]
stage.label_keep {
values = ["service", "environment"]
}
}
faro.receiver "browser" {
extra_log_labels = {
"service" = "frontend",
"environment" = "local",
}
server {
listen_address = "0.0.0.0"
listen_port = 12347
max_allowed_payload_size = "1MiB"
}
output {
logs = [loki.process.browser.receiver]
}
}
loki.process "browser" {
forward_to = [loki.write.local.receiver]
stage.label_keep {
values = ["service", "environment"]
}
}
loki.write "local" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}
@@ -0,0 +1,262 @@
{
"annotations": {
"list": []
},
"editable": false,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "up{job=\"backend\"}",
"legendFormat": "backend",
"refId": "A"
}
],
"title": "Backend scrape status",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "cores"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "rate(process_cpu_seconds_total{job=\"backend\"}[5m])",
"legendFormat": "CPU cores",
"refId": "A"
}
],
"title": "Process CPU",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"id": 3,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "process_resident_memory_bytes{job=\"backend\"}",
"legendFormat": "resident memory",
"refId": "A"
}
],
"title": "Resident memory",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"id": 4,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "go_goroutines{job=\"backend\"}",
"legendFormat": "goroutines",
"refId": "A"
}
],
"title": "Go goroutines",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 16
},
"id": 5,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "go_memstats_heap_alloc_bytes{job=\"backend\"}",
"legendFormat": "heap allocated",
"refId": "A"
}
],
"title": "Go heap allocation",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 41,
"tags": [
"go",
"runtime"
],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timezone": "browser",
"title": "Go runtime",
"uid": "go-runtime",
"version": 1
}
@@ -0,0 +1,262 @@
{
"annotations": {
"list": []
},
"editable": false,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "up{job=\"postgres\"}",
"legendFormat": "postgres exporter",
"refId": "A"
}
],
"title": "Exporter scrape status",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "pg_stat_database_numbackends{datname!~\"template.*\"}",
"legendFormat": "{{datname}}",
"refId": "A"
}
],
"title": "Connections by database",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "ops"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"id": 3,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "rate(pg_stat_database_xact_commit[5m])",
"legendFormat": "{{datname}} commits",
"refId": "A"
}
],
"title": "Committed transactions per second",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "ops"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"id": 4,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "rate(pg_stat_database_deadlocks[5m])",
"legendFormat": "{{datname}} deadlocks",
"refId": "A"
}
],
"title": "Deadlocks per second",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 16
},
"id": 5,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "pg_database_size_bytes",
"legendFormat": "{{datname}}",
"refId": "A"
}
],
"title": "Database size",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 41,
"tags": [
"postgres",
"database"
],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timezone": "browser",
"title": "PostgreSQL",
"uid": "postgres",
"version": 1
}
@@ -0,0 +1,221 @@
{
"annotations": {
"list": []
},
"editable": false,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"max": 100,
"min": 0,
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode=\"idle\"}[5m])))",
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"title": "CPU busy",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"max": 100,
"min": 0,
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)",
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"title": "Memory used",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"id": 3,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "node_load1",
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"title": "Load average over 1 minute",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"drawStyle": "line",
"fillOpacity": 10,
"lineWidth": 1,
"showPoints": "never"
},
"max": 100,
"min": 0,
"unit": "percent"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"id": 4,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"editorMode": "code",
"expr": "100 * node_filesystem_avail_bytes{mountpoint=\"/\"} / node_filesystem_size_bytes{mountpoint=\"/\"}",
"legendFormat": "{{instance}} root free",
"refId": "A"
}
],
"title": "Root filesystem free",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 41,
"tags": [
"system",
"host"
],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timezone": "browser",
"title": "Linux system",
"uid": "system",
"version": 1
}
@@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: Lincodex
orgId: 1
folder: Lincodex
type: file
disableDeletion: true
editable: false
updateIntervalSeconds: 60
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,22 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
uid: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: false
jsonData:
httpMethod: GET
timeInterval: 30s
- name: Loki
type: loki
uid: loki
access: proxy
url: http://loki:3100
editable: false
jsonData:
maxLines: 1000
+45
View File
@@ -0,0 +1,45 @@
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /loki
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
schema_config:
configs:
- from: "2025-01-01"
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
storage_config:
filesystem:
directory: /loki/chunks
tsdb_shipper:
active_index_directory: /loki/index
cache_location: /loki/index_cache
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
limits_config:
retention_period: 168h
analytics:
reporting_enabled: false
+31
View File
@@ -0,0 +1,31 @@
global:
scrape_interval: 30s
evaluation_interval: 30s
scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- prometheus:9090
- job_name: backend
metrics_path: /metrics
static_configs:
- targets:
- backend:9090
- job_name: postgres
static_configs:
- targets:
- postgres-exporter:9187
- job_name: node
static_configs:
- targets:
- node-exporter:9100
- job_name: ml
metrics_path: /metrics
file_sd_configs:
- files:
- /etc/prometheus/targets/ml.yml
+1
View File
@@ -0,0 +1 @@
[]