mariano / disque-php

PHP library for Disque, an in-memory, distributed job queue
MIT License
132 stars 19 forks source link

Return a K/V-like response for INFO, but with categories #43

Closed dominics closed 3 years ago

dominics commented 7 years ago

Instead of responding to ->info() with a large string (# Server\r\ndisque_version:1.0-rc1\r\ndisque_git_sha1:00000000\r\netc..), lets parse the information nicely. The output is divided into sections by headings, so those end up as keys in an associative array.

This approach is largely based on the Predis ServerInfoV26x.php class - so, thank @nrk for this.

This is a breaking change; anyone relying on $client->info() returning a string would be affected. So, this should probably wait until we have a 3.0 branch. (Happy to rebase the PR at that point.) Breaking change noted in the CHANGELOG.

Here's a json_encode($client->info()):

{
    "Server": {
        "disque_version": "1.0-rc1",
        "disque_git_sha1": "00000000",
        "disque_git_dirty": "0",
        "disque_build_id": "1b9bed5f419fb409",
        "os": "Linux 4.4.0-59-generic x86_64",
        "arch_bits": "64",
        "multiplexing_api": "epoll",
        "gcc_version": "5.3.1",
        "process_id": "16542",
        "run_id": "5a58ee04afaa616f97746ff02eabf1ef14e2613d",
        "tcp_port": "7712",
        "uptime_in_seconds": "6426",
        "uptime_in_days": "0",
        "hz": "10",
        "executable": "\/home\/me\/blah\/disque-server",
        "config_file": ""
    },
    "Clients": {
        "connected_clients": "1",
        "client_longest_output_list": "0",
        "client_biggest_input_buf": "0",
        "blocked_clients": "0"
    },
    "Memory": {
        "used_memory": "2745152",
        "used_memory_human": "2.62M",
        "used_memory_rss": "11186176",
        "used_memory_peak": "2745152",
        "used_memory_peak_human": "2.62M",
        "mem_fragmentation_ratio": "4.07",
        "mem_allocator": "jemalloc-4.0.3"
    },
    "Jobs": {
        "registered_jobs": "3762"
    },
    "Queues": {
        "registered_queues": "1"
    },
    "Persistence": {
        "loading": "0",
        "aof_enabled": "0",
        "aof_state": "off",
        "aof_rewrite_in_progress": "0",
        "aof_rewrite_scheduled": "0",
        "aof_last_rewrite_time_sec": "-1",
        "aof_current_rewrite_time_sec": "-1",
        "aof_last_bgrewrite_status": "ok",
        "aof_last_write_status": "ok"
    },
    "Stats": {
        "total_connections_received": "1296",
        "total_commands_processed": "1346",
        "instantaneous_ops_per_sec": "0",
        "total_net_input_bytes": "99397",
        "total_net_output_bytes": "84372",
        "instantaneous_input_kbps": "0.01",
        "instantaneous_output_kbps": "0.19",
        "rejected_connections": "0",
        "latest_fork_usec": "0"
    },
    "CPU": {
        "used_cpu_sys": "409.21",
        "used_cpu_user": "7.42",
        "used_cpu_sys_children": "0.00",
        "used_cpu_user_children": "0.00"
    }
}
Revisor commented 7 years ago

What if the response had methods for each row?

$info->getDisqueVersion(), $info->getRegisteredJobs()...?

Or at the very least it could define all known keys as constants, so that the developer can access them by $info[InfoResponse::DISQUE_VERSION].

What do you think about it?

mariano commented 7 years ago

I like both approaches

On Sat, Mar 11, 2017 at 12:12 Revisor notifications@github.com wrote:

What if the response had methods for each row?

$info->getDisqueVersion(), $info->getRegisteredJobs()...?

Or at the very least it could define all known keys as constants, so that the developer can access them by $info[InfoResponse::DISQUE_VERSION].

What do you think about it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mariano/disque-php/pull/43#issuecomment-285872521, or mute the thread https://github.com/notifications/unsubscribe-auth/AABIps2JvW25s-LUcgsGPLphi6vjCZ_eks5rkrnCgaJpZM4MaNuK .