Skip to content

Commit 0606ca7

Browse files
committed
Expose onboarding metrics on worker level
1 parent 33c28de commit 0606ca7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

netbox_onboarding/metrics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Plugin additions to the NetBox navigation menu.
2+
3+
(c) 2020 Network To Code
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
"""
14+
from prometheus_client import Counter
15+
16+
onboardingtask_results_counter = Counter(
17+
name="onboardingtask_results_total", documentation="Count of results for Onboarding Task", labelnames=("status",)
18+
)

netbox_onboarding/worker.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@
1515

1616
from django.core.exceptions import ValidationError
1717
from django_rq import job
18+
from prometheus_client import Summary
1819

1920
from dcim.models import Device
2021

2122
from .choices import OnboardingFailChoices
2223
from .choices import OnboardingStatusChoices
2324
from .exceptions import OnboardException
25+
from .metrics import onboardingtask_results_counter
2426
from .models import OnboardingDevice
2527
from .models import OnboardingTask
2628
from .onboard import OnboardingManager
2729

2830
logger = logging.getLogger("rq.worker")
2931

3032

33+
REQUEST_TIME = Summary("onboardingtask_processing_seconds", "Time spent processing onboarding request")
34+
35+
36+
@REQUEST_TIME.time()
3137
@job("default")
3238
def onboard_device(task_id, credentials): # pylint: disable=too-many-statements
3339
"""Process a single OnboardingTask instance."""
@@ -98,4 +104,6 @@ def onboard_device(task_id, credentials): # pylint: disable=too-many-statements
98104
ot.save()
99105
onboarding_status = False
100106

107+
onboardingtask_results_counter.labels(status=ot.status).inc()
108+
101109
return dict(ok=onboarding_status)

0 commit comments

Comments
 (0)