Script Auto Monitor API ETLE (Detect Error Real-Time)

Script Auto Monitor API ETLE (Detect Error Real-Time)

Script auto monitor API ETLE untuk cek status server, response, dan error secara real-time menggunakan Bash, PowerShell, dan notifikasi.

Script auto monitor API ETLE untuk cek status server, response, dan error secara real-time menggunakan Bash, PowerShell, dan notifikasi.



Script Auto Monitor API ETLE (Detect Error Real-Time)


Monitoring API sangat penting dalam sistem ETLE untuk memastikan data dari kamera seperti Hikvision iDS-2CD9396-BIS dapat terkirim ke server analytic (EAS/EMST) tanpa gangguan.

Dengan script auto monitoring, teknisi dapat mendeteksi error lebih cepat seperti API down, timeout, atau response gagal.


1. Konsep Monitoring API

Tujuan:

  • Cek status API (UP / DOWN)

  • Cek response time

  • Deteksi error (500, timeout)

  • Logging otomatis


2. Script Bash (Linux Server 🔥)

#!/bin/bash

URL="http://10.172.1.2:1020/api/status"
LOG="monitor_api.log"

while true
do
  STATUS=$(curl -s -o /dev/null -w "%{http_code}" $URL)
  TIME=$(date)

  if [ "$STATUS" != "200" ]; then
    echo "$TIME - ERROR - Status: $STATUS" >> $LOG
  else
    echo "$TIME - OK" >> $LOG
  fi

  sleep 5
done

👉 Fungsi:

  • Cek API tiap 5 detik

  • Log error otomatis


3. Script PowerShell (Windows Server)

while ($true) {
    $url = "http://10.172.1.2:1020/api/status"
    $time = Get-Date

    try {
        $response = Invoke-WebRequest -Uri $url -UseBasicParsing
        if ($response.StatusCode -eq 200) {
            "$time - OK" | Out-File -Append monitor_api.txt
        } else {
            "$time - ERROR $($response.StatusCode)" | Out-File -Append monitor_api.txt
        }
    }
    catch {
        "$time - DOWN" | Out-File -Append monitor_api.txt
    }

    Start-Sleep -Seconds 5
}

4. Script Python (Advanced Monitoring 🔥)

import requests
import time
from datetime import datetime

url = "http://10.172.1.2:1020/api/status"

while True:
    try:
        r = requests.get(url, timeout=3)
        if r.status_code == 200:
            print(f"{datetime.now()} - OK")
        else:
            print(f"{datetime.now()} - ERROR {r.status_code}")
    except:
        print(f"{datetime.now()} - DOWN")

    time.sleep(5)

5. Tambahkan Notifikasi Telegram (PRO 🔥)

import requests

def send_telegram(msg):
    token = "TOKEN_BOT"
    chat_id = "CHAT_ID"
    requests.get(f"https://api.telegram.org/bot{token}/sendMessage?chat_id={chat_id}&text={msg}")

👉 Integrasi:

  • Kirim alert kalau API down


6. Monitoring Banyak Kamera / API

URLS=(
"http://10.172.1.2:1020/api/status"
"http://10.172.1.3:1020/api/status"
)

for URL in "${URLS[@]}"
do
  curl -I $URL
done

7. Log Monitoring

Contoh log:

2026-03-26 10:00:01 - OK
2026-03-26 10:00:06 - ERROR 500
2026-03-26 10:00:11 - DOWN

8. Integrasi dengan NOC System

Bisa dikembangkan ke:

  • Grafana

  • Zabbix

  • PRTG

👉 Jadi dashboard seperti TMC 🔥


9. Troubleshooting dari Monitoring

❌ Status 500

  • Server error

  • API crash


❌ DOWN

  • Server mati

  • Network putus


❌ Delay tinggi

  • Server overload

  • Bandwidth penuh


10. Insight Profesional

👉 Di proyek ETLE:

  • Monitoring wajib 24 jam

  • Tanpa monitoring:
    ❌ tidak tahu API mati


👉 Best practice:

  • Combine:

    • Script

    • Dashboard

    • Alert


Kesimpulan

Script auto monitoring API sangat penting untuk memastikan sistem ETLE berjalan stabil. Dengan monitoring real-time, teknisi dapat dengan cepat mendeteksi dan menangani masalah sebelum berdampak besar pada sistem.


🌐 Kunjungi juga

👉 https://www.haikalitsupport.fun/

إرسال تعليق

Silakan tinggalkan komentar Anda dengan bahasa yang sopan dan relevan dengan topik.
Pertanyaan, saran, atau sharing pengalaman seputar IT Support sangat kami apresiasi.
Komentar yang mengandung spam, promosi, atau ujaran tidak pantas tidak akan ditampilkan.
Terima kasih 🙏