The proper way to proxy metrics from other system to Prometheus

1,010 views
Skip to first unread message

yingk...@gmail.com

unread,
Jan 16, 2018, 2:46:27 AM1/16/18
to Prometheus Developers
Hi all,

I am new to Prometheus and i have some questions about the basic concepts which i am seeking clarification. Let me try to illustrate my questions in the following example.

---

**Background**

I have an e-commerce application which i would like to monitor. Apart from the technical metrics, i would also like to get some business information like

1. total number of orders today
2. revenue today

---

**Scenario 1:**

Assume i have the right to alter the application, in that case i should implement the prometheus client library in the application code and expose these metrics at the /metrics endpoints.

Q1: In that case, i am direct instrumenting the e-commerce application. Is it correct?

Q2. So the code i added could be still regarded as an exporter and it is bundled with the application code?

---

**Scenario 2:**

Assume i am have NO control on the application code but it has an API where i could get the info i need. So i create another application using the prometheus client library and calls this API in order to expose the metrics at the /metrics endpoints.

Q3. In that case, i am NOT directing instrumenting the e-commerce application?

Q4: Am I writing an exporter?

Q5: How to control the refresh rate of the metrics? Should i call the API when prometheus scrapes the endpoint OR i should write a schedule job which keeps refreshing the metrics at the endpoint in a regular interval which is independent of the prometheus scrape interval?

---

**Scenario 3:**

Assume i am have NO control on the application code but it has an NO API provided. The only way i could get the business info is by querying the database. So i create another application using the prometheus client library and queries the database in order to expose the metrics at the /metrics endpoints.

Q6. In that case, i am NOT directing instrumenting the e-commerce application?

Q7: Am I writing an exporter?

Q8: How to control the refresh rate of the metrics? Should i query the db when prometheus scrapes the endpoints OR i should write a schedule job which keeps refreshing the metrics at the endpoint in a regular interval which is independent of the prometheus scrape interval?

---

**Other questions**

Q9. What is a collector? What is its role in exporter?

Q10. When i should use an collector? (ex. https://github.com/prometheus/client_python#custom-collectors)

Q11. How to control the metrics refresh rate when using collector?

Q12. Could i make use of collector in the above scenarios?

---

Some of the questions may sounds silly and i would be grateful if someone could give me more ideas on the definitions of those terms as well as some simple examples which could help understanding those concepts.

Thanks for your time.

Ben Kochie

unread,
Jan 16, 2018, 3:02:24 AM1/16/18
to yingk...@gmail.com, Prometheus Developers
Answers inline.

On Tue, Jan 16, 2018 at 8:46 AM, <yingk...@gmail.com> wrote:
Hi all,

I am new to Prometheus and i have some questions about the basic concepts which i am seeking clarification. Let me try to illustrate my questions in the following example.

---

**Background**

I have an e-commerce application which i would like to monitor. Apart from the technical metrics, i would also like to get some business information like

1. total number of orders today
2. revenue today

---

**Scenario 1:**

Assume i have the right to alter the application, in that case i should implement the prometheus client library in the application code and expose these metrics at the /metrics endpoints.

Q1: In that case, i am direct instrumenting the e-commerce application. Is it correct?

Yes
 

Q2. So the code i added could be still regarded as an exporter and it is bundled with the application code?

Not exactly, in our terminology exporters are stand-alone bridges.  However we don't have a single term to describe "directly instrumented application".  But from Prometheus perspective there is no difference between the two.


---

**Scenario 2:**

Assume i am have NO control on the application code but it has an API where i could get the info i need. So i create another application using the prometheus client library and calls this API in order to expose the metrics at the /metrics endpoints.

Q3. In that case, i am NOT directing instrumenting the e-commerce application?

Correct.
 

Q4: Am I writing an exporter?

Yes.
 

Q5: How to control the refresh rate of the metrics? Should i call the API when prometheus scrapes the endpoint OR i should write a schedule job which keeps refreshing the metrics at the endpoint in a regular interval which is independent of the prometheus scrape interval?

The best practice is for the exporter to initiate API requests for each Prometheus scrape.
 

---

**Scenario 3:**

Assume i am have NO control on the application code but it has an NO API provided. The only way i could get the business info is by querying the database. So i create another application using the prometheus client library and queries the database in order to expose the metrics at the /metrics endpoints.

Q6. In that case, i am NOT directing instrumenting the e-commerce application?

Correct.
 

Q7: Am I writing an exporter?

Yes
 

Q8: How to control the refresh rate of the metrics? Should i query the db when prometheus scrapes the endpoints OR i should write a schedule job which keeps refreshing the metrics at the endpoint in a regular interval which is independent of the prometheus scrape interval?

Same as the above, query the metrics source when Prometheus requests it.  The reasoning is that the Prometheus polling design dictates that the client has no control over the timing of collection, that is entirely controlled by the Prometheus server.  Since there may be more than one Prometheus server, there may be more than one simultaneous scrape.

There are already a couple of pre-built SQL exporters out there for turning generic SQL queries into metrics.

 

---

**Other questions**

Q9. What is a collector? What is its role in exporter?

Collectors are a special concept for modular exporters like the node_exporter and mysqld_exporter.  Depending on the use case you may want to enable or disable some collectors based on your monitoring needs.  Typically you don't need to worry about this for writing  your own direct instrumentation/exporters as you just add what you need in the first place.


Q10. When i should use an collector? (ex. https://github.com/prometheus/client_python#custom-collectors)

Generally you don't need to do this for direct instrumentation, but if you're writing for something more complex you may need them.
 

Q11. How to control the metrics refresh rate when using collector?

Refresh rate is entirely up to the Prometheus server(s)
 

Q12. Could i make use of collector in the above scenarios?

Most likely unnecessary.
 

---

Some of the questions may sounds silly and i would be grateful if someone could give me more ideas on the definitions of those terms as well as some simple examples which could help understanding those concepts.

Thanks for your time.

--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-developers+unsub...@googlegroups.com.
To post to this group, send email to prometheus-developers@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/c4b0eeab-e415-435f-b402-74ec450ed347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

yingk...@gmail.com

unread,
Jan 16, 2018, 3:12:21 AM1/16/18
to Prometheus Developers
Got it. Thanks Ben! =D
Reply all
Reply to author
Forward
0 new messages