Skip to content

Commit

Permalink
Merge pull request #266 from membermatters/feature/more-prometheus-me…
Browse files Browse the repository at this point in the history
…trics

Feature/more prometheus metrics
  • Loading branch information
jabelone authored Jun 4, 2024
2 parents 8c8c33c + 35f0c2e commit d77a46a
Show file tree
Hide file tree
Showing 48 changed files with 1,056 additions and 198 deletions.
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

0 comments on commit d77a46a

Please sign in to comment.