Skip to content

stats_exporter: Refactor and add docstrings to graph data export script

Now that the script is ok, i thought it was the right time to improve it a bit.

So here it goes:

  • refactor a bit the script
  • Add docstrings and comments to clarify some part
  • simplify the data computation (no if, simply inline the call for history data solely for content).
  • Make the script parametric to reuse the setup from the manifest (avoiding future problems, hard-coding values in the long run is not what we want)

This also:

  • export-stats: Rename script with consistent _ for python filename
  • extract variables from puppet manifest to avoid duplication
  • export_archive_counters: Update required python dependencies (requests was not mentioned)

Test Plan

prior version script run. current version script run. Check output are the same and it is.

$ python ./export-archive_counters.py > test.origin.json
$ python ./export_archive_counters.py --history-data-file ./history-counters.munin.json > test.json
$ stat test.json
  File: test.json
  Size: 85468           Blocks: 168        IO Block: 4096   regular file
Device: fe02h/65026d    Inode: 43916075    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/    tony)   Gid: ( 1000/    tony)
Access: 2019-08-10 23:32:28.555767531 +0200
Modify: 2019-08-10 23:31:41.050503170 +0200
Change: 2019-08-10 23:31:41.050503170 +0200
 Birth: -
$ diff test.json test.origin.json  # <- no diff
$ sha512sum test.json
147670ea7b4d8d388adfcf09586e5c143113d26f6eee265ba2d0b88185b3809b6429668c3ba96a46829a68149a2355ff069e8018935eebc2ebd923069e2f17bb  test.json
$ sha512sum test.origin.json
147670ea7b4d8d388adfcf09586e5c143113d26f6eee265ba2d0b88185b3809b6429668c3ba96a46829a68149a2355ff069e8018935eebc2ebd923069e2f17bb  test.origin.json

Migrated from D1841 (view on Phabricator)

Merge request reports