# gitlab-languages
[![PyPI - License](https://img.shields.io/pypi/l/gitlab-languages.svg)](https://github.com/max-wittig/gitlab-languages/blob/master/LICENSE)
Utility to generate a Prometheus data source text file for your GitLab instance
using the [GitLab Language API](https://docs.gitlab.com/ee/api/projects.html#languages)
## installation from PyPI
1. Install from PyPI as CLI
```bash
pip install -U gitlab-languages
```
1. Run the program
```bash
gitlab-languages --cache cache.json --args owned=True # more info about usage: see below
```
## installation from source
1. Install python dependencies
```bash
poetry install
```
1. Set the required environment variables
```bash
export GITLAB_TOKEN=<SOME_TOKEN_WITH_API_SCOPE>
export GITLAB_URL=https://gitlab.com # optional, defaults to https://gitlab.com
# optional:
export WORKER_COUNT=24
```
1. Run the tool
```bash
gitlab-languages
```
## usage
```plain
usage: gitlab_languages [-h] [--project_limit PROJECT_LIMIT]
[--args ARGS [ARGS ...]]
[--groups GROUPS [GROUPS ...]]
[--ignore_groups IGNORE_GROUPS [IGNORE_GROUPS ...]]
[--cache CACHE] [-o OUTPUT]
optional arguments:
-h, --help show this help message and exit
--project_limit PROJECT_LIMIT
Set project limit to scan
--args ARGS [ARGS ...]
Provide custom args to the GitLab API
--groups GROUPS [GROUPS ...]
Scan only certain groups
--ignore_groups IGNORE_GROUPS [IGNORE_GROUPS ...]
Ignore certain groups and their projects
--cache CACHE Cache file to use
-o OUTPUT, --output OUTPUT
Location of the metrics file output
```
### additional arguments
You can specify additional arguments, that will be directly supplied to the
[python-gitlab library](https://github.com/python-gitlab/python-gitlab) or to the GitLab API endpoint.
Example:
```bash
gitlab-languages --args owned=True
```
More info about the available additional args can be found here:
* http://python-gitlab.readthedocs.io/en/stable/
* https://docs.gitlab.com/ee/api/
### example output
The output will look something like this:
```plain
metrics.txt
# HELP languages_percent Languages scanned in percent
# TYPE languages_percent gauge
languages_percent{language="Java"} 11.73
languages_percent{language="CSS"} 1.97
languages_percent{language="TypeScript"} 3.5
languages_percent{language="HTML"} 6.14
languages_percent{language="JavaScript"} 17.16
languages_percent{language="Python"} 10.4
languages_percent{language="Modelica"} 3.7
languages_percent{language="TeX"} 1.64
languages_percent{language="Shell"} 6.35
languages_percent{language="Batchfile"} 0.76
languages_percent{language="HCL"} 7.15
languages_percent{language="BitBake"} 0.56
languages_percent{language="C"} 5.25
languages_percent{language="C++"} 0.72
languages_percent{language="Matlab"} 2.77
languages_percent{language="TXL"} 0.05
languages_percent{language="Objective-C"} 1.48
languages_percent{language="XSLT"} 1.68
languages_percent{language="Perl"} 1.71
languages_percent{language="Ruby"} 0.03
languages_percent{language="C#"} 10.3
languages_percent{language="PowerShell"} 0.11
languages_percent{language="Pascal"} 0.01
languages_percent{language="ASP"} 0.0
languages_percent{language="PLpgSQL"} 0.0
languages_percent{language="Makefile"} 2.06
languages_percent{language="SQLPL"} 0.0
languages_percent{language="Puppet"} 0.0
languages_percent{language="Groovy"} 2.56
languages_percent{language="M4"} 0.01
languages_percent{language="Roff"} 0.15
languages_percent{language="CMake"} 0.01
languages_percent{language="NSIS"} 0.01
languages_percent{language="PHP"} 0.0
languages_percent{language="Go"} 0.0
languages_percent{language="Smalltalk"} 0.02
languages_percent{language="Visual Basic"} 0.0
languages_percent{language="Smarty"} 0.0
# HELP languages_scanned_total Total languages scanned
# TYPE languages_scanned_total gauge
languages_scanned_total 38.0
# HELP projects_scanned_total Total projects scanned
# TYPE projects_scanned_total gauge
projects_scanned_total 61.0
# HELP projects_skipped_total Total projects skipped
# TYPE projects_skipped_total gauge
projects_skipped_total 0.0
# HELP projects_no_language_total Projects without language detected
# TYPE projects_no_language_total gauge
projects_no_language_total 39.0
# HELP groups_scanned_total Total groups scanned
# TYPE groups_scanned_total gauge
groups_scanned_total 0.0
```
Run the script via GitLab CI with schedules and export the metrics.txt file as GitLab pages.
Then you can add it to your Prometheus instance as scrape source.
Raw data
{
"_id": null,
"home_page": "https://github.com/max-wittig/gitlab-languages",
"name": "gitlab-languages",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "gitlab,languages,api,python-gitlab,prometheus,metrics",
"author": "Max Wittig",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/86/67/0c6d3bddbcf9ece8bf2fa613395c930a547a6d3cf57150844b6bbce9efef/gitlab_languages-2.3.2.tar.gz",
"platform": null,
"description": "# gitlab-languages\n\n[![PyPI - License](https://img.shields.io/pypi/l/gitlab-languages.svg)](https://github.com/max-wittig/gitlab-languages/blob/master/LICENSE)\n\nUtility to generate a Prometheus data source text file for your GitLab instance\nusing the [GitLab Language API](https://docs.gitlab.com/ee/api/projects.html#languages)\n\n## installation from PyPI\n\n1. Install from PyPI as CLI\n\n ```bash\n pip install -U gitlab-languages\n ```\n\n1. Run the program\n\n ```bash\n gitlab-languages --cache cache.json --args owned=True # more info about usage: see below\n ```\n\n## installation from source\n\n1. Install python dependencies\n\n ```bash\n poetry install\n ```\n\n1. Set the required environment variables\n\n ```bash\n export GITLAB_TOKEN=<SOME_TOKEN_WITH_API_SCOPE>\n export GITLAB_URL=https://gitlab.com # optional, defaults to https://gitlab.com\n # optional:\n export WORKER_COUNT=24\n ```\n\n1. Run the tool\n\n ```bash\n gitlab-languages\n ```\n\n## usage\n\n```plain\nusage: gitlab_languages [-h] [--project_limit PROJECT_LIMIT]\n [--args ARGS [ARGS ...]]\n [--groups GROUPS [GROUPS ...]]\n [--ignore_groups IGNORE_GROUPS [IGNORE_GROUPS ...]]\n [--cache CACHE] [-o OUTPUT]\n\noptional arguments:\n -h, --help show this help message and exit\n --project_limit PROJECT_LIMIT\n Set project limit to scan\n --args ARGS [ARGS ...]\n Provide custom args to the GitLab API\n --groups GROUPS [GROUPS ...]\n Scan only certain groups\n --ignore_groups IGNORE_GROUPS [IGNORE_GROUPS ...]\n Ignore certain groups and their projects\n --cache CACHE Cache file to use\n -o OUTPUT, --output OUTPUT\n Location of the metrics file output\n```\n\n### additional arguments\n\nYou can specify additional arguments, that will be directly supplied to the\n[python-gitlab library](https://github.com/python-gitlab/python-gitlab) or to the GitLab API endpoint.\nExample:\n\n```bash\ngitlab-languages --args owned=True\n```\n\nMore info about the available additional args can be found here:\n\n* http://python-gitlab.readthedocs.io/en/stable/\n* https://docs.gitlab.com/ee/api/\n\n### example output\n\nThe output will look something like this:\n\n```plain\nmetrics.txt\n\n# HELP languages_percent Languages scanned in percent\n# TYPE languages_percent gauge\nlanguages_percent{language=\"Java\"} 11.73\nlanguages_percent{language=\"CSS\"} 1.97\nlanguages_percent{language=\"TypeScript\"} 3.5\nlanguages_percent{language=\"HTML\"} 6.14\nlanguages_percent{language=\"JavaScript\"} 17.16\nlanguages_percent{language=\"Python\"} 10.4\nlanguages_percent{language=\"Modelica\"} 3.7\nlanguages_percent{language=\"TeX\"} 1.64\nlanguages_percent{language=\"Shell\"} 6.35\nlanguages_percent{language=\"Batchfile\"} 0.76\nlanguages_percent{language=\"HCL\"} 7.15\nlanguages_percent{language=\"BitBake\"} 0.56\nlanguages_percent{language=\"C\"} 5.25\nlanguages_percent{language=\"C++\"} 0.72\nlanguages_percent{language=\"Matlab\"} 2.77\nlanguages_percent{language=\"TXL\"} 0.05\nlanguages_percent{language=\"Objective-C\"} 1.48\nlanguages_percent{language=\"XSLT\"} 1.68\nlanguages_percent{language=\"Perl\"} 1.71\nlanguages_percent{language=\"Ruby\"} 0.03\nlanguages_percent{language=\"C#\"} 10.3\nlanguages_percent{language=\"PowerShell\"} 0.11\nlanguages_percent{language=\"Pascal\"} 0.01\nlanguages_percent{language=\"ASP\"} 0.0\nlanguages_percent{language=\"PLpgSQL\"} 0.0\nlanguages_percent{language=\"Makefile\"} 2.06\nlanguages_percent{language=\"SQLPL\"} 0.0\nlanguages_percent{language=\"Puppet\"} 0.0\nlanguages_percent{language=\"Groovy\"} 2.56\nlanguages_percent{language=\"M4\"} 0.01\nlanguages_percent{language=\"Roff\"} 0.15\nlanguages_percent{language=\"CMake\"} 0.01\nlanguages_percent{language=\"NSIS\"} 0.01\nlanguages_percent{language=\"PHP\"} 0.0\nlanguages_percent{language=\"Go\"} 0.0\nlanguages_percent{language=\"Smalltalk\"} 0.02\nlanguages_percent{language=\"Visual Basic\"} 0.0\nlanguages_percent{language=\"Smarty\"} 0.0\n# HELP languages_scanned_total Total languages scanned\n# TYPE languages_scanned_total gauge\nlanguages_scanned_total 38.0\n# HELP projects_scanned_total Total projects scanned\n# TYPE projects_scanned_total gauge\nprojects_scanned_total 61.0\n# HELP projects_skipped_total Total projects skipped\n# TYPE projects_skipped_total gauge\nprojects_skipped_total 0.0\n# HELP projects_no_language_total Projects without language detected\n# TYPE projects_no_language_total gauge\nprojects_no_language_total 39.0\n# HELP groups_scanned_total Total groups scanned\n# TYPE groups_scanned_total gauge\ngroups_scanned_total 0.0\n```\n\nRun the script via GitLab CI with schedules and export the metrics.txt file as GitLab pages.\nThen you can add it to your Prometheus instance as scrape source.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Utility to generate a Prometheus data source from programming languages inside GitLab repositores",
"version": "2.3.2",
"split_keywords": [
"gitlab",
"languages",
"api",
"python-gitlab",
"prometheus",
"metrics"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "a5b830835d54ecd2d862b504faa694f3",
"sha256": "ac83a2ab897eec78210b211727746529735bedd723ceaa94e54603b7d8b56a1e"
},
"downloads": -1,
"filename": "gitlab_languages-2.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a5b830835d54ecd2d862b504faa694f3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 7899,
"upload_time": "2022-12-20T10:29:47",
"upload_time_iso_8601": "2022-12-20T10:29:47.508753Z",
"url": "https://files.pythonhosted.org/packages/28/c9/93fe39ae0180d419fe5c11d9a5c6e0b10ed3ce576030d8b9c53c886c5508/gitlab_languages-2.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "3d81a23b07579e8d1263af20ac005ca3",
"sha256": "067ad191fd947f603e1ae353200445878327ec2491792d76080d38b4da763228"
},
"downloads": -1,
"filename": "gitlab_languages-2.3.2.tar.gz",
"has_sig": false,
"md5_digest": "3d81a23b07579e8d1263af20ac005ca3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 8147,
"upload_time": "2022-12-20T10:29:48",
"upload_time_iso_8601": "2022-12-20T10:29:48.675484Z",
"url": "https://files.pythonhosted.org/packages/86/67/0c6d3bddbcf9ece8bf2fa613395c930a547a6d3cf57150844b6bbce9efef/gitlab_languages-2.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-20 10:29:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "max-wittig",
"github_project": "gitlab-languages",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "gitlab-languages"
}