# PCMonitor Agent - Complete Diagnostic Toolkit

## 📦 Tools Available

All tools are in: `E:\xampp\htdocs\tracker\agent-csharp\`

---

## 🔧 Scripts & Tools

### 1. **DIAGNOSTIC-CMD.bat** ⭐ START HERE
**For users with Command Prompt (cmd.exe)**

```bash
cd E:\xampp\htdocs\tracker\agent-csharp
DIAGNOSTIC-CMD.bat
```

**Checks:**
- ✓ Service status
- ✓ Config file exists and location
- ✓ Log directory
- ✓ Network connectivity
- ✓ Executable location

**Best for:** Quick status check, no PowerShell needed

---

### 2. **DIAGNOSTIC.bat**
**For users with PowerShell**

(More detailed than DIAGNOSTIC-CMD.bat)

---

### 3. **BUILD_CLEAN.bat**
**To rebuild the agent executable**

```bash
BUILD_CLEAN.bat
```

**Does:**
1. Clean previous build
2. Restore NuGet packages
3. Build release version
4. Publish executable
5. Verify exe created

**Use when:** You need to rebuild/recompile

---

### 4. **INSTALL_SIMPLE.bat**
**To install/reinstall as Windows Service**

```bash
INSTALL_SIMPLE.bat
```

**Does:**
1. Finds executable
2. Registers Windows Service
3. Creates config directory
4. Generates config.json if needed
5. Starts service

**Run as:** Administrator

---

## 📖 Documentation

### 1. **DATA_NOT_SHOWING_DIAGNOSIS.md** 📋 MAIN GUIDE
Complete step-by-step diagnosis with both cmd and PowerShell commands.

**Sections:**
- Step 1: Verify Agent Service
- Step 2: Run Diagnostic
- Step 3: Access Debug Dashboard
- Step 4: Verify Configuration
- Step 5: Test API Connectivity
- Step 6: Check Database
- Step 7: Check Log Files
- Common Problems & Solutions

---

### 2. **QUICK_REFERENCE.md** 🚀 CHEAT SHEET
Quick reference for cmd.exe commands.

**Includes:**
- Common commands for service management
- Configuration & log commands
- Network testing
- Troubleshooting flowchart
- Quick setup guide
- First-time setup steps

---

### 3. **TROUBLESHOOTING.md** 🔍 DETAILED GUIDE
(In agent-csharp folder)

**Includes:**
- Detailed problem analysis
- PowerShell commands for each issue
- Database query examples
- Network troubleshooting
- Step-by-step fixes

---

### 4. **BUILD_SUCCESS.md**
Documentation of successful build with list of fixes applied.

---

## 🌐 Web-Based Tools

### **Debug Dashboard**
```
URL: http://localhost/tracker/debug.php
     or
     http://tracker.lppmunud.id/debug.php
```

**Shows:**
- Total agents registered
- Total activities logged
- List of all agents with status
- Last 20 activities
- Last 20 processes
- All diagnostic info

**Access anytime to check database status**

---

## 📊 Flowchart: What to Use When

```
Agent data not showing?
│
├─ First time setup?
│  └─ Use: INSTALL_SIMPLE.bat → DIAGNOSTIC-CMD.bat
│
├─ Service not running?
│  └─ Use: sc query PCMonitorAgent (check status)
│     └─ Then: net start PCMonitorAgent (start it)
│
├─ Data not in database?
│  └─ Use: DIAGNOSTIC-CMD.bat (check everything)
│     └─ Then: review TROUBLESHOOTING.md
│
├─ Want to rebuild?
│  └─ Use: BUILD_CLEAN.bat
│
├─ Want to check database?
│  └─ Use: Debug Dashboard at http://localhost/tracker/debug.php
│
└─ Need detailed PowerShell commands?
   └─ Use: DATA_NOT_SHOWING_DIAGNOSIS.md
```

---

## 🎯 Quick Start (5 minutes)

1. **Run Diagnostic:**
   ```bash
   cd E:\xampp\htdocs\tracker\agent-csharp
   DIAGNOSTIC-CMD.bat
   ```

2. **Read the output** - it will tell you what's wrong

3. **Check Debug Dashboard:**
   ```
   http://localhost/tracker/debug.php
   ```

4. **If still having issues:**
   - See "Common Problems" in QUICK_REFERENCE.md
   - Read relevant section in DATA_NOT_SHOWING_DIAGNOSIS.md

---

## 🛠️ Installation Steps (First Time)

### Step 1: Build
```bash
cd E:\xampp\htdocs\tracker\agent-csharp
BUILD_CLEAN.bat
```
Wait 1-2 minutes for compilation...

### Step 2: Install (Run as Admin)
```bash
INSTALL_SIMPLE.bat
```

### Step 3: Verify
```bash
sc query PCMonitorAgent
```
Should show: `STATE : 4 RUNNING`

### Step 4: Test
```bash
DIAGNOSTIC-CMD.bat
```
All items should show `[OK]`

### Step 5: Check Dashboard
```
http://localhost/tracker/debug.php
```
Should show agents > 0

---

## 🚨 Error Messages & Solutions

| Error | Meaning | Fix |
|-------|---------|-----|
| `Service not found` | Not installed | Run INSTALL_SIMPLE.bat |
| `Access is denied` | Not Admin | Right-click → Run as Admin |
| `Cannot reach tracker.lppmunud.id` | Network issue | Check internet, firewall |
| `HTTP 404` | Wrong API URL | Check config.json |
| `Cannot connect to API` | Service not running | Run `net start PCMonitorAgent` |
| `No log files` | Service crashed | Check config, reinstall |

---

## 📞 Support Information

If you need help, have ready:

1. Output from: `DIAGNOSTIC-CMD.bat`
2. Config file: `C:\ProgramData\PCMonitor\config.json`
3. Recent logs: `C:\ProgramData\PCMonitor\Logs\*.log`
4. Database status: `http://localhost/tracker/debug.php` (screenshot)

---

## 📚 File Locations Reference

| What | Location |
|------|----------|
| Config | `C:\ProgramData\PCMonitor\config.json` |
| Logs | `C:\ProgramData\PCMonitor\Logs\` |
| Executable | `E:\xampp\htdocs\tracker\agent-csharp\bin\Release\net6.0-windows\PCMonitorAgent.exe` |
| Build Scripts | `E:\xampp\htdocs\tracker\agent-csharp\` |
| Database | MySQL at `tracker.lppmunud.id` |
| Web Dashboard | `http://localhost/tracker/dashboard` |
| Debug Page | `http://localhost/tracker/debug.php` |

---

## ✅ Verification Checklist

- [ ] DIAGNOSTIC-CMD.bat shows all `[OK]`
- [ ] Service status: `STATE : 4 RUNNING`
- [ ] Config URL is correct: `http://tracker.lppmunud.id/tracker/api`
- [ ] Can ping `tracker.lppmunud.id`
- [ ] Debug Dashboard shows agents > 0
- [ ] Debug Dashboard shows activities > 0
- [ ] Web Dashboard displays data
- [ ] No errors in C:\ProgramData\PCMonitor\Logs\

---

**Toolkit Version:** 1.0  
**Last Updated:** 2026-03-27  
**Status:** Complete & Ready to Use ✅
