metrics: Add the first (simple) custom metrics
This commit is contained in:
parent
1e23151021
commit
06c0d6cf44
9 changed files with 60 additions and 0 deletions
0
core/core/management/__init__.py
Normal file
0
core/core/management/__init__.py
Normal file
0
core/core/management/commands/__init__.py
Normal file
0
core/core/management/commands/__init__.py
Normal file
8
core/core/management/commands/update_metrics.py
Normal file
8
core/core/management/commands/update_metrics.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
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()
|
11
core/core/metrics.py
Normal file
11
core/core/metrics.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from prometheus_client import Gauge
|
||||
from django_prometheus import exports
|
||||
from inventory.models import *
|
||||
|
||||
g_items_total = Gauge('c3lf_items_total', 'Current Total items')
|
||||
|
||||
def update_item_count():
|
||||
# Get the count of MyModel objects
|
||||
count = Item.objects.count()
|
||||
# Set the gauge to the current count
|
||||
g_items_total.set(count)
|
|
@ -70,6 +70,7 @@ INSTALLED_APPS = [
|
|||
'inventory',
|
||||
'mail',
|
||||
'notify_sessions',
|
||||
'core'
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
|
|
|
@ -19,6 +19,8 @@ from django.urls import path, include
|
|||
|
||||
from .version import get_info
|
||||
|
||||
from .metrics import *
|
||||
|
||||
urlpatterns = [
|
||||
path('djangoadmin/', admin.site.urls),
|
||||
path('api/2/', include('inventory.api_v2')),
|
||||
|
|
|
@ -311,6 +311,16 @@
|
|||
notify:
|
||||
- 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
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
@ -321,6 +331,12 @@
|
|||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: start c3lf-sys3 timer
|
||||
service:
|
||||
name: c3lf-sys3-cron.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: add postfix to www-data group
|
||||
user:
|
||||
name: postfix
|
||||
|
|
13
deploy/ansible/playbooks/templates/c3lf-sys3-cron.service.j2
Normal file
13
deploy/ansible/playbooks/templates/c3lf-sys3-cron.service.j2
Normal file
|
@ -0,0 +1,13 @@
|
|||
[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
|
|
@ -0,0 +1,9 @@
|
|||
[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