gomyck-tools 1.2.3__tar.gz → 1.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/PKG-INFO +2 -1
  2. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/metrics.py +46 -41
  3. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/gomyck_tools.egg-info/PKG-INFO +2 -1
  4. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/gomyck_tools.egg-info/requires.txt +1 -0
  5. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/setup.py +1 -1
  6. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/README.md +0 -0
  7. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/__init__.py +0 -0
  8. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/aes_tools.py +0 -0
  9. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/api_result.py +0 -0
  10. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/application.py +0 -0
  11. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/b64.py +0 -0
  12. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/bashPath.py +0 -0
  13. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/bottle_web_base.py +0 -0
  14. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/bottle_webserver.py +0 -0
  15. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/bottle_websocket.py +0 -0
  16. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/browser_element_tools.py +0 -0
  17. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/call.py +0 -0
  18. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/cjson.py +0 -0
  19. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/ckafka.py +0 -0
  20. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/compile_tools.py +0 -0
  21. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/console.py +0 -0
  22. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/cron_lite.py +0 -0
  23. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/database.py +0 -0
  24. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/date_utils.py +0 -0
  25. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/dict_wrapper.py +0 -0
  26. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/douglas_rarefy.py +0 -0
  27. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/download_tools.py +0 -0
  28. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/enums.py +0 -0
  29. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/ex.py +0 -0
  30. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/excelOpt.py +0 -0
  31. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/html_soup.py +0 -0
  32. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/http_utils.py +0 -0
  33. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/images_tools.py +0 -0
  34. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/imgDialog.py +0 -0
  35. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/mqtt_utils.py +0 -0
  36. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/obj.py +0 -0
  37. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/pacth.py +0 -0
  38. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/plan_area_tools.py +0 -0
  39. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/process_pool.py +0 -0
  40. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/pty_tools.py +0 -0
  41. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/resource_bundle_tools.py +0 -0
  42. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/rsa.py +0 -0
  43. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/screenshot_tools.py +0 -0
  44. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/sign.py +0 -0
  45. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/sm_tools.py +0 -0
  46. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/snow_id.py +0 -0
  47. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/str_diff.py +0 -0
  48. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/string_tools.py +0 -0
  49. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/sys_info.py +0 -0
  50. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/sys_log.py +0 -0
  51. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/thread_pool.py +0 -0
  52. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/upload_tools.py +0 -0
  53. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/win_canvas.py +0 -0
  54. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/win_control.py +0 -0
  55. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/wordFill.py +0 -0
  56. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/word_fill.py +0 -0
  57. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/word_fill_entity.py +0 -0
  58. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/ctools/work_path.py +0 -0
  59. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/gomyck_tools.egg-info/SOURCES.txt +0 -0
  60. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/gomyck_tools.egg-info/dependency_links.txt +0 -0
  61. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/gomyck_tools.egg-info/top_level.txt +0 -0
  62. {gomyck-tools-1.2.3 → gomyck-tools-1.2.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gomyck-tools
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: A ctools for python development by hao474798383
5
5
  Home-page: https://blog.gomyck.com
6
6
  Author: gomyck
@@ -27,5 +27,6 @@ Requires-Dist: paho-mqtt~=2.1.0
27
27
  Requires-Dist: fuzzywuzzy~=0.18.0
28
28
  Requires-Dist: pymysql~=1.1.1
29
29
  Requires-Dist: pyzipper==0.3.6
30
+ Requires-Dist: prometheus_client==0.21.1
30
31
 
31
32
  this package is for python development
@@ -1,29 +1,34 @@
1
1
  import os
2
2
  import threading
3
+ import time
3
4
  from enum import Enum
4
5
 
5
- from prometheus_client import Counter, Gauge, Summary, Histogram
6
-
7
- from ctools import call, cjson, sys_log
8
- from ctools.application import Server
6
+ from prometheus_client import Counter, Gauge, Summary, Histogram, start_http_server
7
+ from ctools import call, cjson, sys_log, work_path
9
8
 
10
9
  log = sys_log.flog
11
10
 
12
- metrics = {}
11
+ _metrics_port = 8011
12
+ _persistent_json = {}
13
13
  _metrics_initial = {}
14
- persistent_json = {}
15
- temp_metrics_json = {}
16
- is_metrics_init: bool = True
17
14
  _lock = threading.Lock()
18
15
 
19
16
 
17
+ # 认证中间件
18
+ # @app.before_request
19
+ # def check_authentication():
20
+ # auth = request.authorization
21
+ # if not auth or auth.username != USERNAME or auth.password != PASSWORD:
22
+ # return Response(
23
+ # "Unauthorized", 401, {"WWW-Authenticate": 'Basic realm="Login Required"'}
24
+ # )
25
+
20
26
  class MetricType(Enum):
21
27
  COUNTER = 'counter'
22
28
  GAUGE = 'gauge'
23
29
  SUMMARY = 'summary'
24
30
  HISTOGRAM = 'histogram'
25
31
 
26
-
27
32
  class Metric:
28
33
  def __init__(self, metric_type: MetricType, metric_key: str, metric_labels: [],
29
34
  persistent: bool = False, buckets: [] = None, reset: bool = False, desc: str = ""):
@@ -47,60 +52,51 @@ class Metric:
47
52
  raise Exception('metric type not found')
48
53
  _metrics_initial[metric_key] = self
49
54
 
50
-
51
55
  @call.once
52
- def init():
53
- global is_metrics_init
54
- global temp_metrics_json
55
- persistent_path = os.path.join(Server.indicatorsPath, 'persistent.json')
56
- if os.path.exists(persistent_path):
56
+ def init(reset_persistent: bool = False):
57
+ persistent_path = os.path.join(work_path.get_current_path(), 'persistent.json')
58
+ if os.path.exists(persistent_path) and not reset_persistent:
57
59
  with open(persistent_path, 'r') as persistent_file:
58
- global persistent_json
60
+ global _persistent_json
59
61
  try:
60
62
  content = persistent_file.readline()
61
- # log.info("persistent初始化: %s" % content)
62
- persistent_json = cjson.loads(content)
63
+ log.info("persistent初始化: %s" % content)
64
+ _persistent_json = cjson.loads(content)
63
65
  except Exception:
64
66
  log.error('persistent.json is not valid json!!!!!')
65
- persistent_json = {}
67
+ _persistent_json = {}
66
68
  _init_all_metrics()
67
- for key, item in persistent_json.items():
69
+ for key, item in _persistent_json.items():
68
70
  metrics_key = key.split("-")[0]
69
71
  if '_labels' in key or metrics_key not in _metrics_initial: continue
70
- opt(metrics_key, persistent_json[key + '_labels'], persistent_json[key])
72
+ opt(metrics_key, _persistent_json[key + '_labels'], _persistent_json[key])
71
73
  persistent_metrics()
72
- is_metrics_init = False
74
+ start_http_server(port=_metrics_port)
73
75
 
74
-
75
- @call.schd(60, start_by_call=True)
76
+ @call.schd(5, start_by_call=True)
76
77
  def persistent_metrics():
77
- if persistent_json and not _lock.locked():
78
- with open(os.path.join(Server.indicatorsPath, 'persistent.json'), 'w') as persistent_file:
79
- persistent_file.write(cjson.dumps(persistent_json))
78
+ if _persistent_json and not _lock.locked():
79
+ log.info('begin persistent metrics to file...')
80
+ with open(os.path.join(work_path.get_current_path(), 'persistent.json'), 'w') as persistent_file:
81
+ persistent_file.write(cjson.dumps(_persistent_json))
80
82
  persistent_file.flush()
81
83
 
82
-
83
84
  def opt(metric_key: str, label_values: [], metric_value: int):
84
85
  _lock.acquire(timeout=5)
85
86
  try:
86
87
  persistent_key = "%s-%s" % (metric_key, "_".join(map(str, label_values)))
87
- metric_entity: Metric = metrics.get(persistent_key)
88
- if not metric_entity:
89
- metric_entity = metrics[persistent_key] = _metrics_initial[metric_key]
90
-
88
+ metric_entity: Metric = _metrics_initial[metric_key]
91
89
  if metric_entity.persistent:
92
- if not is_metrics_init and not metric_entity.reset and persistent_key in persistent_json:
93
- persistent_json[persistent_key] += metric_value
90
+ if not metric_entity.reset and persistent_key in _persistent_json:
91
+ _persistent_json[persistent_key] += metric_value
94
92
  else:
95
- persistent_json[persistent_key] = metric_value
96
- persistent_json[persistent_key + '_labels'] = label_values
93
+ _persistent_json[persistent_key] = metric_value
94
+ _persistent_json[persistent_key + '_labels'] = label_values
97
95
 
98
- if persistent_json[persistent_key] < 0:
99
- persistent_json[persistent_key] = 0
96
+ if _persistent_json[persistent_key] < 0:
97
+ _persistent_json[persistent_key] = 0
100
98
  metric_value = 0
101
99
 
102
- temp_metrics_json[persistent_key] = metric_value
103
-
104
100
  if metric_entity.metric_type == MetricType.COUNTER or metric_entity.metric_type == MetricType.GAUGE:
105
101
  if label_values is None or len(label_values) == 0:
106
102
  if metric_entity.metric_type == MetricType.COUNTER and metric_entity.reset:
@@ -123,4 +119,13 @@ def opt(metric_key: str, label_values: [], metric_value: int):
123
119
  _lock.release()
124
120
 
125
121
  def _init_all_metrics():
126
- Metric(MetricType.COUNTER, 'demo123123', ['asdasd', 'sdfsdf'], persistent=True)
122
+ Metric(MetricType.GAUGE, 'gomyck', ['g_label1', 'g_label2'], persistent=True, reset=True)
123
+
124
+ # if __name__ == '__main__':
125
+ # init()
126
+ # import random
127
+ # while True:
128
+ # opt('data_reported_time', ['123', '123'], random.randint(1, 10))
129
+ # opt('data_received_time', ['123', '123'], random.randint(1, 10))
130
+ # opt('data_insert_time', ['123', '123'], random.randint(1, 10))
131
+ # time.sleep(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gomyck-tools
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: A ctools for python development by hao474798383
5
5
  Home-page: https://blog.gomyck.com
6
6
  Author: gomyck
@@ -27,5 +27,6 @@ Requires-Dist: paho-mqtt~=2.1.0
27
27
  Requires-Dist: fuzzywuzzy~=0.18.0
28
28
  Requires-Dist: pymysql~=1.1.1
29
29
  Requires-Dist: pyzipper==0.3.6
30
+ Requires-Dist: prometheus_client==0.21.1
30
31
 
31
32
  this package is for python development
@@ -15,3 +15,4 @@ paho-mqtt~=2.1.0
15
15
  fuzzywuzzy~=0.18.0
16
16
  pymysql~=1.1.1
17
17
  pyzipper==0.3.6
18
+ prometheus_client==0.21.1
@@ -11,7 +11,7 @@ requirements = parse_requirements(os.path.join(os.path.dirname(__file__), 'requi
11
11
 
12
12
  setup(
13
13
  name="gomyck-tools",
14
- version="1.2.3",
14
+ version="1.2.5",
15
15
  author="gomyck",
16
16
  author_email="hao474798383@163.com",
17
17
  description="A ctools for python development by hao474798383",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes