# Check every machine from a program

One program walks your machines and prints the memory available and the disk space left on each.
It only reads, so the agent token it uses needs no extra classes.

**In short:** `pip install cmdop`, set `CMDOP_TOKEN` (an agent token from the Agents tab) and `CMDOP_URL`
(`https://<contour>.cmdop.dev`), and run the program below.

## When to use this

A cron job, a status page or a script that should notice a full disk before you do.

## Steps

1. Install the SDK ([Python](https://docs.cmdop.ai/reference/sdk/python.md) or [TypeScript](https://docs.cmdop.ai/reference/sdk/typescript.md)).
2. Create an agent token on your page and set the two variables. Treat the token like a password.
3. Run:

   ```python
   import cmdop

   with cmdop.connect() as c:                       # CMDOP_TOKEN, CMDOP_URL
       for m in c.machines_list():
           if m.state != "online":
               continue
           info = c.machine(m.name).sys_info()
           root = next(d for d in info.disks if d.mount == "/")
           print(m.name, info.memory_available // 2**20, "MiB available,",
                 root.available // 2**30, "GiB left on /")
   ```

## Check

One line per online machine, with numbers you can compare with the system's own settings.

## If it fails

- [`unauthorized`](https://docs.cmdop.ai/reference/errors/unauthorized.md): the token ran out or was revoked; create a
  new one.
- A machine is skipped: it is not `online` in [`machines_list`](https://docs.cmdop.ai/reference/tools/machines_list.md).

## Related

[`sys_info`](https://docs.cmdop.ai/reference/tools/sys_info.md) · [Use from your product](https://docs.cmdop.ai/guides/embed.md) ·
[Tokens](https://docs.cmdop.ai/concepts/tokens.md)
