-- 监控示例脚本
local start_time = os.clock()

-- 记录内存使用情况
local mem_start = memory.current()
local mem_limit = memory.limit()

-- 记录开始时的CPU和内存使用
local start_cpu = sys.get_cpu_usage()
local start_mem = sys.get_memory_usage()

-- 创建一些数据
local data = {}
for i = 1, 10000 do
    data[i] = string.rep("a", 100)
end

-- 模拟HTTP请求
local response, error = http.get("https://api.example.com/status")
if error then
    sys.log("ERROR", "Failed to call API: " .. error)
else
    sys.log("INFO", "API response: " .. tostring(response))
end

-- 记录结束时的CPU和内存使用
local end_cpu = sys.get_cpu_usage()
local end_mem = sys.get_memory_usage()
local mem_used = memory.current() - mem_start
local elapsed = os.clock() - start_time

-- 返回结果
return {
    memory_usage = {
        start = mem_start,
        used = mem_used,
        current = memory.current(),
        limit = mem_limit
    },
    cpu_usage = {
        start = start_cpu,
        end = end_cpu,
        change = end_cpu - start_cpu
    },
    system_memory = {
        start = start_mem,
        end = end_mem,
        change = end_mem - start_mem
    },
    execution_time = elapsed,
    data_size = #data
}