//native
type Clickhouse = {
username: string;
password: string;
host: string;
};
/**
* Get prometheus metrics
* Returns prometheus metrics for a service.
*/
export async function main(
auth: Clickhouse,
organizationId: string,
serviceId: string,
filtered_metrics: string | undefined
) {
const url = new URL(
`https://api.clickhouse.cloud/v1/organizations/${organizationId}/services/${serviceId}/prometheus`
);
for (const [k, v] of [["filtered_metrics", filtered_metrics]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 141 days ago