darpan 0.2.0

Linux developer service monitoring utility with auto-detection, real-time health checks, and interactive TUI for databases, APIs, Docker containers, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# Darpan(दर्पण) - Linux Developer Service Monitor

> **Darpan** (दर्पण) means "mirror" in Sanskrit - a real-time reflection of your entire development environment.

[  ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[  ![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/)

**Stop checking services one by one.** Darpan shows you everything at a glance.

## 📋 Table of Contents

* [What is Darpan?]#what-is-darpan
* [Why Use Darpan?]#why-use-darpan
* [Installation]#installation
* [Quick Start Tutorial]#quick-start-tutorial
* [Detailed Usage Guide]#detailed-usage-guide
* [Configuration]#configuration
* [Real-World Examples]#real-world-examples
* [Troubleshooting]#troubleshooting
* [Advanced Features]#advanced-features


---

## 🎯 What is Darpan?

Darpan is a **developer-friendly service monitoring tool** for Linux that automatically detects and monitors all your development services in one place.

### The Problem It Solves

As a developer, you probably run multiple services:

```bash
# You do this all day:
docker ps                          # Check Docker
systemctl status postgresql        # Check PostgreSQL
redis-cli ping                     # Check Redis
curl localhost:3000               # Check your app
lsof -i :8080                     # Find what's on port 8080
```

**This is tedious and time-consuming!**

### The Solution

With Darpan:

```bash
darpan watch    # See everything at once!
```

**One command** shows you:

* ✅ All running services
* ✅ Their health status
* ✅ Response times
* ✅ Why services are down
* ✅ Live activity logs


---

## 💡 Why Use Darpan?

### For Solo Developers

* 🚀 **Start your day faster**: Know what's running before you begin coding
* 🔍 **Debug quicker**: Instantly see which service is down
* 🧘 **Reduce cognitive load**: One tool instead of 10 commands

### For Teams

* 📊 **Shared understanding**: Everyone sees the same service status
* 🎯 **Faster onboarding**: New devs understand the stack immediately
* 🔧 **Better debugging**: "Is Redis down for you too?"

### Key Features

* 🔎 **Auto-detection**: Finds services automatically (ports, processes, Docker)
* ❤️ **Health checks**: Port, HTTP, database-specific checks
* 🖥️ **Two interfaces**: CLI for quick checks, TUI for monitoring
* ⚙️ **Zero config**: Works immediately, configure only when needed
* 🐳 **Docker aware**: Detects and monitors containers
* 📱 **Lightweight**: <20MB RAM, <5.5MB binary


---

## 📦 Installation

### Prerequisites

* **Operating System**: Linux (Ubuntu, Debian, Arch, etc.)
* **Rust**: 1.70 or later (for building from source)
* **Optional**: Docker (for Docker container detection)

### Method 1: Build from Source (Recommended)

#### Step 1: Clone the Repository

```bash
cd ~
git clone https://github.com/codeBunny2022/darpan.git
cd darpan
```

#### Step 2: Build and Install

```bash
# Build the release version (optimized)
cargo build --release

# Install globally (requires sudo)
sudo cp target/release/darpan /usr/local/bin/

# Or install for current user only
cargo install --path .
```

#### Step 3: Verify Installation

```bash
darpan --version
# Output: darpan 0.1.0
```

✅ **Done!** Darpan is now available system-wide.

### Method 2: Install via Cargo (Future)

```bash
# Coming soon!
cargo install darpan
```


---

## 🚀 Quick Start Tutorial

Let's learn Darpan with a hands-on tutorial!

### Tutorial 1: Your First Status Check

#### Step 1: Check What's Running

Open a terminal and run:

```bash
darpan status
```

**What you'll see:**

```
Project: your-current-directory

╭───────────┬────────────┬──────────┬────────────────┬──────────╮
│ STATUS    │ NAME       │ TYPE     │ HOST:PORT      │ RESPONSE │
├───────────┼────────────┼──────────┼────────────────┼──────────┤
│ ✓ Healthy │ PostgreSQL │ Database │ localhost:5432 │ 12ms     │
│ ✓ Healthy │ Redis      │ Cache    │ localhost:6379 │ 3ms      │
╰───────────┴────────────┴──────────┴────────────────┴──────────╯

All 2 services are healthy ✓
```

**Understanding the output:**

* **Green checkmark**: Service is healthy
***Yellow warning**: Service is degraded
***Red X**: Service is down
* **Response time**: How long the health check took

#### Step 2: Understand What Was Detected

Darpan automatically found:

* **PostgreSQL** on port 5432 (standard PostgreSQL port)
* **Redis** on port 6379 (standard Redis port)

**How?** Darpan:


1. Scanned localhost ports 3000-9999
2. Found open ports 5432 and 6379
3. Identified them as PostgreSQL and Redis
4. Checked their health

### Tutorial 2: Interactive Monitoring

#### Step 1: Launch the TUI (Terminal User Interface)

```bash
darpan watch
```

**What you'll see:**

```
╔═══════════════════════════════════════════════╗
║  Darpan - your-directory | Live Monitor      ║
╠═══════════════════════════════════════════════╣
║ >> ✓ PostgreSQL    Database    :5432    12ms ║
║    ✓ Redis          Cache       :6379     3ms ║
╠═══════════════════════════════════════════════╣
║ Quick Info:                                   ║
║   Service: PostgreSQL                         ║
║   Status: ✓ HEALTHY                           ║
╠═══════════════════════════════════════════════╣
║ Live Logs:                                    ║
║   [18:13:33] Detected 2 services              ║
║   [18:13:38] Health check: 2/2 healthy        ║
╠═══════════════════════════════════════════════╣
║ q: quit | Enter: details | ↑↓: navigate      ║
╚═══════════════════════════════════════════════╝
```

#### Step 2: Navigate and Explore

**Try these controls:**


1. **Move up/down**: Press `` and `` (or `j` and `k`)
   * Watch the `>>` selector move
   * Quick Info panel updates automatically
2. **View details**: Press `Enter` on any service
   * See full service information
   * View process ID, command line
   * See error messages and suggestions
3. **Go back**: Press `q` or `Esc`
   * Returns to main dashboard
4. **Refresh**: Press `r`
   * Forces an immediate health check
   * Watch the logs update
5. **Quit**: Press `q` from the main dashboard

#### Step 3: Watch Live Updates

Leave the TUI running for a minute:

* Auto-refreshes every 5 seconds
* Live logs show activity
* Status updates automatically
* Time since last update shown at bottom

**Try this experiment:**


1. Keep `darpan watch` running
2. In another terminal, stop a service: `sudo systemctl stop redis`
3. Watch Darpan detect it within 5 seconds!
4. Restart Redis: `sudo systemctl start redis`
5. Watch it turn green again!

### Tutorial 3: Troubleshooting a Down Service

#### Step 1: Simulate a Problem

Stop Redis temporarily:

```bash
sudo systemctl stop redis-server
```

#### Step 2: Check Status

```bash
darpan status
```

**Output:**

```
╭────────────┬────────────┬──────────┬────────────────┬──────────╮
│ STATUS     │ NAME       │ TYPE     │ HOST:PORT      │ RESPONSE │
├────────────┼────────────┼──────────┼────────────────┼──────────┤
│ ✓ Healthy  │ PostgreSQL │ Database │ localhost:5432 │ 12ms     │
│ ✗ Down     │ Redis      │ Cache    │ localhost:6379 │ N/A      │
╰────────────┴────────────┴──────────┴────────────────┴──────────╯

1/2 services healthy. 1 need attention!
```

#### Step 3: Investigate the Problem

Use the `why` command:

```bash
darpan why "Redis"
```

**Output:**

```
Service: Redis
────────────────────────────────────────────────────────
Status: DOWN ✗
Reason: Port not reachable: Connection refused
Location: localhost:6379
Process ID: Not running

Suggestion: Check if Redis is running and accepting connections

Last checked: 2026-01-20 18:30:45
```

**This tells you:**

* ❌ Redis is not running
* 📍 Expected on port 6379
* 💡 Suggestion: Check if it's running

#### Step 4: Fix the Problem

```bash
sudo systemctl start redis-server
```

#### Step 5: Verify the Fix

```bash
darpan status
```

✅ **All services are healthy!**


---

## 📚 Detailed Usage Guide

### Command Reference

#### `darpan status`

Shows current status of all services.

**Basic usage:**

```bash
darpan status
```

**Options:**

```bash
# JSON output (for scripts)
darpan status --format json

# Specific project
darpan status --path ~/my-project

# With debug logging
darpan --verbose status
```

**When to use:**

* 🌅 Starting your workday
* 🐛 Before debugging
* 🚀 Before deploying
* 🔄 After restarting services

#### `darpan watch`

Interactive TUI with live monitoring.

**Basic usage:**

```bash
darpan watch
```

**Controls:**

| Key | Action |
|----|----|
| `` / `k` | Move selection up |
| `` / `j` | Move selection down |
| `Enter` | View service details |
| `L` | View live logs for selected service |
| `q` | Quit (or back from details/logs) |
| `Esc` | Back to dashboard |
| `r` | Manual refresh |

**Log Viewer Controls:**

| Key | Action |
|----|----|
| `Space` | Pause/Resume log streaming |
| `` / `` | Scroll through logs (when paused) |
| `/` | Enter search mode |
| `1-4` | Filter by log level (1=ERROR, 2=WARN, 3=INFO, 4=DEBUG) |
| `0` | Clear all filters |
| `E` | Export logs to file |
| `q` / `Esc` | Return to service details |

**When to use:**

* 👀 Continuous monitoring
* 🔍 Troubleshooting complex issues
* 📊 During development
* 🎯 When waiting for services to start

#### `darpan why <service-name>`

Detailed troubleshooting for a specific service.

**Basic usage:**

```bash
darpan why "PostgreSQL"
darpan why "Redis"
darpan why "Backend API"
```

**Example output:**

```
Service: Backend API
────────────────────────────────────────────────────────
Status: DOWN ✗
Reason: Process not running
Location: localhost:3001
Process ID: Not found
Expected: node dist/server.js

Suggestion: Run 'npm run dev' in project directory

Last checked: 2026-01-20 18:35:22
```

**When to use:**

* ❓ Service shows as down
* 🐛 Debugging startup issues
* 📖 Learning about service configuration

#### `darpan init`

Creates a `.darpan.yml` configuration file.

**Basic usage:**

```bash
cd ~/my-project
darpan init
```

**Creates:**

```yaml
version: 1

services:
  - name: Backend API
    type: http_server
    port: 3001
    health_check:
      type: http
      path: /api/health
    tags: [critical, backend]
    
  - name: PostgreSQL
    type:
      database: postgres
    port: 5432
    health_check:
      type: postgres
      database: myapp_dev
```

**When to use:**

* 📝 Custom service names
* 🎯 Specific health checks
* 👥 Sharing config with team
* 🏷️ Organizing with tags

### Real-time Log Viewing

Darpan includes a powerful log streaming feature that lets you view real-time logs from any service directly in the TUI.

#### Accessing Logs

1. **From Dashboard:**
   - Use `↑`/`↓` to select a service
   - Press `L` to open the log viewer

2. **From Service Details:**
   - When viewing service details, press `L` to view logs

#### Supported Log Sources

Darpan automatically detects and streams logs from:

**🐳 Docker Containers**
- Full stdout/stderr streaming
- Timestamps and log metadata
- Works with all running containers

**⚙️ Systemd Services**
- Journalctl integration
- Structured log parsing
- Log levels and priorities
- Works with: postgresql, redis-server, mysql, nginx, etc.

**📁 File-based Logs**
- Auto-detects common log locations:
  - `./logs/*.log`
  - `/var/log/<service-name>/*.log`
  - `~/.pm2/logs/*.log` (PM2-managed apps)
- Real-time tailing with file watching
- Handles log rotation gracefully

**⚡ Process Output**
- Direct stdout/stderr capture via procfs
- For processes not managed by systemd
- Fallback option for custom services

#### Log Viewer Features

**Live Streaming:**
```
┌─ SERVICE LOGS: redis-server ──────────────────────────┐
│ Source: Systemd | Lines: 100 | ● LIVE (Space: pause)  │
├────────────────────────────────────────────────────────┤
│ [12:30:45.123 INFO ] Redis 7.0.15 starting            │
│ [12:30:45.145 INFO ] Running in standalone mode       │
│ [12:30:46.201 WARN ] No persistent storage configured │
│ [12:30:47.089 INFO ] Ready to accept connections:6379 │
│ [12:30:48.134 INFO ] Accepted 127.0.0.1:45678         │
```

**Search Functionality:**
- Press `/` to enter search mode
- Type your query
- Matching text is highlighted in yellow
- Press `Enter` to apply, `Esc` to cancel

**Log Level Filtering:**
- Press `1` to show only ERROR logs
- Press `2` to show only WARN logs
- Press `3` to show only INFO logs
- Press `4` to show only DEBUG logs
- Press `0` to clear filter and show all

**Pause and Scroll:**
- Press `Space` to pause live streaming
- Use `↑`/`↓` to scroll through logs (when paused)
- Resumes auto-scrolling when unpaused

**Export Logs:**
- Press `E` to export current log buffer
- Saves to: `~/.config/darpan/logs/darpan-<service>-<timestamp>.log`
- Includes metadata header with service info
- Useful for sharing or archiving

#### Configuration for Log Files

If Darpan doesn't auto-detect your log files, you can specify them in `.darpan.yml`:

```yaml
version: 1

services:
  - name: My Node App
    type: http_server
    port: 3000
    log_file: /var/log/myapp/app.log  # Custom log path
    
  - name: Custom Service
    type: custom
    port: 8080
    systemd_unit: my-custom.service  # Override systemd unit
```

#### Tips for Log Viewing

**Performance:**
- Log buffer holds last 100 lines per service
- Older logs are automatically rotated out
- Minimal memory footprint even with active streaming

**Troubleshooting Log Access:**
- **Docker logs:** Requires Docker daemon access
- **Systemd logs:** May require sudo for some services
- **Process logs:** Limited to processes owned by current user
- **File logs:** Requires read permissions on log files

**Best Practices:**
- Use search (`/`) to find specific errors quickly
- Filter by ERROR (1) to see only critical issues
- Export logs before clearing buffers for record-keeping
- Pause streaming when analyzing specific log sections

### Working with Different Projects

#### Scenario 1: Multiple Projects

You can use Darpan in any project without any setup:

**Project A: E-commerce App**

```bash
cd ~/projects/ecommerce
darpan watch
# Detects: PostgreSQL, Redis, Node.js backend, React frontend
```

**Project B: Analytics Service**

```bash
cd ~/projects/analytics
darpan watch
# Detects: MySQL, Python API, Celery workers
```

**Project C: Microservices**

```bash
cd ~/projects/microservices
darpan watch
# Detects: Multiple Docker containers, APIs
```

#### Scenario 2: Service-Specific Configs

Each project can have its own `.darpan.yml`:

**Backend API Project:**

```bash
cd ~/api-service
cat > .darpan.yml << 'EOF'
version: 1
services:
  - name: FastAPI Backend
    type: http_server
    port: 8000
    health_check:
      type: http
      path: /health
  - name: PostgreSQL
    type: { database: postgres }
    port: 5432
EOF

darpan watch
```

**Frontend Project:**

```bash
cd ~/frontend
cat > .darpan.yml << 'EOF'
version: 1
services:
  - name: React Dev Server
    type: http_server
    port: 3000
  - name: API Backend
    type: http_server
    port: 8000
    health_check:
      type: http
      path: /api/health
EOF

darpan watch
```


---

## ⚙️ Configuration

### Configuration Hierarchy

Darpan uses a three-level configuration system:

```
1. System Defaults (built-in)
   2. User Config (~/.config/darpan/config.yml)
   ↓
3. Project Config (.darpan.yml)
```

### User Configuration

Create `~/.config/darpan/config.yml` for global settings:

```bash
mkdir -p ~/.config/darpan
cat > ~/.config/darpan/config.yml << 'EOF'
global:
  theme: dark
  refresh_interval: 5  # seconds

detection:
  enabled_detectors: [config, port, process, docker]
  port_range: [3000, 9999]  # Ports to scan

health_checks:
  timeout: 3  # seconds
  retry_count: 2

projects:
  - path: ~/work/client-a
    auto_load: true
  - path: ~/work/client-b
    auto_load: true
EOF
```

### Project Configuration

Create `.darpan.yml` in your project root:

```bash
cd ~/my-project
cat > .darpan.yml << 'EOF'
version: 1

services:
  # Web Server
  - name: Backend API
    type: http_server
    port: 3001
    health_check:
      type: http
      path: /api/health
      expected_status: 200
    tags: [critical, backend]
    
  # Database
  - name: PostgreSQL
    type:
      database: postgres
    port: 5432
    health_check:
      type: postgres
      database: myapp_dev
    tags: [database, critical]
    
  # Cache
  - name: Redis
    type:
      cache: redis
    port: 6379
    health_check:
      type: redis
    tags: [cache]
    
  # Custom service
  - name: Celery Worker
    type: custom
    process: python celery_worker.py
    health_check:
      type: custom
      script: ./check_celery.sh
    tags: [worker]

# Service dependencies
dependencies:
  - service: Backend API
    depends_on: [PostgreSQL, Redis]
EOF
```

### Supported Service Types

```yaml
# HTTP Server
type: http_server

# Database
type: { database: postgres }  # postgres, mysql, mongodb, sqlite

# Cache
type: { cache: redis }  # redis, memcached

# Message Queue
type: { message_queue: rabbitmq }  # rabbitmq, kafka, redis

# Search Engine
type: { search: elasticsearch }  # elasticsearch, meilisearch

# Docker Container
type: docker_container

# Custom
type: custom
```

### Health Check Types

```yaml
# Port connectivity (default)
health_check:
  type: port

# HTTP endpoint
health_check:
  type: http
  path: /health
  expected_status: 200

# PostgreSQL
health_check:
  type: postgres
  database: mydb

# Redis
health_check:
  type: redis

# MySQL
health_check:
  type: mysql
  database: mydb

# Custom script
health_check:
  type: custom
  script: ./health_check.sh
  timeout: 5s
```


---

## 🌟 Real-World Examples

### Example 1: Full-Stack MERN App

**Setup:**

```bash
cd ~/mern-app
darpan init
```

**Edit** `.darpan.yml`:

```yaml
version: 1

services:
  - name: MongoDB
    type: { database: mongodb }
    port: 27017
    tags: [database]
    
  - name: Express Backend
    type: http_server
    port: 5000
    health_check:
      type: http
      path: /api/health
    tags: [backend, critical]
    
  - name: React Frontend
    type: http_server
    port: 3000
    tags: [frontend]
    
  - name: Redis Session Store
    type: { cache: redis }
    port: 6379
    tags: [cache]

dependencies:
  - service: Express Backend
    depends_on: [MongoDB, Redis Session Store]
  - service: React Frontend
    depends_on: [Express Backend]
```

**Usage:**

```bash
# Start your services
mongod &
redis-server &
cd backend && npm run dev &
cd frontend && npm start &

# Monitor everything
darpan watch
```

### Example 2: Django + PostgreSQL

```bash
cd ~/django-project
cat > .darpan.yml << 'EOF'
version: 1

services:
  - name: Django Dev Server
    type: http_server
    port: 8000
    health_check:
      type: http
      path: /admin/
    tags: [web]
    
  - name: PostgreSQL
    type: { database: postgres }
    port: 5432
    health_check:
      type: postgres
      database: django_db
    tags: [database]
    
  - name: Celery Worker
    type: custom
    process: celery -A myapp worker
    tags: [worker]
    
  - name: Celery Beat
    type: custom
    process: celery -A myapp beat
    tags: [scheduler]

dependencies:
  - service: Django Dev Server
    depends_on: [PostgreSQL]
  - service: Celery Worker
    depends_on: [PostgreSQL, Redis]
EOF
```

### Example 3: Microservices with Docker

```bash
cd ~/microservices
cat > .darpan.yml << 'EOF'
version: 1

services:
  - name: Auth Service
    type: http_server
    port: 8001
    health_check:
      type: http
      path: /health
    tags: [microservice, critical]
    
  - name: User Service
    type: http_server
    port: 8002
    health_check:
      type: http
      path: /health
    tags: [microservice]
    
  - name: Payment Service
    type: http_server
    port: 8003
    health_check:
      type: http
      path: /health
    tags: [microservice, critical]
    
  - name: Notification Service
    type: http_server
    port: 8004
    health_check:
      type: http
      path: /health
    tags: [microservice]
    
  - name: PostgreSQL
    type: { database: postgres }
    port: 5432
    tags: [database]
    
  - name: Redis
    type: { cache: redis }
    port: 6379
    tags: [cache]
    
  - name: RabbitMQ
    type: { message_queue: rabbitmq }
    port: 5672
    tags: [queue]
EOF
```

**With Docker Compose:**

```bash
docker-compose up -d
darpan watch
# Automatically detects all containers!
```


---

## 🔧 Troubleshooting

### Common Issues and Solutions

#### Issue 1: No Services Detected

**Symptom:**

```bash
darpan status
# No services detected.
```

**Solutions:**


1. **Check if services are actually running:**

```bash
# Check open ports
ss -tlnp | grep LISTEN

# Check processes
ps aux | grep postgres
ps aux | grep redis
```


2. **Verify port range:**
   Create `~/.config/darpan/config.yml`:

```yaml
detection:
  port_range: [1000, 65535]  # Scan wider range
```


3. **Use explicit configuration:**

```bash
darpan init
# Edit .darpan.yml to define your services
```

#### Issue 2: Service Shows as Down but It's Running

**Symptom:**

```
✗ Down     │ Redis      │ Cache    │ localhost:6379 │ N/A
```

**Solutions:**


1. **Check the actual service:**

```bash
redis-cli ping
# Should return: PONG
```


2. **Check if port is accessible:**

```bash
telnet localhost 6379
# or
nc -zv localhost 6379
```


3. **Configure custom health check:**

```yaml
services:
  - name: Redis
    type: { cache: redis }
    port: 6379
    health_check:
      type: redis  # Use Redis-specific check
      timeout: 5s
      retry_count: 3
```

#### Issue 3: Docker Containers Not Detected

**Symptom:**
Docker containers running but not showing in Darpan.

**Solutions:**


1. **Check Docker access:**

```bash
docker ps
# If this fails, Docker daemon might not be running
```


2. **Add user to docker group:**

```bash
sudo usermod -aG docker $USER
# Logout and login again
```


3. **Enable Docker detector:**

```yaml
# ~/.config/darpan/config.yml
detection:
  enabled_detectors: [config, port, process, docker]
```

#### Issue 4: Permission Denied Errors

**Symptom:**

```
Error: Permission denied (os error 13)
```

**Solutions:**


1. **Darpan doesn't need sudo** for basic functionality
2. **For Docker:** Add user to docker group (see above)
3. **For system services:** Run status checks work without sudo

#### Issue 5: TUI Shows Garbled Text

**Symptom:**
Terminal display is corrupted.

**Solutions:**


1. **Reset terminal:**

```bash
reset
```


2. **Use modern terminal:**

* ✅ GNOME Terminal
* ✅ Konsole
* ✅ Alacritty
* ✅ iTerm2 (if on Mac via WSL)


3. **Check terminal size:**

```bash
# TUI needs at least 80x24
echo $COLUMNS x $LINES
```


---

## 🚀 Advanced Features

### JSON Output for Automation

Export service status as JSON:

```bash
# Get all services
darpan status --format json

# Parse with jq
darpan status --format json | jq '.[] | select(.port == 5432)'

# Count healthy services
darpan status --format json | jq '[.[] | select(.health_status.status == "Healthy")] | length'

# Get unhealthy services
darpan status --format json | jq '[.[] | select(.health_status.status != "Healthy")] | .[].name'
```

### Integration with Scripts

**Health check script:**

```bash
#!/bin/bash
# check_services.sh

OUTPUT=$(darpan status --format json)
UNHEALTHY=$(echo $OUTPUT | jq '[.[] | select(.health_status.status != "Healthy")] | length')

if [ $UNHEALTHY -gt 0 ]; then
    echo "❌ $UNHEALTHY service(s) are unhealthy!"
    echo $OUTPUT | jq '[.[] | select(.health_status.status != "Healthy")] | .[].name'
    exit 1
else
    echo "✅ All services are healthy"
    exit 0
fi
```

**Pre-deployment check:**

```bash
#!/bin/bash
# pre_deploy.sh

echo "Checking services before deployment..."
darpan status

if darpan status --format json | jq -e '[.[] | select(.health_status.status != "Healthy")] | length == 0' > /dev/null; then
    echo "✅ All services healthy. Proceeding with deployment."
    ./deploy.sh
else
    echo "❌ Some services are unhealthy. Aborting deployment."
    darpan status
    exit 1
fi
```

### Custom Health Check Scripts

**Example: Custom health check for Celery:**

```bash
# check_celery.sh
#!/bin/bash
celery -A myapp inspect active >/dev/null 2>&1
if [ $? -eq 0 ]; then
    exit 0  # Healthy
else
    exit 1  # Unhealthy
fi
```

**Configuration:**

```yaml
services:
  - name: Celery Worker
    type: custom
    process: celery worker
    health_check:
      type: custom
      script: ./check_celery.sh
      timeout: 5s
```

### Tags for Organization

Use tags to organize and filter services:

```yaml
services:
  - name: Auth API
    tags: [critical, microservice, auth]
  - name: Payment Service
    tags: [critical, microservice, payment]
  - name: Analytics Worker
    tags: [worker, non-critical]
  - name: Cache Layer
    tags: [infrastructure, cache]
```


---

## 📖 Best Practices

### 1. Start Simple

* Begin without `.darpan.yml`
* Let auto-detection work
* Add config only when needed

### 2. Use Meaningful Names

```yaml
# ❌ Bad
- name: Service 1
- name: Server

# ✅ Good
- name: User Authentication API
- name: Payment Processing Service
```

### 3. Tag Appropriately

```yaml
tags: [critical, backend]  # For core services
tags: [optional, worker]   # For non-critical services
```

### 4. Document Health Checks

```yaml
- name: API Gateway
  health_check:
    type: http
    path: /health  # Document why this endpoint
```

### 5. Share Configs with Team

```bash
# Commit .darpan.yml to git
git add .darpan.yml
git commit -m "Add Darpan service monitoring config"
```


---

## 🤝 Contributing

We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

### Quick Links

* 🐛 [Report a Bug]https://github.com/codeBunny2022/darpan/issues
* 💡 [Request a Feature]https://github.com/codeBunny2022/darpan/issues
* 📖 [Documentation]https://github.com/codeBunny2022/darpan/wiki


---

## 📄 License

MIT License - see [LICENSE](LICENSE) for details.


---

## 🙏 Acknowledgments

* Built with [Rust]https://www.rust-lang.org/
* TUI powered by [Ratatui]https://github.com/ratatui-org/ratatui
* Inspired by tools like `htop`, `docker-compose`, and `systemctl`


---

## 📚 Additional Resources

* [QUICKSTART.md]QUICKSTART.md - 5-minute quick start guide
* [TUI_IMPROVEMENTS.md]TUI_IMPROVEMENTS.md - TUI features and updates
* [CHANGELOG.md]CHANGELOG.md - Version history
* [FIXED_ISSUES.md]FIXED_ISSUES.md - Recent bug fixes


---

## 💬 Support

Need help?

* 📖 Read the [QUICKSTART.md]QUICKSTART.md
* 🔍 Check [FIXED_ISSUES.md]FIXED_ISSUES.md
* 🐛 [Open an issue]https://github.com/codeBunny2022/darpan/issues


---

**Made with ❤️ for developers who are tired of checking services manually**

```bash
# Try it now!
darpan watch
```