Project

General

Profile

Actions

Bug #7701

closed

kstat -j does not produce valid JSON

Added by Robert Mustacchi over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Category:
cmd - userland programs
Start date:
2016-12-29
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

# kstat -j unix::dbu_evict:tasks unix::dbu_evict:executed
[{
        "module": "unix",
        "instance": 12,
        "name": "dbu_evict",
        "class": "taskq",
        "type": 1,
        "snaptime": 818674.918781405,
        "data": {
                "tasks": 33565284,
        }
}{
        "module": "unix",
        "instance": 12,
        "name": "dbu_evict",
        "class": "taskq",
        "type": 1,
        "snaptime": 818674.918781405,
        "data": {
                "executed": 33565284,
        }
}]

There are two things wrong.

  • There is a comma at the end of a single element data object. If there are multiple elements in the data object it is formatted correctly.
  • Since two individual stats were requested they are not separated by a comma. If there is a single stat pattern with multiple matching stats it is formatted correctly.

One more case of invalid output:

$ kstat -j unix::dbu_evict:tasks unix::dbu_evict:executed poll | tail -1                
},]

There are many other areas where the kstat command will not end up producing valid json.

Actions #1

Updated by Electric Monk over 5 years ago

  • Status changed from New to Closed

git commit 774814910cba5b65219849ca27b13b2fbe8127ee

commit  774814910cba5b65219849ca27b13b2fbe8127ee
Author: Bryan Cantrill <bryan@joyent.com>
Date:   2016-12-30T14:59:04.000Z

    7701 kstat -j does not produce valid JSON
    7702 kstat(1) doesn't deal well with uninitialized named kstats
    7703 in some locales, kstat -j produces invalid JSON
    Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Reviewed by: Peter Tribble <peter.tribble@gmail.com>
    Approved by: Richard Lowe <richlowe@richlowe.net>

Actions

Also available in: Atom PDF