Loading...

Pretty print duration

Performing a reindex job in Elasticsearch gives you the time the job took.

curl -XPOST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
> {
>   "source": {
>     "index": "fo-log-2017.05.05"
>   },
>   "dest": {
>     "index": "fo-log-fix-2017.05.05",
>      "pipeline": "kt-improve"
>   }
> }'

The outcome.

{
	"took": 13147934,
	"timed_out": false,
	"total": 15855322,
	"updated": 0,
	"created": 15855322,
	"deleted": 0,
	"batches": 15856,
	"version_conflicts": 0,
	"noops": 0,
	"retries": {
		"bulk": 0,
		"search": 0
	},
	"throttled_millis": 0,
	"requests_per_second": -1.0,
	"throttled_until_millis": 0,
	"failures": []
}

13147934 milliseconds is a little bit cryptic. A simple way to give your customers a more human readable information is the JavaScript pretty-ms package and its CLI.

npm install --global pretty-ms
npm install --global pretty-ms-cli

The usage prints 3 hours, 39 minutes, 7.9 seconds

pretty-ms 13147934
3h 39m 7.9s