Skip to main content

gitlab-languages

PyPI - License

Utility to generate a Prometheus data source text file for your GitLab instance using the GitLab Language API

installation from PyPI

  1. Install from PyPI as CLI

    pip install -U gitlab-languages
    
  2. Run the program

    gitlab-languages --cache cache.json --args owned=True # more info about usage: see below
    

installation from source

  1. Install python dependencies

    poetry install
    
  2. Set the required environment variables

    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
    
  3. Run the tool

    gitlab-languages
    

usage

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 or to the GitLab API endpoint. Example:

gitlab-languages --args owned=True

More info about the available additional args can be found here:

example output

The output will look something like this:

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.

Metadata

Release files for gitlab-languages 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitlab-languages 2.4.0
File Size Uploaded
gitlab_languages-2.4.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitlab-languages 2.4.0
File Interpreter ABI Platform
gitlab_languages-2.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / gitlab_languages-2.4.0.tar.gz

Download URL gitlab_languages-2.4.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e3ea0bbd2cb4371513caf40c01e535011f726ae339cf2d8397a133abba78ba9f
BLAKE2b-256 checksum
How to use checksums
69d86546889aeaa7efb77623a548a8ccc4310a2de42b9a6c887ac6caa8d793ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1021-azure

Release files / gitlab_languages-2.4.0-py3-none-any.whl

Download URL gitlab_languages-2.4.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b4f6e5fbdd8a6106c17a74dad9507a78d767efaba4a2ce7c6512f88bea7db7f
BLAKE2b-256 checksum
How to use checksums
572d17e73e2e6a467b39250b5f04d8376abd8fa018df17f6571452323c800d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1021-azure

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.6.0

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

1 release file

1.0.6

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page