What is the best way to derive gitlab job metrics

I am trying to export certain gitlab job metrics to prometheus. The metrics are as follows

  1. Gitlab job id
  2. Timstamp of job Start
  3. Timestamp of Job End
  4. Job duration

I have had a look at this doc about predefined variables and I can echo ’CI_JOB_STARTED_AT and get the job start time. This is not feasible since I will have to edit every gitlab-ci.yml file and thats just way too many repos.

So far my best best is to use the api with the jobs endpoint to derive the data I want and export it to prometheus. Is this the best way to do this?

I will appreciate any help on this.