{"id":39399411,"url":"https://github.com/keshrisohit/devops_metrics","last_synced_at":"2026-01-18T03:22:35.804Z","repository":{"id":50179760,"uuid":"230751564","full_name":"keshrisohit/devops_metrics","owner":"keshrisohit","description":"This repo is an attempt to capture devops metrics like lead time, deployment metric, mean time to recovery etc.","archived":false,"fork":false,"pushed_at":"2022-12-08T03:22:01.000Z","size":410,"stargazers_count":8,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-01T10:40:53.668Z","etag":null,"topics":["bitbucket","deployment-metric","developer-tools","devops-metrics","devops-tools","github"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keshrisohit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-29T13:06:54.000Z","updated_at":"2022-11-12T16:18:13.000Z","dependencies_parsed_at":"2023-01-24T07:30:42.125Z","dependency_job_id":null,"html_url":"https://github.com/keshrisohit/devops_metrics","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/keshrisohit/devops_metrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshrisohit%2Fdevops_metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshrisohit%2Fdevops_metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshrisohit%2Fdevops_metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshrisohit%2Fdevops_metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keshrisohit","download_url":"https://codeload.github.com/keshrisohit/devops_metrics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshrisohit%2Fdevops_metrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28528037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitbucket","deployment-metric","developer-tools","devops-metrics","devops-tools","github"],"created_at":"2026-01-18T03:22:35.095Z","updated_at":"2026-01-18T03:22:35.795Z","avatar_url":"https://github.com/keshrisohit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# devops_metrics\nThis repo is an attempt to capture devops metrics like lead time, deployment metric, mean time to recovery etc.\n\n\n\nPullRequest will have source and target branch , multiple commits and multiple participants\n\nmerge_commit_sha  column from pull_request  will be commit_id in build_details table when merged branch is deployed\n\n\n![Alt text](db_schema.png?raw=true \"Title\")\n\n\n### Setup details \n\n##### If you want to deploy on AWS lambda and api gateway \n\nSetup your config in config.py or set it in envoirnment variable\n\n\n```DB_URL - connection string to database(eg:sqlite:///metrics.db)```\n\n\nif you are using bitbucket set  \n```BITBUCKET_CLIENT_ID  and BITBUCKET_SECRET_KEY ``` i\n\nif you are using github  set \n```GITHUB_ACCESS_TOKEN ```\n\n\nSetup your database tables\nGo to project root directory and run \n\n\n```PYTHONPATH=./ alembic upgrade head```\n\n\n\nSetup your access key and secret key using ```aws configure```\n\nInstall severless  https://serverless.com/framework/docs/providers/aws/guide/installation/\n\n\nRun ```serverless deploy``` to deploy \n\n\n\n##### If you want torun it as docker container \n\n```docker build . -t devops_metrics:latest```\n\nRun in docker container \n\n```\ndocker run -d  -p 5000:5000 \\\n-e DB_URL='' \\\n-e BITBUCKET_CLIENT_ID='' \\\n-e BITBUCKET_SECRET_KEY='' \\\n-e GITHUB_ACCESS_TOKEN='' \\\ndevops_metrics:latest\n```\n\nAfter deployment add the below  urls as a webhook for all the pull_request_event\n```\nhost:port/pull_request/bitbucket for bitbucket\nhost:port/pull_request/github for github\n```\n\n##### Details of APIs to push data\n\n\n```\n\u003chost\u003e:port/issue  to post issue data\n{ \n   'issue_id':'abc',\n   'start_time':'2019-05-15T15:20:30Z',\n   'end_time':'2019-05-15T15:20:30Z',\n   'title':'title',\n   'description':'desc',\n   'sev':'high',\n   'reported_by':'xyz'\n}\n```\n```\nhost:port/build_detail  to post deployment build detail data\n{ \n   'build_id':'123',\n   'project_name':'xyz_service',\n   'source_type':'github',\n   'source_location':'github.com/url',\n   'branch_name':'master',\n   'commit_id':'ahskjdhsdadfasd',\n   'start_time':'2019-05-15T15:20:30Z',\n   'end_time':'2019-05-15T15:20:30Z',\n   'status':'SUCCESS'\n}\n```\n\n#### Build details data\nlambda with name code_build_metrics will get deployed which can subscribe to ```aws code build``` event and persist build details if use aws code build\n\n\n##### How to get access token and add webhook for github?\nhttps://developer.github.com/webhooks/creating/#setting-up-a-webhook\n\nhttps://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line\n\n\n##### How to get client id and secrete key   and add webhook for bitbucket?\nhttps://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html\n\nhttps://vssue.js.org/guide/bitbucket.html\n\n\n\n\nAll the queries will pull data for last 30 days\n\n##### Lead time\n\nGet all commits for merged pull_request, where target branch is master.\nBuild details deployment commit id should be same as merge_commit_sha in pull_request\naverage of difference between commit time and build_details end_time is you lead time as commit is deployed in production\n````\nselect pr.repository_url as repository ,week(pr.merged_at) as week ,avg(timestampdiff(minute,c.time,bd.end_time)) as lead_time\nfrom pull_request pr , \nbuild_details bd ,\ncommit c , \nbranch b,\npull_request_commit_association prc,\npull_request_branch_association prb\nwhere pr.action ='MERGED'\nand prb.branch_id=b.id\nand prb.branch_type='TARGET'\nand b.name='master'\nand bd.commit_id = pr.merge_commit_sha\nand c.id =prc.commit_id\nand pr.id=prc.pull_request_id\n\ngroup by pr.merged_at,pr.repository_url\n````\n\n\n##### Lead time if you consider meregd to master as deployemnt\nLets say you dont have build details and if you depploy your code after merge to master, we can get approx lead time assuming PR merged_at as deployemnt time \n\n```\n select pr.repository_url,week(pr.merged_at),avg(timestampdiff(minute,c.time,pr.merged_at))as lead_time \n from pull_request_commit_association prc, \n`commit` c,\n branch b,\n pull_request pr,\n pull_request_branch_association prb \n where prc.commit_id=c.id\n and pr.id=prc.pull_request_id \n and prb.pull_request_id=pr.id  \n and prb.branch_id=b.id  \n and action ='MERGED' \n and prb.branch_type='TARGET' \n and b.name='master' group by week(pr.merged_at),pr.repository_url\n and pr.merged_at \u003e NOW() - INTERVAL 30 DAY\n```\n\n##### Deployment frequency if you have build_deatils\n```\nselect bd.project_name as service ,count(*) as deployment_frequency ,week(bd.start_time)  \nfrom build_details  bd\nwhere bd.end_time \u003e NOW() - INTERVAL 30 DAY\ngroup by week(bd.start_time),bd.project_name;\n```\n\n##### Deployemnt frequency if you consider meregd to master as deployemnt\n\n```\nselect count(*) deployment_frequency,week(pr.merged_at), pr.repository_url as repository_url from \npull_request pr, \npull_request_branch_association prb  ,\nbranch b\nwhere\nprb.branch_id=b.id\nand  pr.action='MERGED'\nand prb.branch_type='TARGET'\nand b.name='master'\nand pr.merged_at \u003e NOW() - INTERVAL 30 DAY\ngroup by week(pr.merged_at),pr.repository_url\n```\n\n##### Mean Time to Recover\nSelect sev types which means service unavailable /un usable\n```\n\nselect avg(timestampdiff(minute,start_time,end_time)) mttr from issues \nwhere sev=''\n\n```\n##### No of review comments.\n```\nselect  pr.repository_url,week(pr.merged_at) ,coalesce(sum(pr.no_of_review_comments),0)+coalesce(sum(pr.no_of_comments),0) as comments  \nfrom pull_request pr \nwhere action='MERGED' \nand pr.merged_at \u003e NOW() - INTERVAL 30 DAY\ngroup by week(pr.merged_at) ,pr.repository_url\n```\n\n##### No of lines changed per repository \n```\nselect  pr.repository_url,week(pr.merged_at) ,COALESCE(SUM(pr.lines_added),0)+COALESCE(SUM(pr.lines_removed),0)\nfrom pull_request pr \nwhere action ='MERGED'\nand pr.merged_at \u003e NOW() - INTERVAL 30 DAY\ngroup by week(pr.merged_at) ,pr.repository_url\n\n```\n\n##### No fo commits per repositroy\n\n```\nselect count(*), week(c.time),repository_url \nfrom commit c \nwhere c.time \u003e NOW() - INTERVAL 30 DAY\ngroup by repository_url ,week(c.time);\n\n```\n\n##### Deployment Time per repository\n\n```\nselect project_name,avg(TIMESTAMPDIFF(second,start_time,end_time)) as deployment_time ,week(start_time)   \nfrom build_details \nwhere start_time \u003e NOW() - INTERVAL 30 DAY\ngroup by week(start_time),project_name;\n\n```\nSample dashboard\n\n\n\n\n\n![Alt text](sample_dashboard.png?raw=true \"Title\")\n\n#### Work in progress.....","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeshrisohit%2Fdevops_metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeshrisohit%2Fdevops_metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeshrisohit%2Fdevops_metrics/lists"}