Build a 2026 AI-Powered Incident Postmortem Writer for Indian SRE Teams with Bun.js, Elysia.js, Grafana Loki, and Ollama: A Self-Hosted Tutorial
Learn how to automate incident postmortems for Indian SRE teams using Bun.js, Elysia.js, Grafana Loki, and a self-hosted Ollama LLM—no cloud lock-in, full data sovereignty.
Agentic Academy Labs
Author
Why Indian SRE Teams Need AI Postmortems in 2026
Site Reliability Engineering in India has scaled massively by 2026. From Bangalore fintech unicorns to Hyderabad SaaS scaleups, on-call engineers face 3x more incidents than in 2023. Writing postmortems is mandatory—but it eats 2–4 hours per incident.
The fix? A self-hosted AI pipeline that pulls logs from Grafana Loki and drafts a blameless postmortem using a local Ollama model. You keep data inside your VPC, satisfy DPDP Act 2023 compliance, and ship docs in minutes.
The 2026 Stack at a Glance
We use a lean, modern, edge-ready toolchain:
- Bun.js — all-in-one JS runtime, bundler, and test runner (3x faster than Node in 2026 benchmarks)
- Elysia.js — typed, ergonomic web framework for Bun
- Grafana Loki — log aggregation already running in most Indian SRE setups
- Ollama — self-hosted LLM (we use
llama3.1:8borqwen2.5:7bfor Hindi-mixed logs)
Step 1: Scaffold with Bun and Elysia
Install Bun (if not already) and create the project:
curl -fsSL https://bun.sh/install | bash
bun create elysia postmortem-ai
cd postmortem-ai
bun add @elysiajs/cors loki-client
Boot the server with a health route:
import { Elysia } from 'elysia'
import { cors } from '@elysiajs/cors'
const app = new Elysia()
.use(cors())
.get('/health', () => ({ ok: true, ts: new Date().toISOString() }))
.listen(3000)
console.log('Postmortem AI on :3000')
Run it: bun run index.ts. You now have a 12KB-memory idle server.
Step 2: Query Grafana Loki for Incident Logs
Most Indian teams already pipe Kubernetes and systemd logs to Loki. We add a helper to fetch a time-window:
import { Loki } from 'loki-client'
const loki = new Loki({ url: Bun.env.LOKI_URL! })
export async function getIncidentLogs(
service: string,
start: string,
end: string
) {
const q = `{service="${service}"} | json`
const res = await loki.queryRange(q, start, end)
return res.data.result.flatMap(r =>
r.values.map(v => v[1])
).join('\n')
}
Tip: Use IST timestamps (+05:30) so on-call reads naturally align with your war-room clock.
Step 3: Self-Hosted Summarization with Ollama
Install Ollama on your Bangalore bare-metal or Mumbai EC2:
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.1:8b
Add a local inference call—no API keys, no egress:
async function draftPostmortem(logs: string) {
const sys = `You are an SRE co-pilot. Write a blameless postmortem in Markdown with: Summary, Impact, Root Cause, Timeline, Action Items. Use Indian English.`
const r = await fetch('http://localhost:11434/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'llama3.1:8b',
prompt: `${sys}\n\nLOGS:\n${logs.slice(0, 12000)}`,
stream: false
})
})
const j = await r.json()
return j.response
}
Step 4: Wire the Endpoint
Combine Loki + Ollama into one POST route:
app.post('/postmortem', async ({ body }) => {
const { service, start, end } = body as any
const logs = await getIncidentLogs(service, start, end)
const md = await draftPostmortem(logs)
return { markdown: md, generatedAt: new Date().toISOString() }
})
Test it from your Pune office laptop:
curl -X POST localhost:3000/postmortem \
-H 'content-type: application/json' \
-d '{"service":"payments-api","start":"2026-01-12T08:00:00+05:30","end":"2026-01-12T09:30:00+05:30"}'
Why This Matters for Indian Compliance
In 2026, the DPDP Act is fully enforced. Sending prod logs to US-hosted LLMs risks penalties. A self-hosted Ollama + Bun stack means:
- Log data never leaves your account
- No per-token billing in dollars
- Works offline during fiber cuts (common in tier-2 cities)
Deploy and Scale
Bundle with Bun and ship as a sidecar in your cluster:
bun build index.ts --target bun --outfile pm.ai
Run behind your existing Traefik ingress with mTLS. For 50 engineers, an 8GB RAM node handles 20 concurrent drafts.
Final Thoughts
By combining Bun.js speed, Elysia.js simplicity, Loki ubiquity, and Ollama sovereignty, Indian SRE teams in 2026 can turn 3 hours of writing into 3 minutes of review. Start small, self-host, and let your on-call finally sleep.
Build it this sprint. Your future incident self will thank you.
Enjoyed this article?
Read More Articles