mirror of
https://github.com/wahyd4/docker-hub-exporter.git
synced 2026-08-09 04:46:34 +10:00
Added last_updated to DockerHub Metrics
This commit is contained in:
@@ -39,12 +39,20 @@ Metrics will be made available on port 9170 by default
|
||||
```
|
||||
# HELP docker_hub_pulls_total counter of docker_pulls from the public API
|
||||
# TYPE docker_hub_pulls_total counter
|
||||
docker_hub_pulls_total{image="prometheus",user="prom"} 5476894.0
|
||||
docker_hub_pulls_total{image="node-exporter",user="prom"} 10103713.0
|
||||
docker_hub_pulls_total{image="prometheus-rancher-exporter",user="infinityworks"} 163994.0
|
||||
docker_hub_pulls_total{image="docker-hub-exporter",user="infinityworks"} 40.0
|
||||
# HELP docker_hub_stars gauge of docker_stars from the public API
|
||||
# TYPE docker_hub_stars gauge
|
||||
docker_hub_stars{image="prometheus",user="prom"} 136.0
|
||||
docker_hub_stars{image="node-exporter",user="prom"} 16.0
|
||||
docker_hub_stars{image="prometheus-rancher-exporter",user="infinityworks"} 3.0
|
||||
docker_hub_stars{image="docker-hub-exporter",user="infinityworks"} 1.0
|
||||
# HELP docker_hub_is_automated gauge of is_automated from the public API
|
||||
# TYPE docker_hub_is_automated gauge
|
||||
docker_hub_is_automated{image="prometheus-rancher-exporter",user="infinityworks"} 1.0
|
||||
docker_hub_is_automated{image="docker-hub-exporter",user="infinityworks"} 1.0
|
||||
# HELP docker_hub_last_updated Unix timestamp of last_updated from the public API
|
||||
# TYPE docker_hub_last_updated gauge
|
||||
docker_hub_last_updated{image="prometheus-rancher-exporter",user="infinityworks"} 1472731040.0
|
||||
docker_hub_last_updated{image="docker-hub-exporter",user="infinityworks"} 1473664481.0
|
||||
```
|
||||
|
||||
## Metadata
|
||||
|
||||
+10
-9
@@ -1,12 +1,7 @@
|
||||
from prometheus_client import start_http_server
|
||||
from prometheus_client.core import CounterMetricFamily, GaugeMetricFamily, REGISTRY
|
||||
|
||||
import json
|
||||
import requests
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
|
||||
import json, requests, sys, time, os, datetime, calendar
|
||||
|
||||
class HubCollector(object):
|
||||
|
||||
@@ -15,7 +10,9 @@ class HubCollector(object):
|
||||
print("Starting exporter")
|
||||
self._pull_metrics = CounterMetricFamily('docker_hub_pulls_total', 'counter of docker_pulls from the public API', labels=["image", "user"])
|
||||
self._star_metrics = GaugeMetricFamily('docker_hub_stars', 'gauge of docker_stars from the public API', labels=["image", "user"])
|
||||
|
||||
self._is_automated = GaugeMetricFamily('docker_hub_is_automated', 'gauge of is_automated from the public API', labels=["image", "user"])
|
||||
self._last_updated = GaugeMetricFamily('docker_hub_last_updated', 'Unix timestamp of last_updated from the public API', labels=["image", "user"])
|
||||
|
||||
for image in images:
|
||||
print("Getting JSON for " + image)
|
||||
self._get_json(image)
|
||||
@@ -25,6 +22,8 @@ class HubCollector(object):
|
||||
|
||||
yield self._pull_metrics
|
||||
yield self._star_metrics
|
||||
yield self._is_automated
|
||||
yield self._last_updated
|
||||
|
||||
def _get_json(self, image):
|
||||
print("Getting JSON Payload for " + image)
|
||||
@@ -33,13 +32,15 @@ class HubCollector(object):
|
||||
response = requests.get(image_url)
|
||||
self._response_json = json.loads(response.content.decode('UTF-8'))
|
||||
|
||||
|
||||
def _get_metrics(self):
|
||||
image_name = self._response_json['name']
|
||||
user_name = self._response_json['user']
|
||||
last_updated = datetime.datetime.strptime(self._response_json['last_updated'], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
last_updated_timestamp = float(calendar.timegm(last_updated.utctimetuple()))
|
||||
self._pull_metrics.add_metric([image_name, user_name], value=self._response_json['pull_count'])
|
||||
self._star_metrics.add_metric([image_name, user_name], value=self._response_json['star_count'])
|
||||
|
||||
self._is_automated.add_metric([image_name, user_name], value=self._response_json['is_automated'])
|
||||
self._last_updated.add_metric([image_name, user_name], value=last_updated_timestamp)
|
||||
|
||||
if __name__ == '__main__':
|
||||
start_http_server(int(os.getenv('BIND_PORT')))
|
||||
|
||||
Reference in New Issue
Block a user