feat: enhance observability with dynamic links, Docker API integration, and health checks

This commit is contained in:
asepharyana
2026-07-22 18:12:44 +07:00
parent 4ef4f615c1
commit da268f1671
7 changed files with 194 additions and 103 deletions
+7
View File
@@ -49,6 +49,13 @@ services:
- dashboard - dashboard
ports: ports:
- '8080:8080' - '8080:8080'
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
jaeger:
condition: service_started
otel-collector:
condition: service_started
networks: networks:
app-shared-net: app-shared-net:
+4 -4
View File
@@ -50,10 +50,10 @@ services:
- '--experimental.plugins.blockpath.moduleName=github.com/traefik/plugin-blockpath' - '--experimental.plugins.blockpath.moduleName=github.com/traefik/plugin-blockpath'
- '--experimental.plugins.blockpath.version=v0.2.1' - '--experimental.plugins.blockpath.version=v0.2.1'
- '--ping=true' - '--ping=true'
- '--tracing.openTelemetry=true' - '--tracing.otel=true'
- '--tracing.openTelemetry.address=otel-collector:4318' - '--tracing.otel.address=otel-collector:4318'
- '--tracing.openTelemetry.insecure=true' - '--tracing.otel.insecure=true'
- '--tracing.openTelemetry.grpc=false' - '--tracing.otel.grpc=false'
- '--tracing.serviceName=traefik' - '--tracing.serviceName=traefik'
healthcheck: healthcheck:
test: ['CMD', 'wget', '--spider', 'http://localhost:8080/ping'] test: ['CMD', 'wget', '--spider', 'http://localhost:8080/ping']
+98 -30
View File
@@ -166,14 +166,11 @@
<!-- Links --> <!-- Links -->
<div class="card"> <div class="card">
<h2>Quick Links</h2> <h2>Quick Links</h2>
<div class="links"> <div class="links" id="quick-links">
<a href="/jaeger" target="_blank">Jaeger UI</a> <div class="loading">Loading...</div>
<a href="/api/metrics" target="_blank">OTel Metrics</a>
<a href="https://traefik.asepharyana.my.id" target="_blank">Traefik</a>
<a href="https://scraper.asepharyana.my.id" target="_blank">Scraper API</a>
<a href="https://github.com/asepharyana/asepharyana-hub" target="_blank">GitHub</a>
</div> </div>
</div> </div>
</div>
<!-- Recent Traces --> <!-- Recent Traces -->
<div class="card" style="grid-column: 1 / -1;"> <div class="card" style="grid-column: 1 / -1;">
@@ -184,6 +181,7 @@
<script> <script>
const JAEGER_API = '/api/jaeger'; const JAEGER_API = '/api/jaeger';
const DOCKER_API = '/api/docker';
const TRACE_LIMIT = 20; const TRACE_LIMIT = 20;
async function fetchJSON(url) { async function fetchJSON(url) {
@@ -283,39 +281,64 @@ async function loadServices() {
const countEl = document.getElementById('service-count'); const countEl = document.getElementById('service-count');
const statSvc = document.getElementById('stat-services'); const statSvc = document.getElementById('stat-services');
const services = [ let dockerContainers = [];
{ name: 'traefik', port: 'traefik' }, try {
{ name: 'redis', port: 'redis' }, // Fetch all running containers via Docker API
{ name: 'nats', port: 'nats' }, const containers = await fetchJSON(`${DOCKER_API}/containers/json?all=true`);
{ name: 'dapr-placement', port: 'dapr-placement' }, // Filter for containers in app-shared-net network
{ name: 'scraper-api', port: 'scraper-api' }, dockerContainers = containers.filter(c => {
{ name: 'scraper-api-dapr', port: 'scraper-api-dapr' }, const nets = c.NetworkSettings && c.NetworkSettings.Networks;
{ name: 'otel-collector', port: 'otel-collector' }, return nets && nets['app-shared-net'];
{ name: 'jaeger', port: 'jaeger' }, });
]; } catch(e) { /* Docker socket not available */ }
// Try to get services from Jaeger for display // Also discover services from Jaeger (OTel-instrumented services)
let jaegerServices = []; let jaegerServices = [];
try { try {
const svcRes = await fetchJSON(`${JAEGER_API}/api/services`); const svcRes = await fetchJSON(`${JAEGER_API}/api/services`);
jaegerServices = svcRes.data || []; jaegerServices = svcRes.data || [];
} catch(e) { /* ignore */ } } catch(e) { /* ignore */ }
// Determine services to display: prefer Jaeger-reported + infrastructure // Merge: Docker names + Jaeger services, with status from Docker
const allNames = new Set([...services.map(s => s.name), ...jaegerServices]); const dockerMap = new Map();
const displayNames = Array.from(allNames).sort(); for (const c of dockerContainers) {
countEl.textContent = displayNames.length; // Docker returns Names as ["/name"] — strip leading /
statSvc.textContent = displayNames.length; const name = (c.Names && c.Names[0]) ? c.Names[0].replace(/^\//, '') : c.Id.slice(0, 12);
const state = c.State || 'unknown';
const status = c.Status || '';
const image = c.Image || '';
dockerMap.set(name, { name, state, status, image });
}
listEl.innerHTML = displayNames.map(name => { // Merge Jaeger-only services (those not in Docker network)
// Determine status: Jaeger services are "up", check others via probe for (const svc of jaegerServices) {
// Simple heuristic: green if in Docker services list, yellow for Jaeger-only if (!dockerMap.has(svc)) {
const infraService = services.find(s => s.name === name); dockerMap.set(svc, { name: svc, state: 'jaeger', status: 'seen via OTel', image: '' });
const status = infraService ? 'up' : 'degraded'; }
const badgeClass = status === 'up' ? 'badge-up' : 'badge-degraded'; }
const label = status === 'up' ? 'up' : 'unknown';
// Sort: running first, then by name
const entries = Array.from(dockerMap.values()).sort((a, b) => {
const order = { running: 0, jaeger: 1, paused: 2, exited: 3, restarting: 3, unknown: 4 };
return (order[a.state] || 4) - (order[b.state] || 4) || a.name.localeCompare(b.name);
});
countEl.textContent = entries.length;
statSvc.textContent = entries.length;
listEl.innerHTML = entries.map(svc => {
let badgeClass, label;
if (svc.state === 'running') {
badgeClass = 'badge-up'; label = 'up';
} else if (svc.state === 'jaeger') {
badgeClass = 'badge-degraded'; label = 'otel';
} else if (svc.state === 'paused') {
badgeClass = 'badge-degraded'; label = 'paused';
} else {
badgeClass = 'badge-down'; label = 'down';
}
return `<div class="service-item"> return `<div class="service-item">
<span class="name">${escHtml(name)}</span> <span class="name">${escHtml(svc.name)}</span>
<span class="badge ${badgeClass}">${label}</span> <span class="badge ${badgeClass}">${label}</span>
</div>`; </div>`;
}).join(''); }).join('');
@@ -354,6 +377,50 @@ async function loadStats() {
} catch(e) { /* ignore - stats may not load */ } } catch(e) { /* ignore - stats may not load */ }
} }
async function loadLinks() {
const el = document.getElementById('quick-links');
try {
const containers = await fetchJSON(`${DOCKER_API}/containers/json?all=true`);
const svcNames = containers
.filter(c => {
const nets = c.NetworkSettings && c.NetworkSettings.Networks;
return nets && nets['app-shared-net'];
})
.map(c => (c.Names && c.Names[0]) ? c.Names[0].replace(/^\//, '') : '')
.filter(Boolean);
const links = [
{ href: '/jaeger', label: 'Jaeger UI', icon: '🔍' },
{ href: '/api/metrics', label: 'OTel Metrics', icon: '📊' },
{ href: 'https://github.com/asepharyana/asepharyana-hub', label: 'GitHub', icon: '📦' },
];
// Dynamic links: add if container name matches a known Traefik route pattern
const domains = ['asepharyana.my.id', 'asepharyana.web.id'];
for (const name of svcNames) {
if (name === 'dashboard') {
links.push({ href: `https://dashboard.${domains[0]}`, label: 'Dashboard', icon: '📈' });
} else if (name === 'jaeger') {
// already added above
} else if (name === 'traefik') {
links.push({ href: `https://traefik.${domains[0]}`, label: 'Traefik', icon: '🔒' });
} else if (name.endsWith('-dapr')) {
// skip dapr sidecars — they don't have their own routes
} else if (name !== 'redis' && name !== 'nats' && name !== 'dapr-placement' && name !== 'otel-collector') {
links.push({ href: `https://${name}.${domains[0]}`, label: name, icon: '🔗' });
}
}
el.innerHTML = links.map(l => `<a href="${l.href}" target="_blank">${l.icon} ${escHtml(l.label)}</a>`).join('');
} catch(e) {
// Fallback: show minimal static links if Docker socket unavailable
el.innerHTML = `
<a href="/jaeger" target="_blank">Jaeger UI</a>
<a href="/api/metrics" target="_blank">OTel Metrics</a>
<a href="https://github.com/asepharyana/asepharyana-hub" target="_blank">GitHub</a>`;
}
}
function setHealth(status, label) { function setHealth(status, label) {
const el = document.getElementById('health-indicator'); const el = document.getElementById('health-indicator');
el.innerHTML = `<span class="dot" style="background:var(--${status})"></span> ${label}`; el.innerHTML = `<span class="dot" style="background:var(--${status})"></span> ${label}`;
@@ -365,6 +432,7 @@ async function refresh() {
loadTraces(), loadTraces(),
loadServices(), loadServices(),
loadStats(), loadStats(),
loadLinks(),
]); ]);
setHealth('green', 'All Systems Operational'); setHealth('green', 'All Systems Operational');
} catch(e) { } catch(e) {
+78 -56
View File
@@ -1,70 +1,92 @@
server { # Dashboard nginx — runs as root to access Docker socket
listen 8080; user root;
server_name localhost; worker_processes auto;
root /usr/share/nginx/html; pid /var/run/nginx.pid;
index index.html; pcre_jit on;
# CORS headers for API endpoints events {
add_header Access-Control-Allow-Origin *; worker_connections 1024;
add_header Access-Control-Allow-Methods "GET, OPTIONS"; }
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range";
# Security headers http {
add_header X-Frame-Options DENY; include /etc/nginx/mime.types;
add_header X-Content-Type-Options nosniff; default_type application/octet-stream;
add_header Referrer-Policy same-origin;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
# Gzip # Gzip
gzip on; gzip on;
gzip_types text/html text/css application/javascript application/json; gzip_types text/html text/css application/javascript application/json;
# Jaeger API proxy server {
location /api/jaeger/ { listen 8080;
proxy_pass http://jaeger:16686/; server_name localhost;
proxy_set_header Host $host; root /usr/share/nginx/html;
proxy_set_header X-Real-IP $remote_addr; index index.html;
proxy_http_version 1.1;
proxy_read_timeout 30s;
}
# Jaeger UI # Security headers
location /jaeger/ { add_header X-Frame-Options DENY;
proxy_pass http://jaeger:16686/; add_header X-Content-Type-Options nosniff;
proxy_set_header Host $host; add_header Referrer-Policy same-origin;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
}
# OTel collector prometheus metrics # Jaeger API proxy
location /api/metrics { location /api/jaeger/ {
proxy_pass http://otel-collector:8889/metrics; proxy_pass http://jaeger:16686/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_read_timeout 10s; proxy_set_header X-Real-IP $remote_addr;
} proxy_http_version 1.1;
proxy_read_timeout 30s;
}
# OTel collector health # Jaeger UI
location /api/health { location /jaeger/ {
proxy_pass http://otel-collector:8888/healthz; proxy_pass http://jaeger:16686/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_read_timeout 5s; proxy_set_header X-Real-IP $remote_addr;
} proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
}
# Static files (including index.html) # OTel collector prometheus metrics
location / { location /api/metrics {
try_files $uri $uri/ /index.html; proxy_pass http://otel-collector:8889/metrics;
expires 5s; proxy_set_header Host $host;
add_header Cache-Control "public, must-revalidate"; proxy_read_timeout 10s;
} }
# Deny hidden files # OTel collector health
location ~ /\. { location /api/health {
deny all; proxy_pass http://otel-collector:13133/;
access_log off; proxy_set_header Host $host;
log_not_found off; proxy_read_timeout 5s;
} }
error_page 404 /index.html; # Docker API proxy (read-only Unix socket)
location /api/docker/ {
proxy_pass http://unix:/var/run/docker.sock:/;
proxy_set_header Host $host;
proxy_read_timeout 10s;
}
# Static files
location / {
try_files $uri $uri/ /index.html;
expires 5s;
add_header Cache-Control "public, must-revalidate";
}
# Deny hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
error_page 404 /index.html;
}
} }
+2 -1
View File
@@ -1,5 +1,6 @@
FROM nginx:alpine FROM nginx:alpine
COPY infra/dashboard/nginx.conf /etc/nginx/conf.d/default.conf # Replace default nginx.conf with our custom config (runs as root for Docker socket access)
COPY infra/dashboard/nginx.conf /etc/nginx/nginx.conf
COPY infra/dashboard/index.html /usr/share/nginx/html/index.html COPY infra/dashboard/index.html /usr/share/nginx/html/index.html
EXPOSE 8080 EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]
-12
View File
@@ -4,20 +4,8 @@
jetstream: true jetstream: true
store_dir: "/data" store_dir: "/data"
# OpenTelemetry tracing
otel {
traces {
exporter: "otlp"
otlp {
endpoint: "otel-collector:4318"
insecure: true
}
}
}
# HTTP monitoring # HTTP monitoring
http_port: 8222 http_port: 8222
# Limits # Limits
max_payload: 1MB max_payload: 1MB
max_pending_size: 64MB
+5
View File
@@ -39,7 +39,12 @@ processors:
value: asepharyana-hub value: asepharyana-hub
action: upsert action: upsert
extensions:
health_check:
endpoint: 0.0.0.0:13133
service: service:
extensions: [health_check]
pipelines: pipelines:
traces: traces:
receivers: [otlp] receivers: [otlp]