Skip to content

Commit

Permalink
prometheus metrics接口新增全部域名字段
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Nov 21, 2023
1 parent ce998d4 commit df15d47
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
44 changes: 38 additions & 6 deletions domain_admin/api/prometheus_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,54 @@ def metrics():
logger.info('success')

# 域名数据 @since v1.5.27
domain_info_fields = [
"id",
"user_id",
"domain",
"group_id",
"group_name",
"comment",
"domain_registrar",
"domain_registrar_url",
"domain_start_time",
"domain_expire_time",
"is_auto_update",
"is_expire_monitor",
"icp_company",
"icp_licence",
'tags',
'real_domain_expire_days',
'update_time_label',
'domain_start_date',
'domain_expire_date',
"create_time",
"update_time",
]

domain_info_gauge = Gauge(
"domain_info",
"this is a domain info data",
["domain", "group_name"],
name="domain_info",
documentation="this is a domain info data",
labelnames=domain_info_fields,
registry=registry)

domain_info_rows = DomainInfoModel.select()

domain_info_lst = [model_to_dict(row, extra_attrs=['real_domain_expire_days']) for row in domain_info_rows]
domain_info_lst = [model_to_dict(
row,
extra_attrs=[
'tags',
'real_domain_expire_days',
'update_time_label',
'domain_start_date',
'domain_expire_date',
]
) for row in domain_info_rows]

# 分组名
group_service.load_group_name(domain_info_lst)
for row in domain_info_lst:
domain_info_gauge.labels(
row['domain'],
row['group_name']
*[row[field] for field in domain_info_fields]
).set(row['real_domain_expire_days'])

return Response(prometheus_client.generate_latest(registry), mimetype='text/plain')
2 changes: 1 addition & 1 deletion http/prometheus.http
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

POST {{baseUrl}}/metrics
Content-Type: application/json
Authorization: Bearer f60c03bfff8bb42dcf6821542e5fd11e
Authorization: Bearer 27a79ecddc8947c9f5ce658453c45c9b

###

0 comments on commit df15d47

Please sign in to comment.