mydbportal-agent

MyDbPortal Agent.

Build Status

A lightweight system monitoring agent designed to run on your server, collect vital database stats and help in database installation .

Overview

This project provides a complete solution for provisioning, monitoring, and cleaning up a server with a standard database stack (MySQL, PostgreSQL, MongoDB). It consists of two main parts:

  1. The Agent: A secure, lightweight server that exposes a single API endpoint to report system health.
  2. Setup & Cleanup Scripts: Powerful shell scripts that automate the entire server lifecycle, from initial setup to complete teardown.

Features

How It Works

  1. Setup: You run the init.sh script on a fresh server. It installs the databases, configures them for remote access, and starts the monitoring agent as a system service.
  2. Monitoring: The agent runs in the background, ready to receive secure requests from the MyDbPortal platform. When requested, it gathers real-time system stats and sends them back.
  3. Cleanup: If you decommission the server, you run the cleanup_database_server.sh script to wipe all related software and configurations, leaving the system clean.

Getting Started

Prerequisites

Installation

To set up your server, run the following command:

curl -sL https://raw.githubusercontent.com/bonheur15/mydbportal-agent/main/init.sh | bash

This will download and execute the setup script, which handles the entire installation process automatically.

Usage

The Agent API

The agent exposes a single endpoint to fetch system statistics.

Example Request:

curl -X GET http://<your-server-ip>:7723/stats \
     -H "Content-Type: application/json" \
     -H "agent_token: your-secret-agent-token"

Server Cleanup

To completely remove the agent and all database services from your server, run the cleanup script:

curl -sL https://raw.githubusercontent.com/bonheur15/mydbportal-agent/main/cleanup_database_server.sh | bash

Warning: This is a destructive operation and will permanently delete all data.

Configuration

The agent is configured using environment variables, which are set automatically by the init.sh script in the database-agent.service file.

For Developers

Local Development

To run the agent locally for development:

  1. Clone the repository:
    git clone https://github.com/bonheur15/mydbportal-agent.git
    cd mydbportal-agent
    
  2. Install dependencies:
    bun install
    
  3. Run the development server:
    bun run dev
    

The server will start with hot-reloading on http://localhost:7723.

Build

To compile the agent into a standalone executable:

bun run build

The compiled binary will be located in out/linux-x64.

Contributing

Contributions are welcome! If you have a feature request or find a bug, please open an issue on the Contributing Guide.

License

This project is licensed under the MIT License.