Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

c# - Update prometheus counter based on a returned value

I'm trying to create a custom metric for Prometheus that will be scraped and shown on grafana. Basically a metric that will tell me how many files were sent today. I'm not sure if my understanding is correct, but can I use the Counter metric to increment based on a value that my Job has returned?

I have a job that sends over a file to a sftp server. I'm returning the value (in a DTO) of how many files are sent via a service method that my job controller is calling. Can i use the counter metric to scrape the returned value inside my DTO?

i have a job scheduler project that calls an endpoint url. Then my endpoint looks like this

[HttpGet]
[ProducesResponseType(typeof(bool), 200)]
[ProducesResponseType(404)]
[Route("Report")]
public async Task<IActionResult> SendReport()
{
        var result = SendToSFTP();
          
        var howManyFilesSent = result.FilesSent;
        ///insert code to call metric to increment

        return Ok(result);
}

I know another alternative is just to scrape the number of times my endpoint fail. But i want to know if its possible to use the counter metric in the above way?

http_requests_received_total{code="500",method="GET",controller="ScheduledJob",action="SendReport"} 1

thanks!

question from:https://stackoverflow.com/questions/66059362/update-prometheus-counter-based-on-a-returned-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...