docker_hub_exporter

package module
v0.0.0-...-125fe67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 9 Imported by: 0

README

Prometheus Docker Hub Exporter

Exposes metrics of container pulls and stars from the Docker Hub API, to a Prometheus compatible endpoint. The exporter is capable of pulling down stats for individual images, or for orgs or users from DockerHub. This is based on the un-documented V2 Docker Hub API.

!!! This repository is now deprecated, feel free to fork !!!

Configuration

The image is setup to take parameters from environment variables or flags:

The available environment variables are:

  • BIND_PORT The port you wish to run the container on, defaults to 9170
  • ORGS The docker hub organizations you wish to monitor, expected in the format "org1, org2" (Also works for users)
  • IMAGES The images you wish to monitor, expected in the format "user/image1, user/image2". Can be across different dockerhub users.

Below is a list of the available flags. You can also find this list by using the --help flag.

  • images Images you wish to monitor: expected format 'user/image1,user/image2'
  • listen-address Address on which to expose metrics and web interface. (default ":9170")
  • organisations Organisations/Users you wish to monitor: expected format 'org1,org2'
  • telemetry-path Path under which to expose metrics. (default "/metrics")

Install and deploy

Run manually from Docker Hub:

docker run -d --restart=always -p 9170:9170 infinityworks/docker-hub-exporter -listen-address=:9170 -images="infinityworks/ranch-eye,infinityworks/prom-conf" -organisations="super6awspoc"

Build a docker image:

docker build -t <image-name> .
docker run -d --restart=always -p 9170:9170 <image-name> -listen-address=:9170 -images="infinityworks/ranch-eye,infinityworks/prom-conf" -organisations="super6awspoc"

Known Issues

Currently there is a known issue with this build where if you provide a image or list of images belonging to an organisation that has also been passed into the application then Prometheus will error during metrics gathering reporting that the metric was already collected with the same name and labels.

Metrics

Metrics will be made available on port 8080 by default An example of these metrics can be found in the METRICS.md markdown file in the root of this repository

Metadata

Documentation

Index

Constants

View Source
const Namespace = "docker_hub_image"

Namespace of the prometheus metrics

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter is used to store Metrics data

func New

func New(organisations, images []string, connectionRetries int, opts ...Option) *Exporter

New creates a new Exporter and returns it

func (Exporter) Collect

func (e Exporter) Collect(ch chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (Exporter) Describe

func (e Exporter) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type ImageResult

type ImageResult struct {
	Name        string    `json:"name"`
	User        string    `json:"user"`
	StarCount   float64   `json:"star_count"`
	IsAutomated bool      `json:"is_automated"`
	PullCount   float64   `json:"pull_count"`
	LastUpdated time.Time `json:"last_updated"`
}

type Option

type Option func(*Exporter)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithLogger

func WithLogger(logger *log.Logger) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type OrganisationResult

type OrganisationResult struct {
	Count    int           `json:"count"`
	Next     string        `json:"next"`
	Previous string        `json:"previous"`
	Results  []ImageResult `json:"results"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL