Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Change epoch for live metrics #115

Merged
merged 3 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions azure_monitor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Change epoch for live metrics
([#115](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/115))

## 0.4b.0
Released 2020-06-29

Expand Down
2 changes: 1 addition & 1 deletion azure_monitor/examples/metrics/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def get_ram_usage_callback(observer):
label_keys=(),
)

input("Metrics will be printed soon. Press a key to finish...\n")
input("Press any key to exit...")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
import json
import logging
import time

import requests

Expand Down Expand Up @@ -42,7 +41,7 @@ def _send_request(self, data: str, request_type: str) -> requests.Response:
"Expect": "100-continue",
"Content-Type": "application/json; charset=utf-8",
utils.LIVE_METRICS_TRANSMISSION_TIME_HEADER: str(
round(time.time()) * 1000
utils.get_time_since_epoch()
),
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
import datetime
import time
import uuid

Expand All @@ -26,3 +27,13 @@ def create_metric_envelope(instrumentation_key: str):
version=azure_monitor_context.get("ai.internal.sdkVersion"),
)
return envelope


def get_time_since_epoch():
now = datetime.datetime.now()
# epoch is defined as 12:00:00 midnight on January 1, 0001 for Microsoft
epoch = datetime.datetime(1, 1, 1)
delta = (now - epoch).total_seconds()
# return the number of 100-nanosecond intervals
delta = round(delta * 10000000)
return delta