go-pluto / styx

Export Data from Prometheus to csv, gnuplot & matplotlib
https://speakerdeck.com/metalmatze/prometheus-styx
MIT License
99 stars 24 forks source link

Adding support for specific step size in CSV output #2

Open thorhs opened 6 years ago

thorhs commented 6 years ago

Added flag --step, which is the step size in seconds. This will generate a line every step seconds. Not specifying a step size, or supplying a step size of 0 uses the previous step size calculations.

metalmatze commented 6 years ago

Does this result in the same steps when returning e.g. an hour by default?

thorhs commented 6 years ago

I updated the tests to be successful, sorry for not doing that initially.

As part of this PR, I switched the steps function to return a duration, in stead of integer seconds, as the prometheus API supports fractions in its steps.

If no --step flag is given, the previous behaviour is maintained, where we divide the duration into 254 steps. Since steps no longer uses whole seconds, but rather time.Duration, I switched the factor 4.2 with 254 steps which seems to be what the original intent was. The code feels cleaner when using time.Duration is used, since that is what is actually being worked on.

If --step is given, that actual value is used, bypassing the step calculation.

ghost commented 3 years ago

I just tried to clone, build and test your repository. When using the --step or --s flag, it gives me the following error:

flag provided but not defined: -step

When runngin styx --help, the step flag is recognized correctly:

NAME:
   styx - Export metrics from prometheus

USAGE:
   styx [global options] command [command options] [arguments...]

VERSION:
   0.0.0

COMMANDS:
     gnuplot     Directly plot a graph with gnuplot
     matplotlib  Generate a file that uses matplotlib
     help, h     Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --step value, -s value      Step size in result data (default: 0s)
   --duration value, -d value  The duration to get timeseries from (default: 1h0m0s)
   --header                    Include a header into the csv file
   --prometheus value          (default: "http://localhost:9090")
   --help, -h                  show help
   --version, -v               print the version