Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.json file output format #369

Closed
ErwinBoltz opened this issue Feb 27, 2024 · 12 comments · Fixed by #382
Closed

.json file output format #369

ErwinBoltz opened this issue Feb 27, 2024 · 12 comments · Fixed by #382
Labels
bug Something isn't working

Comments

@ErwinBoltz
Copy link

Hello !

To begin, just wanted to say thanks 🥇

i'm not quite sure this is an unexpected behavior so please tell me if i'm missing something or doing something wrong !

Bug description

The .json file when using json exporter is incorrectly outputed.

To Reproduce

My goal was to use scaphandre in order to monitor the consumption of a docker container.
So for example i did this :

./scaphandre json --containers -t 15 -s 5 -f report.json

you will get a report.json file formated like this :

{"host": { ... } }{"host": { ... } }{"host": { ... } }

The problem is that if you want to use this json file ( i'm using Python in order to get the data i'm interessed in ) it contains multiple JSON objects concatenated together without proper separation.

This format causes the JSON parser to encounter an error because it expects only one JSON object per file.

Expected behavior

Each JSON object should be separated by a comma , or be placed in an array [...].

[
{"host": { ... } },
{"host": { ... } },
{"host": { ... } }
]

or

{"host": { ... } },
{"host": { ... } },
{"host": { ... } }

Environment

  • Linux distribution version [Pop!_OS 22.04 LTS]
  • Kernel version [6.6.10-76060610-generic]
@ErwinBoltz ErwinBoltz added the bug Something isn't working label Feb 27, 2024
@ErwinBoltz
Copy link
Author

ErwinBoltz commented Feb 27, 2024

if anyone needs it i did a bash script in order to reformat in a valid json format :

#!/bin/bash

input_file="report.json"
output_file="formatted_report.json"

# Check if input file exists
if [ ! -f "$input_file" ]; then
    echo "Input file $input_file not found."
    exit 1
fi

# Check if jq is installed
if ! command -v jq &> /dev/null; then
    echo "jq is required but it's not installed. Aborting."
    exit 1
fi

# Process input file and format output
jq -s '.' "$input_file" > "$output_file"

echo "Output written to $output_file"

@joegharbi
Copy link

Hello,
Thank you for documenting this bug.
And congratulations to the team for the great progress.

I've been using scaphandre json exporter for more than a year since V0.5.0 and had no issues.

I'm also facing the same issue as soon as I installed the new version v1.0.

My environment is windows 11 which means it's a platform independent issue appeared with the latest release.

Looking forward to hearing from you soon.

@bpetit bpetit linked a pull request Apr 22, 2024 that will close this issue
@bpetit
Copy link
Contributor

bpetit commented Apr 23, 2024

Hi !

Thank you for raising this issue, I tried a PR here.

Let me know if you can try this branch before it makes it to dev, I'd love to hear feedbacks.

@joegharbi
Copy link

Hi,
Thank you for your time and effort.
Unfortunately, I still have the same issue with the JSON exporter.
I am using Windows 11.

@bpetit
Copy link
Contributor

bpetit commented Apr 23, 2024

Hi,

Did you build scaphandre on the branch '369-json-file-output-format' ?

@ErwinBoltz
Copy link
Author

Hello, just tried it, works fine for me. Thanks for your work ! 👍

@joegharbi
Copy link

Hi @bpetit Yes that's what I did.

@bpetit
Copy link
Contributor

bpetit commented May 6, 2024

Hi !

Thanks @ErwinBoltz for the feedback.

@joegharbi this has been merged to dev. Could you confirm, you still have the issue with the latest dev and provide an output please ?

@joegharbi
Copy link

@bpetit Good news it is now giving the correct format from the json exporter.
However, there are some errors as shown in the attached screenshot.
Screenshot 2024-05-06 140437
Thank you.

@bpetit
Copy link
Contributor

bpetit commented May 6, 2024

This is another issue. It might be because the driver is not properly set up. Did you install it as an administrator (this is still needed, but might not be needed in the future) ?

Could you open a dedicated issue if it remains as it is ? thanks

@bpetit bpetit closed this as completed May 6, 2024
@joegharbi
Copy link

joegharbi commented May 6, 2024

@bpetit Yes I installed it as an administrator.
I opened this new issue #384 but I think it is linked to this one too #376.
Thank you.

@bpetit bpetit added this to General Jun 19, 2024
@bpetit bpetit moved this to Done in General Jun 19, 2024
@bpetit
Copy link
Contributor

bpetit commented Nov 2, 2024

Lets follow up on #376 @joegharbi then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants