Project

General

Profile

Bug #9992

kstat -j does not produce valid JSON

Added by Brian Ewell 8 months ago. Updated 8 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
cmd - userland programs
Start date:
2018-11-20
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

The kstat command fails to produce valid JSON objects when used with a count of greater than one:

kstat -j unix::dbu_evict:tasks 1 2
[{
        "module": "unix",
        "instance": 21,
        "name": "dbu_evict",
        "class": "taskq",
        "type": 1,
        "snaptime": 3383559.368276734,
        "data": {
                "tasks": 10536387
        }
}]

[, {
        "module": "unix",
        "instance": 21,
        "name": "dbu_evict",
        "class": "taskq",
        "type": 1,
        "snaptime": 3383576.634575867,
        "data": {
                "tasks": 10536387
        }
}]

While the first JSON object is properly formatted, the second is not. There is an improper comma after the opening of the array and before the opening of the associate array:

[, {

This should instead look like the beginning of the first block:
[{

History

#1

Updated by Joshua M. Clulow 8 months ago

I suspect it's time we refactored the JSON emitter logic in kstat to be in terms of something a bit more robust, like:

https://github.com/davepacheco/pmx/blob/bf586d737c3e709a5d3e787bbbd068a85cf1eb64/src/libjsonemitter/jsonemitter.h

Note that while the code above appears to be MPLv2 licensed in that repository, we own the copyright at Joyent and we can definitely replace that with the CDDL for inclusion into illumos.

Also available in: Atom PDF