我正在尝试通过Flask服务自定义Prometheus指标。看着https://github.com/prometheus/client_python,我有一个类似于以下代码:
<svg version="1.1" baseProfile="full" width="256" height="256" xmlns="http://www.w3.org/2000/svg">
<defs>
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Dancing+Script:400');
</style>
<mask id="mask">
<rect x="0" y="0" width="256" height="256" stroke-width="0" fill="white" />
<text font-size="128" x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" fill="black" style="font-family: 'Dancing Script';">T</text>
</mask>
</defs>
<circle cx="128" cy="128" r="128" stroke-width="0" fill="red" mask="url(#mask)" />
<text font-size="128" x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" fill="black" style="font-family: 'Dancing Script';">T</text>
</svg>
使用此设置,我不确定是否应该在哪里声明自定义指标?
答案 0 :(得分:1)
通过将我的自定义收集器注册到REGISTRY中解决了该问题
for c in s_values:
df1 = FSCN_today[FSCN_today['Exporter Name'] == c]
legal.paragraphs[7].text = c
legal.paragraphs[8].text = df1[10:1].iloc # <- Changed
# Add a table with the same amount of columns as the DataFrame
table = legal.add_table(0, len(df1.columns))
table.autofit = True
# Create the header line (= column labels of the DataFrame)
header = table.add_row()
for col, cell in enumerate(header.cells):
cell.text = str(df1.columns[col])
# Insert the content of DataFrame in the table
for ind in df1.index:
row = table.add_row()
for pos, col in enumerate(df1.columns):
row.cells[pos].text = df1.loc[ind, col]
# Add a break in paragraph 15 (before the table)
legal.paragraphs[15].add_run().add_break()
# Add the table to paragraph 15
legal.paragraphs[15]._p.addnext(table._tbl)
notice_name = str(c)+ ".docx"
legal.save(notice_name)
# Remove the table
table._element.getparent().remove(table._element)
然后使用
REGISTRY.register(CustomCollector())