Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/more prometheus metrics #266

Merged
merged 40 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d9fd92d
added prometheus metrics to all db models
jabelone May 28, 2024
98874e6
update gha
jabelone May 28, 2024
12e9fac
escaped backticks in gha comment
jabelone May 28, 2024
c42ea8a
update gha comment
jabelone May 28, 2024
10ba19e
added access device metrics
jabelone May 28, 2024
feb30cc
fixup metrics import
jabelone May 28, 2024
70aadbd
added name to door metrics
jabelone May 28, 2024
cef1af2
fixed door locked_out logging
jabelone May 28, 2024
a1cd835
fix bug with device uptime reporting endpoint
jabelone May 28, 2024
dcc17b3
Add Vikunja teams configuration
jabelone May 30, 2024
bcc191e
made vikunja team sync only happen if user active
jabelone May 30, 2024
f0d507c
Added celery task for application level metrics
jabelone May 30, 2024
e3952e6
version bump Python packages
jabelone May 30, 2024
e037872
fix typo in requirements
jabelone May 30, 2024
d0e05a6
add config for danihodovic/celery-exporter
jabelone May 30, 2024
0882e87
update celery metrics typo
jabelone May 31, 2024
0160ef6
add celery Prometheus exporter to caprover and Docker compose
jabelone May 31, 2024
a96886c
prepend all app level metrics with mm_
jabelone May 31, 2024
7d1ff23
add Prometheus metrics server to celery
jabelone May 31, 2024
f02a415
adjust logging
jabelone May 31, 2024
11c5dbf
update celery prom server signal
jabelone May 31, 2024
79d224a
setup api_metrics app and celery task to update them
jabelone May 31, 2024
79af581
fixed typo in metrics
jabelone May 31, 2024
da579e2
fix bug in metrics calc task
jabelone May 31, 2024
defd85f
update calculate metrics task return value
jabelone May 31, 2024
9171ebf
update metrics stored format
jabelone May 31, 2024
4a8fd13
update metric log
jabelone May 31, 2024
bfd7f5c
fixed metrics bug
jabelone Jun 1, 2024
e8b7580
removed old API_SECRET_KEY constance config
jabelone Jun 1, 2024
d2c041d
added 6/12 month membership metrics
jabelone Jun 1, 2024
879fd1e
increased some description fields in models
jabelone Jun 3, 2024
a21d710
added some memberbucks metrics
jabelone Jun 3, 2024
c0be813
added vending discord post and update vending memberbucks log message
jabelone Jun 3, 2024
9a7d084
update import typo
jabelone Jun 3, 2024
fe4ea1f
fix constance grouping
jabelone Jun 3, 2024
00c7a87
removed old, redundant mdns code
jabelone Jun 4, 2024
778b772
replaced all print calls with loggers
jabelone Jun 4, 2024
1d1d565
Make report_online_status default to False for auto provisioned devices
jabelone Jun 4, 2024
6334753
disable (un)lock, sync and reboot buttons on memberbucks devices
jabelone Jun 4, 2024
35f0c2e
removed interlock sync button
jabelone Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/comment_wrong_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,33 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const output = `
Warning: we only accept PRs to the \`dev\` branch. It looks like you've created a PR to the \`main\` branch. Please edit this PR and select the \`dev\` branch as the target branch instead. If this was intentional please ignore this message.
`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Warning: we only accept PRs to the `dev` branch. It looks like you've created a PR to the `main` branch. Please edit this PR and select the `dev` branch as the target branch instead. If this was intentional please ignore this message.'
body: output
})

comment_warning_internal_pr:
if: ${{ github.event.pull_request.head.ref != 'dev' }}
runs-on: ubuntu-latest
steps:
- name: Comment warning about the wrong branch selected for PR
id: comment_docker_image
uses: actions/github-script@v6
with:
script: |
const output = `
Warning: we only accept PRs to main from the \`dev\` branch. It looks like you've created a PR from a different branch. Please edit this PR and select the \`dev\` branch as the source branch instead. If this was intentional please ignore this message.
`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
16 changes: 14 additions & 2 deletions docker/caprover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ caproverOneClickApp:
Your service is available at http://$$cap_appname.$$cap_root_domain.
You may need to load the data fixtures or create an admin login using the Django cli.
You can connect to the running container and run something like `python3 manage.py loaddata fixtures/initial.json` to do this.
We also setup a prometheus exporter for celery at http://$$cap_appname-mm-celery-prom-exporter:9808/metrics.
The prometheus exporter is for celery level, not application level metrics.
displayName: "MemberMatters"
isOfficial: true
description: Open source membership management platform for makerspaces and community groups.
Expand Down Expand Up @@ -90,7 +92,6 @@ services:
# MemberMatters Celery Worker
$$cap_appname-mm-celery-worker:
image: membermatters/membermatters:$$cap_mm_version
# command: ["celery", "-A", "membermatters.celeryapp", "worker", "-l", "INFO"]
restart: always
environment:
MM_ENV: $$cap_env
Expand All @@ -113,7 +114,6 @@ services:
# MemberMatters Celery Beat
$$cap_appname-mm-celery-beat:
image: membermatters/membermatters:$$cap_mm_version
# command: ["celery", "-A", "membermatters.celeryapp", "beat", "-l", "INFO"]
restart: always
environment:
MM_ENV: $$cap_env
Expand All @@ -132,3 +132,15 @@ services:
- $$cap_appname-mm-webapp
caproverExtra:
notExposeAsWebApp: true

# Celery Prometheus Exporter
$$cap_appname-mm-celery-prom-exporter:
image: danihodovic/celery-exporter
restart: always
environment:
CE_BROKER_URL: "redis://srv-captain--$$cap_appname-mm-redis:6379/0"
depends_on:
- $$cap_appname-mm-redis
- $$cap_appname-mm-celery-worker
caproverExtra:
notExposeAsWebApp: true
9 changes: 9 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ services:
- mm-celery-worker
- mm-redis

mm-celery-prom-exporter:
image: danihodovic/celery-exporter
restart: always
environment:
CE_BROKER_URL: "redis://mm-redis:6379/0"
depends_on:
- mm-celery-worker
- mm-redis

volumes:
mm-postgres-volume:
driver: local
2 changes: 1 addition & 1 deletion docs/POST_INSTALL_STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ However, as noted below, currencies will use a hardcoded value set by a configur
* "SITE_NAME" - Name of the website.
* "SITE_OWNER" - Name of the organisation running this website.
* "GOOGLE_ANALYTICS_MEASUREMENT_ID" - Enter your measurement ID to enable Google analytics. Only the new GA4 measurement IDs are supported. It should look something like G-XXXXXXXXXX.
* "API_SECRET_KEY" - Secret key used to authenticate some requests from access control devices.

### Signup
* "INDUCTION_ENROL_LINK" - URL to enrol in the Canvas LMS induction course.
Expand Down Expand Up @@ -189,6 +188,7 @@ as above (NOT recommended for security).
* "ENABLE_DISCORD_INTEGRATION" - enable the post to Discord channel feature when an interlock or door swipe is recorded.
* "DISCORD_DOOR_WEBHOOK" - URL for the door webhook.
* "DISCORD_INTERLOCK_WEBHOOK" - URL for the interlock webhook.
* "DISCORD_MEMBERBUCKS_PURCHASE_WEBHOOK" - URL for the vending/product purchase webhook.

### Home Page and Welcome Email Cards

Expand Down
2 changes: 1 addition & 1 deletion memberportal/access/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@admin.register(AccessControlledDeviceAPIKey)
class AccessControlledDeviceAPIKey(APIKeyModelAdmin):
class AccessControlledDeviceAPIKeyAdmin(APIKeyModelAdmin):
pass


Expand Down
103 changes: 103 additions & 0 deletions memberportal/access/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from prometheus_client import Counter, Histogram

device_connections_total = Counter(
"mm_device_connections_total",
"Number of device connections",
["type", "id", "name"],
)

device_disconnections_total = Counter(
"mm_device_disconnections_total",
"Number of device disconnections",
["type", "id", "name"],
)

device_authentications_total = Counter(
"mm_device_authentications_total",
"Number of device authentications",
["type", "id", "name"],
)

device_checkins_total = Counter(
"mm_device_checkins_total",
"Number of device checkins",
["type", "id", "name"],
)

device_access_successes_total = Counter(
"mm_device_access_successes_total",
"Number of successful access swipes logged",
["type", "id", "name"],
)

device_access_failures_total = Counter(
"mm_device_access_failures_total",
"Number of failed access swipes logged",
["type", "id", "name"],
)

device_force_reboots_total = Counter(
"mm_device_force_reboots_total",
"Number of force reboots",
["type", "id", "name"],
)

device_syncs_total = Counter(
"mm_device_syncs_total",
"Number of syncs",
["type", "id", "name"],
)

device_force_bumps_total = Counter(
"mm_device_force_bumps_total",
"Number of force bumps",
["type", "id", "name"],
)

device_force_locks_total = Counter(
"mm_device_force_locks_total",
"Number of force locks",
["type", "id", "name"],
)

device_force_unlocks_total = Counter(
"mm_device_force_unlocks_total",
"Number of force unlocks",
["type", "id", "name"],
)

device_interlock_session_activations_total = Counter(
"mm_device_interlock_session_activations_total",
"Number of interlock session activations",
["type", "id", "name"],
)

device_interlock_sessions_left_on_total = Counter(
"mm_device_interlock_sessions_left_on_total",
"Number of interlock sessions left on",
["type", "id", "name"],
)

device_interlock_sessions_deactivated_total = Counter(
"mm_device_interlock_sessions_deactivated_total",
"Number of interlock session deactivations",
["type", "id", "name"],
)

device_interlock_sessions_rejected_total = Counter(
"mm_device_interlock_sessions_rejected_total",
"Number of interlock session rejections",
["type", "id", "name"],
)

device_interlock_sessions_cost_cents = Counter(
"mm_device_interlock_sessions_cost_cents",
"Cost of interlock sessions",
["type", "id", "name"],
)

device_interlock_session_duration_seconds = Histogram(
"mm_device_interlock_session_duration_seconds",
"Duration of interlock sessions",
["type", "id", "name"],
)
23 changes: 23 additions & 0 deletions memberportal/access/migrations/0019_auto_20240603_2150.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.25 on 2024-06-03 11:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("access", "0018_auto_20240525_0016"),
]

operations = [
migrations.AlterField(
model_name="accesscontrolleddevice",
name="description",
field=models.CharField(max_length=500, verbose_name="Description/Location"),
),
migrations.AlterField(
model_name="interlocklog",
name="reason",
field=models.CharField(blank=True, max_length=500, null=True),
),
]
Loading
Loading