{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/casama-ai/json-schema/casama-ai-server-capacity-schema.json",
  "title": "ServerCapacity",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/casama-ai-openapi.json#/components/schemas/ServerCapacity",
  "type": "object",
  "properties": {
    "budget_mb": {
      "type": "integer",
      "description": "Memory hosted computers may use (COMPUTER_HOST_MEMORY_GB); 0 = none set"
    },
    "latest": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "at": {
          "type": "string"
        },
        "mem_total_mb": {
          "type": "integer"
        },
        "mem_available_mb": {
          "type": "integer"
        },
        "load1": {
          "type": "number"
        },
        "cpus": {
          "type": "integer"
        },
        "disk_used_pct": {
          "type": [
            "number",
            "null"
          ]
        },
        "computers_running": {
          "type": "integer"
        },
        "computers_mem_mb": {
          "type": "integer"
        }
      },
      "required": [
        "at",
        "mem_total_mb",
        "mem_available_mb",
        "load1",
        "cpus",
        "disk_used_pct",
        "computers_running",
        "computers_mem_mb"
      ]
    },
    "days": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "day": {
            "type": "string"
          },
          "peak_computers_mem_mb": {
            "type": "integer"
          },
          "peak_computers": {
            "type": "integer"
          },
          "min_available_mb": {
            "type": "integer"
          },
          "peak_load1": {
            "type": "number"
          }
        },
        "required": [
          "day",
          "peak_computers_mem_mb",
          "peak_computers",
          "min_available_mb",
          "peak_load1"
        ]
      }
    },
    "refusals_30d": {
      "type": "integer"
    },
    "full_in_weeks": {
      "type": [
        "number",
        "null"
      ],
      "description": "Weeks until daily peaks reach the budget at the 30-day trend"
    },
    "alerts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "early_warning",
              "capacity_full",
              "low_memory",
              "disk"
            ]
          },
          "day": {
            "type": "string"
          },
          "body": {
            "type": "string"
          }
        },
        "required": [
          "kind",
          "day",
          "body"
        ]
      }
    },
    "alarm": {
      "$ref": "#/$defs/CapacityAlarm"
    },
    "computer_metrics": {
      "type": "object",
      "properties": {
        "wake_times": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string"
              },
              "count": {
                "type": "integer"
              },
              "p50_ms": {
                "type": "integer"
              },
              "p90_ms": {
                "type": "integer"
              }
            },
            "required": [
              "mode",
              "count",
              "p50_ms",
              "p90_ms"
            ]
          }
        },
        "browser_ooms_7d": {
          "type": "integer"
        },
        "wakes_by_caller_7d": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "caller": {
                "type": "string"
              },
              "count": {
                "type": "integer"
              }
            },
            "required": [
              "caller",
              "count"
            ]
          }
        },
        "shell_programs_7d": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "program": {
                "type": "string"
              },
              "count": {
                "type": "integer"
              }
            },
            "required": [
              "program",
              "count"
            ]
          }
        },
        "job_boxes_7d": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer"
            },
            "p50_ms": {
              "type": [
                "integer",
                "null"
              ]
            },
            "p90_ms": {
              "type": [
                "integer",
                "null"
              ]
            }
          },
          "required": [
            "count",
            "p50_ms",
            "p90_ms"
          ]
        }
      },
      "required": [
        "wake_times",
        "browser_ooms_7d",
        "wakes_by_caller_7d",
        "shell_programs_7d",
        "job_boxes_7d"
      ],
      "description": "Wake timings, OOM kills, shell programs, and job-box stats (7d)"
    }
  },
  "required": [
    "budget_mb",
    "latest",
    "days",
    "refusals_30d",
    "full_in_weeks",
    "alerts"
  ],
  "$defs": {
    "CapacityAlarm": {
      "type": "object",
      "properties": {
        "level": {
          "type": "integer",
          "description": "0 = no alarm; 70, 80, 90 or 95 = percent of the memory budget; 100 = full (a start refused or the host low on memory)"
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "level_since": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_push_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "snoozed_until": {
          "type": [
            "string",
            "null"
          ]
        },
        "ended_at": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "level",
        "started_at",
        "level_since",
        "last_push_at",
        "snoozed_until",
        "ended_at"
      ],
      "description": "Missing on servers before D-601"
    }
  }
}