-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
31 lines (22 loc) · 1 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
ROOT_HASH_TO_ENV = {
"F6OpKZKqvqeFp6CQmFomXNMfMj2EnaUSOXN+Mh+wVWk=": "mainnet",
"gj+B8wb/AmlPk1z1AhVI484rhrUpgSr2oSFIh56VoSg=": "testnet",
"ZNDXIYn4UXMFCwfL2UfKDX+ALn7b5f//UiPBF2vS/PY=": "sandbox",
}
LOCAL_CONFIG_PATH = "/usr/src/validator-monitoring/local.config.json"
def get_environment():
with open(LOCAL_CONFIG_PATH) as f:
config = json.load(f)
root_hash = config["validator"]["zero_state"]["root_hash"]
return ROOT_HASH_TO_ENV.get(root_hash, "env_not_known")
class EnvEnrichedConsumer():
def get_plain_tags(self):
return ['SERVICE:ton'] + self.instance.get('tags', [])
def get_tags(self):
tags = ['SERVICE:ton', 'ENVIRONMENT:{}'.format(get_environment())]
return tags + self.instance.get('tags', [])
def send_gauge_with_env_tag(self, name: str, value):
self.gauge(name, value, tags=self.get_tags())
def send_count_with_env_tag(self, name: str, value):
self.count(name, value, tags=self.get_tags())