<div align="center">
  <img src="https://capsule-render.vercel.app/api?type=rect&height=130&color=0:0ea5e9,100:22c55e&text=Concurrent%20Log%20Collector&fontSize=34&fontColor=ffffff&animation=fadeIn&fontAlignY=55" />
  <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=14&duration=2200&pause=700&color=22C55E&center=true&vCenter=true&width=900&lines=Set+path+log+%2B+endpoint+%E2%86%92+run+service+%E2%86%92+lihat+metrik+di+dashboard;Goroutine+tail+%2B+parse+%E2%86%92+hitung+metrik+%E2%86%92+batch+send+%2B+retry+terukur;Handle+log+rotate%2C+backpressure%2C+dan+retry+exponential+backoff+secara+aman" />
  <br/>
  <img src="https://skillicons.dev/icons?i=go&perline=2" />
</div>

---

## Tujuan dan Manfaat
## **Concurrent Log Collector** membantu monitoring incident dengan cara **tail banyak log secara paralel (goroutine)**, **parse**, **hitung metrik**, lalu **tampilkan dashboard real-time**.
## Manfaat utama: **deteksi error lebih cepat**, **ringkasan metrik rapi**, dan **opsional kirim batch metrik ke endpoint**.

---

## Bahasa dan Teknologi
- ✅ **Go**
- ✅ **Go Module**
- ✅ **HTTP Dashboard (built-in)**
- ✅ **Metrics endpoint (Prometheus-style text)**

---

## Instalasi dan Persiapan
## **Requirement**
- ✅ Windows / Linux / macOS
- ✅ **Go 1.22+** (mengikuti `go.mod`)

## **Install Go (Windows PowerShell)**
```powershell
winget install GoLang.Go
go version
```

## **Clone Proyek**
```powershell
git clone https://github.com/yirassssindaba-coder/Go.git
cd Go
```

---

## Proyek Full
## Source code lengkap sudah tersedia di repository ini (termasuk contoh log di folder `examples/` dan contoh konfigurasi `config.example.json`).

---

## Struktur File Proyek
```text
Go/
├─ README.md
├─ aggregate.go
├─ concurrent-log-collector
├─ config.example.json
├─ config.json
├─ dashboard.go
├─ go.mod
├─ main.go
├─ metrics.go
├─ oswrap.go
├─ parser.go
├─ sender.go
├─ tailer.go
└─ examples/
   └─ app.log
```

---

## Cara Menjalankan
## **Opsi A — Jalankan pakai config (disarankan)**
## 1) Salin contoh config:
```powershell
copy .\config.example.json .\config.json
```

## 2) Jalankan service:
```powershell
go mod tidy
go run . -config .\config.json
```

## **Opsi B — Override cepat via flag**
```powershell
go run . -logs ".\examples\app.log" -endpoint "http://localhost:9000/ingest" -addr ":8080"
```

---

## Cara Pakai
## **1) Set path log + endpoint**
## Edit `config.json`:
- ✅ `logs` → daftar path file log yang mau di-tail
- ✅ `endpoint` → URL tujuan POST batch metrik (boleh kosong `""` kalau dashboard-only)
- ✅ `dashboard_addr` → alamat dashboard (default `:8080`)

## **2) Lihat metrik di dashboard**
- ✅ Dashboard: `http://localhost:8080`
- ✅ API Snapshot JSON: `http://localhost:8080/api/metrics`
- ✅ Preview payload batch: `http://localhost:8080/api/preview`
- ✅ Text metrics: `http://localhost:8080/metrics`

---

## Preview
## **Cek cepat dari terminal**
```powershell
# Snapshot JSON
curl http://localhost:8080/api/metrics

# Preview payload batch
curl http://localhost:8080/api/preview

# Prometheus-style text
curl http://localhost:8080/metrics
```

---

## Anti-Error dan Troubleshooting
## Tool ini punya proteksi untuk kondisi yang sering bikin monitoring “ngaco”.
- ✅ **Log rotate / truncate** → terdeteksi saat ukuran file lebih kecil dari offset → reopen otomatis
- ✅ **Backpressure** → antrean log line dibatasi; kalau penuh → drop terukur + counter `dropped_lines_total`
- ✅ **Retry terukur** → POST batch pakai exponential backoff + retry max (config)

## Jika port 8080 bentrok
```powershell
go run . -config .\config.json -addr ":9090"
```

## Jika `go` tidak dikenali
```powershell
go env
go version
```
