LXC 2.x Web GUI

LXC is an abbreviation for “Linux Containers which is a feature in the linux kernel, it allows you to install multiple Linux installations running on the same kernel. It’s kind of like chroot but much more powerful as it allows for process and network isolation.

I’ve seen that there is a fancy web GUI for Ubuntu and i felt the need for something similar in Debian (never actually tried the Ubuntu LXC Web Panel)

Also this was a way for me to combine some backend with some frontend development while learning JQuery and AJAX.

I wanted to create a single PHP file which was a 100% portable and executable with php’s built in web-server.

# php -S your-ip:80 lxc-web.php

The script uses AJAX to send the following GET Request to itself:

http://your-ip:80/?json=true

The reply contains all sorts of values in the form of a JSON associative array.

{
    "MemTotal": "4004736",
    "MemFree": "411996",
    "MemAvailable": "1886048",
    "Buffers": "381552",
    "Cached": "789360",
    "SwapCached": "9556",
    "Active": "783188",
    "Inactive": "779844",
    "Active(anon)": "203024",
    "Inactive(anon)": "253508",
    "Active(file)": "580164",
    "Inactive(file)": "526336",
    "Unevictable": "0",
    "Mlocked": "0",
    "SwapTotal": "17298108",
    "SwapFree": "16947644",
    "Dirty": "0",
    "Writeback": "0",
    "AnonPages": "385764",
    "Mapped": "264216",
    "Shmem": "64412",
    "Slab": "818108",
    "SReclaimable": "653768",
    "SUnreclaim": "164340",
    "KernelStack": "7296",
    "PageTables": "21428",
    "NFS_Unstable": "0",
    "Bounce": "0",
    "WritebackTmp": "0",
    "CommitLimit": "19300476",
    "Committed_AS": "3589412",
    "VmallocTotal": "34359738367",
    "VmallocUsed": "0",
    "VmallocChunk": "0",
    "HardwareCorrupted": "0",
    "AnonHugePages": "2048",
    "ShmemHugePages": "0",
    "ShmemPmdMapped": "0",
    "HugePages_Total": "0",
    "HugePages_Free": "0",
    "HugePages_Rsvd": "0",
    "HugePages_Surp": "0",
    "Hugepagesize": "2048",
    "DirectMap4k": "1046412",
    "DirectMap2M": "3112960",
    "": "",
    "MemUsed": 1706692,
    "MemTotalBytes": 4100849664,
    "MemUsedBytes": 1747652608,
    "MemAvailableBytes": 1931313152,
    "MemFreeBytes": 421883904,
    "MemUsedPercent": 42.62,
    "MemAvailablePercent": 47.1,
    "MemFreePercent": 10.29,
    "SwapFreePercent": 98,
    "SwapUsedPercent": 2,
    "MemUsedHuman": "1.63 GiB",
    "MemAvailableHuman": "1.8 GiB",
    "MemFreeHuman": "402.34 MiB",
    "processor_count": 2,
    "processor_type": "Intel(R) Celeron(R) CPU G1610T @ 2.30GHz",
    "processor_count_ht": 4,
    "load_1_min": "0.11",
    "load_5_min": "0.10",
    "load_15_min": "0.09",
    "load_percent_1_min": 2.75,
    "load_percent_5_min": 2.5,
    "load_percent_15_min": 2.25,
    "uptime": "15 days, 7 hours, 38 minutes and 46 seconds"
}

These values are then parsed and used to update the charts, it gives us the power of a graph without the need for a database backend.

Todo List

  • AJAX update for container meta.
  • Start/stop/freeze container without reloading page.
  • Optimize the AJAX response
  • Make configurable values for:
    • Update interval
    • Max chart history

Source code

Let me know if you’d like to give it a try!