metrics: Make metrics actually usable
This commit is contained in:
parent
933ee617ff
commit
2e4629d45e
8 changed files with 14 additions and 50 deletions
|
@ -1,8 +0,0 @@
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
from core.metrics import update_item_count
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = "Refresh the metrics"
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
update_item_count()
|
|
|
@ -1,11 +1,16 @@
|
||||||
from prometheus_client import Gauge
|
from django.apps import apps
|
||||||
from django_prometheus import exports
|
from prometheus_client.core import CounterMetricFamily, REGISTRY
|
||||||
from inventory.models import *
|
|
||||||
|
|
||||||
g_items_total = Gauge('c3lf_items_total', 'Current Total items')
|
class ModelCountCollector(object):
|
||||||
|
|
||||||
def update_item_count():
|
def collect(self):
|
||||||
# Get the count of MyModel objects
|
counter = CounterMetricFamily('model_count', 'Number of objects per model', labels=['model', 'app'])
|
||||||
count = Item.objects.count()
|
yield counter
|
||||||
# Set the gauge to the current count
|
if not apps.models_ready or not apps.apps_ready:
|
||||||
g_items_total.set(count)
|
return
|
||||||
|
for app_name, app_config in apps.app_configs.items():
|
||||||
|
for model in app_config.get_models():
|
||||||
|
counter.add_metric([model.__name__, app_name], model.objects.count())
|
||||||
|
yield counter
|
||||||
|
|
||||||
|
REGISTRY.register(ModelCountCollector())
|
|
@ -70,7 +70,6 @@ INSTALLED_APPS = [
|
||||||
'inventory',
|
'inventory',
|
||||||
'mail',
|
'mail',
|
||||||
'notify_sessions',
|
'notify_sessions',
|
||||||
'core'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
|
|
@ -311,16 +311,6 @@
|
||||||
notify:
|
notify:
|
||||||
- restart c3lf-sys3
|
- restart c3lf-sys3
|
||||||
|
|
||||||
- name: add c3lf-sys3-cron service
|
|
||||||
template:
|
|
||||||
src: templates/c3lf-sys3-cron.service.j2
|
|
||||||
dest: /etc/systemd/system/c3lf-sys3-cron.service
|
|
||||||
|
|
||||||
- name: add c3lf-sys3-cron timer
|
|
||||||
template:
|
|
||||||
src: templates/c3lf-sys3-cron.timer.j2
|
|
||||||
dest: /etc/systemd/system/c3lf-sys3-cron.timer
|
|
||||||
|
|
||||||
- name: reload systemd
|
- name: reload systemd
|
||||||
systemd:
|
systemd:
|
||||||
daemon_reload: yes
|
daemon_reload: yes
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=c3lf sys3 background service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=www-data
|
|
||||||
Group=www-data
|
|
||||||
WorkingDirectory=/var/www/c3lf-sys3
|
|
||||||
ExecStart=/var/www/c3lf-sys3/venv/bin/python3 /var/www/c3lf-sys3/repo/core/manage.py update_metrics
|
|
||||||
Environment=DJANGO_SETTINGS_MODULE=core.settings
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Run Nextcloud cron.php every 5 minutes
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnCalendar=minutely
|
|
||||||
Unit=c3lf-sys3-cron.service
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=timers.target
|
|
Loading…
Add table
Reference in a new issue