# PRO TIP - Business hours in Dynatrace for SLOs or metric events

**URL:** <https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742>\
**Category:** Dynatrace Tips\
**Tags:** community-tips, slo, tips-and-tricks, problems-classic\
**Created:** [March 19, 2024, 7:39am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742 "2024-03-19T07:39:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [March 19, 2024, 7:39am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/1 "2024-03-19T07:39:38Z")

</div>

It’s quite common you don’t provide your services 24x7, but you will run them also during non-business hours. Until business hours or business calendar features land into the Dynatrace product natively, it’s possible to have a simple solution.

My approach below works for both Dynatrace Managed and SaaS.

For this feature, we will introduce a new metric - in this example **business\_hours** which will provide just static values:

- **1** during business hours
- **no value** outside of business hours
- **value between 0 and 1** to decrease priorities during “low business hours” (if applicable to your case)

Of course, in your environment you probably have different business hours for different services, thus you will likely need to have a dimension for it, such as level (24x7, 10x5, etc… ). See example below:

 ![Julius_Loman_0-1715850578739.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/d/cd9ee971a942ce2801fbe2b0676bae008e90d69d.png)

For example, values for an **8x5** service level will look like this - a value of **1** &nbsp;between 9:00 and 17:00 for each day and no value outside these times.

 ![Julius_Loman_2-1715850967716.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/c/4c48c5da3a2e2350874e58dc294932c8379920b0.png)

Then in the SLO definition, you will simply use [metric expression](https://docs.dynatrace.com/docs/shortlink/api-metrics-v2-metric-expressions) and multiply your desired metric with the business hours metric with the desired dimension representing your business hours, for example - for SLO on key requests:

```markup
(
    builtin:service.keyRequest.successes.server.rate:splitBy():auto
    * 
    business_hours:filter(and(or(eq(level,"8x5")))):splitBy():auto
):setUnit(Percent)

```

You may also commit the :setUnit transformation if you wish.

**IMPORTANT** : If the metric expression is displayed as a single value (Single value, table, etc) , please include :fold aggregation directly in the expression. This is needed due to the way Dynatrace queries metrics for single value charts. (infinite resolution).

So in the example - during business hours, your original metric will be unaffected (multiplied by 1) and outside of business hours, you will have no value. In this example I’ve chosen a service level of **8x5** , so the result will look like this - notice there are no values during the weekend of 16th and 17th March, and during Monday - Friday we have values only between 8:00 to 16:00 - representing 8x5.

 ![Julius_Loman_1-1715850880208.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/24811353bacdadb5658b0e65956065d174222cf6.png)  
You can use this approach also in Data Explorer, for Metric event definitions or elsewhere you can utilize metric expressions!

**Extension for generating business hours metric**

I’ve decided to publish the extension which allows you to create this business\_hours metric based on cron-like schedules or also from a real calendar! (defined in Office 365, Google Calendar or any remote calendar available in ical format).&nbsp; So you can define your business hours using a shared calendar and the extension will generate the metric accordingly.

You can download the extension from [here](https://github.com/juliusloman/dynatrace-extension-business-hours/releases). You will need to import the CA certificate into your Dynatrace environment and upload the extension. See the README.md for details and links on how to share calendars from Office 365 or Google Calendar.

Using calendar, you can freely define your business hours and exceptions. For example, define 8x5 as a recurring event in your calendar and just delete the occurrences, for example, for holidays.

**Changelog** v0.0.16

- Improved logging

v0.0.15

- Added support for generating negative levels
- Extension Dashboard with simple how-to and generated business hours metrics

v0.0.12

- Initial public version

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [April 8, 2024, 2:26pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/2 "2024-04-08T14:26:42Z")

</div>

Hi&nbsp; Julius,

(you have fans (-😉

I am very interested in your Extension, can you share?

KR Henk

---

<div class="post-metadata">

**Author:** ![jiri\_stefanek](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jiri\_stefanek](https://community.dynatrace.com/u/jiri_stefanek)\
**Post date:** [April 10, 2024, 8:10am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/3 "2024-04-10T08:10:43Z")

</div>

Hi Julius,

I am very interested.🙂

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [April 18, 2024, 7:58am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/4 "2024-04-18T07:58:14Z")

</div>

Hi&nbsp;[@jiri\_stefanek](https://community.dynatrace.com/user/30685)&nbsp;,  
can you please reach out to me directly at julius.loman (at) alanata.sk ?

---

<div class="post-metadata">

**Author:** ![jiri\_stefanek](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jiri\_stefanek](https://community.dynatrace.com/u/jiri_stefanek)\
**Post date:** [April 18, 2024, 8:13am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/5 "2024-04-18T08:13:57Z")

</div>

Hi Julius,

I just send you email.

---

<div class="post-metadata">

**Author:** ![hy](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hy](https://community.dynatrace.com/u/hy)\
**Post date:** [April 25, 2024, 6:16pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/6 "2024-04-25T18:16:44Z")

</div>

Hi Julius,

I just sent you an email directly as well. Hope to hear from you soon. Thank you!

---

<div class="post-metadata">

**Author:** ![hy](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hy](https://community.dynatrace.com/u/hy)\
**Post date:** [April 25, 2024, 6:38pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/7 "2024-04-25T18:38:50Z")

</div>

How did you create the custom metric that defines the different business hours for different services, thus you will likely need to have a dimension for it, such as level (24x7, 10x5, etc) in data explorer?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [April 26, 2024, 7:08am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/8 "2024-04-26T07:08:55Z")

</div>

[@hy](https://community.dynatrace.com/user/49896)&nbsp; exactly. I’ve just replied to your email.

---

<div class="post-metadata">

**Author:** ![elodie\_lam](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@elodie\_lam](https://community.dynatrace.com/u/elodie_lam)\
**Post date:** [May 7, 2024, 4:32pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/9 "2024-05-07T16:32:57Z")

</div>

Hi Julius, this is great! I would also be interested in your extension please 🙂

Thank you!

---

<div class="post-metadata">

**Author:** ![kanthv](https://avatars.discourse-cdn.com/v4/letter/k/ac91a4/32.png) [@kanthv](https://community.dynatrace.com/u/kanthv)\
**Post date:** [May 16, 2024, 5:06am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/10 "2024-05-16T05:06:57Z")

</div>

Sent an email to you and looking forward for your reply mate. Thanks

---

<div class="post-metadata">

**Author:** ![agravier](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/agravier/32/29303_2.png) [@agravier](https://community.dynatrace.com/u/agravier)\
**Post date:** [May 21, 2024, 10:13am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/11 "2024-05-21T10:13:34Z")

</div>

Hi&nbsp;&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;,

You are so inspiring !&nbsp;I have created my own python extension to create the custom metric but I use declarative endpoints with a specific format :

 ![AurelienGravier_1-1716285184703.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/9/893a82f536bd5b5181febcbe86eaa12d9dd81e91.png)

However, I’m encountering a limitation when I define a new business opening hours, I have to wait 1 month before use it in my SLO definition otherwise my SLO is null before the custom metric dimension creation.

Did you experiment the same behaviour with your extension ?

Thank you.  
Regards Aurelien.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [May 21, 2024, 5:13pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/12 "2024-05-21T17:13:28Z")

</div>

I’m not sure if I got your question. The only issue I ever encountered is that you cannot post metrics back in time. So if you define a service level you can only use it for the calculating SLO from current time.so plan accordingly and define your service levels in advance.

---

<div class="post-metadata">

**Author:** ![agravier](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/agravier/32/29303_2.png) [@agravier](https://community.dynatrace.com/u/agravier)\
**Post date:** [May 22, 2024, 7:33am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/13 "2024-05-22T07:33:47Z")

</div>

That’s exactly the limitation I’m encountering : you cannot post metrics back in time.

Thank you for your confirmation.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [May 22, 2024, 7:57am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/14 "2024-05-22T07:57:19Z")

</div>

Yes, that’s impossible as metrics can be ingested only one hour back in time. This will likely change soon with Grail, but not for Managed.

---

<div class="post-metadata">

**Author:** ![rgarzon1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rgarzon1/32/11844_2.png) [@rgarzon1](https://community.dynatrace.com/u/rgarzon1)\
**Post date:** [May 27, 2024, 4:45pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/15 "2024-05-27T16:45:21Z")

</div>

This could be one of the most clever tricks i seen, thank you for share it [@Julius\_Loman](https://community.dynatrace.com/user/3364)

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [June 4, 2024, 6:22am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/16 "2024-06-04T06:22:11Z")

</div>

Hi Julius,

Thanks a lot for your great post.  
I also just sent you and email and like “hy” user I’m interested to know how to create the custom metric that defines the different business hours for different services.

Thanks again.  
Regards,  
Elena

---

<div class="post-metadata">

**Author:** ![germanriezu](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@germanriezu](https://community.dynatrace.com/u/germanriezu)\
**Post date:** [June 21, 2024, 11:58am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/17 "2024-06-21T11:58:17Z")

</div>

Hi Julius, any ETA for this extension to be in the hub?

Thanks

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [June 21, 2024, 12:35pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/18 "2024-06-21T12:35:16Z")

</div>

[@germanriezu](https://community.dynatrace.com/user/42404)&nbsp;unfortunately it was not accepted. Only Dynatrace signed extensions can be in the HUB as of today, no 3rd party extensions. So at least for upcoming months this will stay as it is. You can download it from the provided link including the certificate and use it as a 3rd party extension. In case of any issues, reach out back here in this thread.

---

<div class="post-metadata">

**Author:** ![Kumari\_Sapna](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@Kumari\_Sapna](https://community.dynatrace.com/u/Kumari_Sapna)\
**Post date:** [April 3, 2025, 8:32am UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/19 "2025-04-03T08:32:30Z")

</div>

Hi&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;Thank you for sharing the detailed explanation.  
But the link shared above to download the extension is not accessible Are there some restrictions or any other issues? Can you kindly confirm?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [April 3, 2025, 1:37pm UTC](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742/20 "2025-04-03T13:37:43Z")

</div>

[@Kumari\_Sapna](https://community.dynatrace.com/user/78352),&nbsp;apparently there have been some changes to the sharing policy where this was hosted. I moved this project to github. The link was updated. Thanks for reporting.

[Next page](https://community.dynatrace.com/t/pro-tip-business-hours-in-dynatrace-for-slos-or-metric-events/44742.md?page=2)
