<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>prometheus Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/prometheus/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/prometheus/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Tue, 12 Oct 2021 07:28:09 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://cdn.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>prometheus Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/prometheus/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Enabling PromQL queries with Erlenmeyer</title>
		<link>https://www.clever.cloud/blog/engineering/2021/10/12/enabling-promql-queries-with-erlenmeyer/</link>
		
		<dc:creator><![CDATA[Aurélien Hebert]]></dc:creator>
		<pubDate>Tue, 12 Oct 2021 07:28:09 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[metrics]]></category>
		<category><![CDATA[observability]]></category>
		<category><![CDATA[prometheus]]></category>
		<category><![CDATA[warp10]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/?p=3031</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="erlenmeyer promql 1" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-1368x528.jpg 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><div>You are using Clever Cloud to deploy <strong>applications runtimes</strong> or <strong>add-ons</strong>. But do you know that all Clever Cloud services are producing <strong>metrics?</strong> And that <a href="https://www.clever.cloud/developers/administrate/metrics/overview/">you already have&nbsp;<strong>access</strong> to all of them</a>? Indeed, we register an <strong>agent</strong> on our side, whose job is to collect all local data.<span id="more-3031"></span>Once it's done, they are stored in a Time Series database called <strong><a href="https://www.warp10.io/">Warp10</a></strong>.</div>
<div><img class="alignleft wp-image-3049 size-full" src="https://cdn.clever-cloud.com/uploads/2021/08/erlenmeyer_logo.png" alt="Erlenmeyer logo" width="643" height="205">
<div>
<div>To simplify the adoption of Warp10, the OVHcloud Metrics team built the <strong><a href="https://github.com/ovh/erlenmeyer">Erlenmeyer</a></strong> tool. In the first place, this tool enables the use of <strong>several open source protocols</strong> as PromQL, OpenTSDB, InfluxQL or Graphite to query Warp10 stored metrics.</div>
<div>Secondly, Erlenmeyer works as a proxy in front of a Warp10 cluster. Then we deployed a couple of&nbsp;Erlenmeyer instances in front of our Warp10 infrastructure, naturally providing new ways to query your application metrics.</div>
</div>
<blockquote>In this post, we will review what Erlenmeyer brings and how to handle Clever Cloud services metrics with <strong>PromQL</strong>.</blockquote>
</div>
<div>
<h2>Erlenmeyer protocols</h2>
<div>
<div>Erlenmeyer almost entirely enables <a href="https://www.ovh.com/blog/erlenmeyer-and-promql-compatibility/">PromQL queries</a>, OpenTSDB, InfluxQL and some of the Graphite functions. Moreover, you can retrieve the documentation about each protocol implementation and usage on Erlenmeyer's GitHub:</div>
<ul>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/promql.md">PromQL</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/openTSDB.md">OpenTSDB</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/influxql.md">InfluxQL</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/graphite.md">Graphite</a></li>
</ul>
On Clever Cloud, we deployed an <code>Erlenmeyer</code> in front of our Warp10 backend. This means <strong>all</strong> these <strong>open source protocols</strong> can be used to query our application Metrics. The <strong>host</strong> is <code>https://PROTO-c1-warp10-clevercloud-customers.services.clever-cloud.com/PROTO</code> with <code>PROTO</code> being:

</div>
<div>
<div>
<ul>
 	<li>for PromQL: <code>prometheus</code>,</li>
 	<li>for OpenTSDB: <code>opentsdb</code>,</li>
 	<li>for InfluxQL: <code>influxql</code>,</li>
 	<li>for Graphite: <code>graphite</code>.</li>
</ul>
<div>To authenticate your request, you need to use the Warp10 READ TOKEN as the password of the basic authentication. You can find it in the metrics panel of any Clever Cloud application:</div>
<div></div>
<div></div>
<div>
<div><img class="aligncenter wp-image-3059 size-full" src="https://cdn.clever-cloud.com/uploads/2021/09/Token.png" alt="Metrics token in the console" width="858" height="359"></div>
<div></div>
</div>
</div>
</div>
<div></div>
<div>
<div>
<div>
<div>
<h2>Retrieve the memory data with PromQL</h2>
<div>As a first step, let's store the Warp10 <code>READ TOKEN</code> and an <code>APP_ID</code> as an <strong>environment variable</strong>:</div>
</div>
<div></div>
</div>
<div>
<div>
<pre><code class="language-shell">export TOKEN=MY_AWESOME_TOKEN # Replace the value by your Clever Cloud Warp10 token
export APP_ID=app_test # Replace the value by one of your own Clever Cloud application
</code></pre>
</div>
</div>
</div>
<div>
<h3>Get raw data</h3>
</div>
<div>
<div>
<div>
<div>To retrieve the <code>mem.used_percent</code> in <strong>PromQL</strong>, we need to send an <code>HTTP GET</code> request to Erlenmeyer, with the TOKEN as basic AUTH. In that case, the PromQL <code>GET</code> request requires four parameters: query, start, end and step. Similarly, to learn more about the PromQL language, you can read the <a href="https://prometheus.io/docs/prometheus/latest/querying/basics/">Prometheus documentation</a>. In our case we will create a simple query to get the raw data:</div>
</div>
</div>
</div>
<div>
<div>
<div>
<pre><code class="language-shell">api/v1/query_range?
query=mem.used_percent{app_id="$APP_ID"}&amp;
start=1623289800&amp;
end=1623311400&amp;
step=120s</code></pre>
</div>
<div>
<div>The <code>query</code> parameter is used for the PromQL queries: <code>start</code> and <code>end</code> are milliseconds timestamps corresponding to the time limit to get data. And the <code>step</code> one is the <strong>sampling</strong> parameter.</div>
<div>As data are collected around every minute, let's set at least twice the duration:&nbsp;<code>120s</code>.</div>
<div></div>
<div>Now, to get the result, execute the following <code>cURL</code> <strong>url encoded</strong>:</div>
<div></div>
</div>
<pre><code class="language-shell">curl --request GET --url "https://u:${TOKEN}@prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/api/v1/query_range?query=mem.used_percent%7Bapp_id%3D%22${APP_ID}%22%7D&amp;start=1623289800&amp;end=1623311400&amp;step=120s" --header 'Content-Type: application/json'
</code></pre>
<div>
<div>
<h3>Group by example</h3>
A group by query can be useful in the Clever Cloud case to merge some series (multiple deployments or instances). Thus we will <strong>group</strong> data based on the <code>app_id</code> labels in the following example.
<div>We will re-use the stored variable <code>READ_TOKEN</code>&nbsp; and <code>APP_ID</code>. To compute a group by in our case we apply the <code>max</code> PromQL <strong>function</strong> grouped by the series <code>app_id</code> label:</div>
<div></div>
</div>
<pre><code class="language-shell">api/v1/query_range?
query=max(mem.used_percent{app_id="$APP_ID"}) by (app_id)&amp;
start=1623289800&amp;
end=1623311400&amp;
step=120s
</code></pre>
<div>
<div>Finally to get the result, execute the following <code>cURL</code> <strong>url encoded</strong>:</div>
<div></div>
<pre><code class="language-shell">curl --request GET --url "https://u:${TOKEN}@prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/api/v1/query_range?query=max(mem.used_percent%7Bapp_id%3D%22${APP_ID}%22%7D)%20by%20(app_id)&amp;start=1623289800&amp;end=1623311400&amp;step=120s" --header 'Content-Type: application/json'
</code></pre>
</div>
</div>
<div>
<div>
<h2>Grafana PromQL data source</h2>
You may use <a href="https://grafana.com/">Grafana</a> to create you own dashboards, which is an open source interactive visualisation web application (to deploy a Grafana as a Clever Cloud application, we provide a <a href="https://github.com/CleverCloud/grafana-example">github example</a> and you can also follow this <a href="https://blog.kbdev.io/dev/2021/08/24/grafana-clevercloud.html">French blog post</a>). Of course you can configure a <strong>PromQL</strong> <strong>data source</strong> to get Clever Cloud applications metrics:

</div>
<ul>
 	<li>create a <strong>Prometheus</strong> source,</li>
 	<li>then set Prometheus source <strong>host</strong> to <code>https://prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus</code>,</li>
 	<li>in addition activate the<strong> basic authentication</strong> with a <strong>user</strong> set to <code>metrics</code> and a <strong>password</strong> containing your <code>read Warp10 token</code>,</li>
 	<li>to conclude, click on <code>Save and Test</code>, your Prometheus data source should now be working!</li>
</ul>
</div>
</div>
<div>
<div>
<div>
<div>
<div><img class="aligncenter wp-image-3076 size-full" src="https://cdn.clever-cloud.com/uploads/2021/09/PromQL_source_grafana.png" alt="PromQL Grafana data source configuration" width="773" height="781"></div>
</div>
</div>
</div>
</div>
</div>
<div>
<div>
<h2>Prometheus UI with remote_read endpoint</h2>
Like with Grafana, you can use <a href="https://prometheus.io/docs/introduction/overview/">Prometheus</a> and plot Clever Cloud metrics in the <strong>Web UI</strong>. And as a matter of fact, simply fill your Prometheus <strong>configuration</strong> with a <strong>remote_read</strong> source:
<pre><code class="language-yaml">api/v1/query_range?
remote_read:
  - url: "https://prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/remote_read/"
  basic_auth:
    username: "metrics"
    password: "TOKEN"
</code></pre>
<div></div>
<div>Restart Prometheus, then simply execute a Prometheus query in the UI as below:</div>
<pre><code class="language-shell">{ __name__= "mem.used_percent", app_id="$APP_ID" }
</code></pre>
<div>Our backend is able to correctly resolve <code>.</code>&nbsp; which are invalid prometheus characters. Nonetheless the backend response will always translate those <code>.</code> values in series data (name or labels) into valid <code>_</code>.</div>
</div>
<h2>To Sum Up</h2>
As you can see with this post, you can get metrics of Clever Cloud applications and add-ons. Presently you now have <strong>one more way</strong> to query them, as Erlenmeyer allows the use of <code>PromQL</code>. However the drawback is that you will have to <strong>update regularly your token</strong>, as they expire in a few days. We are working on a solution to improve the user experience. First, we will soon provide our customers with access to a <strong>Grafana</strong> with <strong>configured data source and already pre-filled dashboards</strong>. The <strong>token</strong> will be handled on our side and you will then be able to build your own graphs with <code>PromQL</code> or <code>WarpScript</code> queries.

</div>
</div>
</div>]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="erlenmeyer promql 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/10/erlenmeyer-promql-1-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><div>You are using Clever Cloud to deploy <strong>applications runtimes</strong> or <strong>add-ons</strong>. But do you know that all Clever Cloud services are producing <strong>metrics?</strong> And that <a href="https://www.clever.cloud/developers/administrate/metrics/overview/">you already have&nbsp;<strong>access</strong> to all of them</a>? Indeed, we register an <strong>agent</strong> on our side, whose job is to collect all local data.<span id="more-3031"></span>Once it's done, they are stored in a Time Series database called <strong><a href="https://www.warp10.io/">Warp10</a></strong>.</div>
<div><img class="alignleft wp-image-3049 size-full" src="https://cdn.clever-cloud.com/uploads/2021/08/erlenmeyer_logo.png" alt="Erlenmeyer logo" width="643" height="205">
<div>
<div>To simplify the adoption of Warp10, the OVHcloud Metrics team built the <strong><a href="https://github.com/ovh/erlenmeyer">Erlenmeyer</a></strong> tool. In the first place, this tool enables the use of <strong>several open source protocols</strong> as PromQL, OpenTSDB, InfluxQL or Graphite to query Warp10 stored metrics.</div>
<div>Secondly, Erlenmeyer works as a proxy in front of a Warp10 cluster. Then we deployed a couple of&nbsp;Erlenmeyer instances in front of our Warp10 infrastructure, naturally providing new ways to query your application metrics.</div>
</div>
<blockquote>In this post, we will review what Erlenmeyer brings and how to handle Clever Cloud services metrics with <strong>PromQL</strong>.</blockquote>
</div>
<div>
<h2>Erlenmeyer protocols</h2>
<div>
<div>Erlenmeyer almost entirely enables <a href="https://www.ovh.com/blog/erlenmeyer-and-promql-compatibility/">PromQL queries</a>, OpenTSDB, InfluxQL and some of the Graphite functions. Moreover, you can retrieve the documentation about each protocol implementation and usage on Erlenmeyer's GitHub:</div>
<ul>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/promql.md">PromQL</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/openTSDB.md">OpenTSDB</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/influxql.md">InfluxQL</a></li>
 	<li><a href="https://github.com/ovh/erlenmeyer/blob/master/doc/graphite.md">Graphite</a></li>
</ul>
On Clever Cloud, we deployed an <code>Erlenmeyer</code> in front of our Warp10 backend. This means <strong>all</strong> these <strong>open source protocols</strong> can be used to query our application Metrics. The <strong>host</strong> is <code>https://PROTO-c1-warp10-clevercloud-customers.services.clever-cloud.com/PROTO</code> with <code>PROTO</code> being:

</div>
<div>
<div>
<ul>
 	<li>for PromQL: <code>prometheus</code>,</li>
 	<li>for OpenTSDB: <code>opentsdb</code>,</li>
 	<li>for InfluxQL: <code>influxql</code>,</li>
 	<li>for Graphite: <code>graphite</code>.</li>
</ul>
<div>To authenticate your request, you need to use the Warp10 READ TOKEN as the password of the basic authentication. You can find it in the metrics panel of any Clever Cloud application:</div>
<div></div>
<div></div>
<div>
<div><img class="aligncenter wp-image-3059 size-full" src="https://cdn.clever-cloud.com/uploads/2021/09/Token.png" alt="Metrics token in the console" width="858" height="359"></div>
<div></div>
</div>
</div>
</div>
<div></div>
<div>
<div>
<div>
<div>
<h2>Retrieve the memory data with PromQL</h2>
<div>As a first step, let's store the Warp10 <code>READ TOKEN</code> and an <code>APP_ID</code> as an <strong>environment variable</strong>:</div>
</div>
<div></div>
</div>
<div>
<div>
<pre><code class="language-shell">export TOKEN=MY_AWESOME_TOKEN # Replace the value by your Clever Cloud Warp10 token
export APP_ID=app_test # Replace the value by one of your own Clever Cloud application
</code></pre>
</div>
</div>
</div>
<div>
<h3>Get raw data</h3>
</div>
<div>
<div>
<div>
<div>To retrieve the <code>mem.used_percent</code> in <strong>PromQL</strong>, we need to send an <code>HTTP GET</code> request to Erlenmeyer, with the TOKEN as basic AUTH. In that case, the PromQL <code>GET</code> request requires four parameters: query, start, end and step. Similarly, to learn more about the PromQL language, you can read the <a href="https://prometheus.io/docs/prometheus/latest/querying/basics/">Prometheus documentation</a>. In our case we will create a simple query to get the raw data:</div>
</div>
</div>
</div>
<div>
<div>
<div>
<pre><code class="language-shell">api/v1/query_range?
query=mem.used_percent{app_id="$APP_ID"}&amp;
start=1623289800&amp;
end=1623311400&amp;
step=120s</code></pre>
</div>
<div>
<div>The <code>query</code> parameter is used for the PromQL queries: <code>start</code> and <code>end</code> are milliseconds timestamps corresponding to the time limit to get data. And the <code>step</code> one is the <strong>sampling</strong> parameter.</div>
<div>As data are collected around every minute, let's set at least twice the duration:&nbsp;<code>120s</code>.</div>
<div></div>
<div>Now, to get the result, execute the following <code>cURL</code> <strong>url encoded</strong>:</div>
<div></div>
</div>
<pre><code class="language-shell">curl --request GET --url "https://u:${TOKEN}@prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/api/v1/query_range?query=mem.used_percent%7Bapp_id%3D%22${APP_ID}%22%7D&amp;start=1623289800&amp;end=1623311400&amp;step=120s" --header 'Content-Type: application/json'
</code></pre>
<div>
<div>
<h3>Group by example</h3>
A group by query can be useful in the Clever Cloud case to merge some series (multiple deployments or instances). Thus we will <strong>group</strong> data based on the <code>app_id</code> labels in the following example.
<div>We will re-use the stored variable <code>READ_TOKEN</code>&nbsp; and <code>APP_ID</code>. To compute a group by in our case we apply the <code>max</code> PromQL <strong>function</strong> grouped by the series <code>app_id</code> label:</div>
<div></div>
</div>
<pre><code class="language-shell">api/v1/query_range?
query=max(mem.used_percent{app_id="$APP_ID"}) by (app_id)&amp;
start=1623289800&amp;
end=1623311400&amp;
step=120s
</code></pre>
<div>
<div>Finally to get the result, execute the following <code>cURL</code> <strong>url encoded</strong>:</div>
<div></div>
<pre><code class="language-shell">curl --request GET --url "https://u:${TOKEN}@prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/api/v1/query_range?query=max(mem.used_percent%7Bapp_id%3D%22${APP_ID}%22%7D)%20by%20(app_id)&amp;start=1623289800&amp;end=1623311400&amp;step=120s" --header 'Content-Type: application/json'
</code></pre>
</div>
</div>
<div>
<div>
<h2>Grafana PromQL data source</h2>
You may use <a href="https://grafana.com/">Grafana</a> to create you own dashboards, which is an open source interactive visualisation web application (to deploy a Grafana as a Clever Cloud application, we provide a <a href="https://github.com/CleverCloud/grafana-example">github example</a> and you can also follow this <a href="https://blog.kbdev.io/dev/2021/08/24/grafana-clevercloud.html">French blog post</a>). Of course you can configure a <strong>PromQL</strong> <strong>data source</strong> to get Clever Cloud applications metrics:

</div>
<ul>
 	<li>create a <strong>Prometheus</strong> source,</li>
 	<li>then set Prometheus source <strong>host</strong> to <code>https://prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus</code>,</li>
 	<li>in addition activate the<strong> basic authentication</strong> with a <strong>user</strong> set to <code>metrics</code> and a <strong>password</strong> containing your <code>read Warp10 token</code>,</li>
 	<li>to conclude, click on <code>Save and Test</code>, your Prometheus data source should now be working!</li>
</ul>
</div>
</div>
<div>
<div>
<div>
<div>
<div><img class="aligncenter wp-image-3076 size-full" src="https://cdn.clever-cloud.com/uploads/2021/09/PromQL_source_grafana.png" alt="PromQL Grafana data source configuration" width="773" height="781"></div>
</div>
</div>
</div>
</div>
</div>
<div>
<div>
<h2>Prometheus UI with remote_read endpoint</h2>
Like with Grafana, you can use <a href="https://prometheus.io/docs/introduction/overview/">Prometheus</a> and plot Clever Cloud metrics in the <strong>Web UI</strong>. And as a matter of fact, simply fill your Prometheus <strong>configuration</strong> with a <strong>remote_read</strong> source:
<pre><code class="language-yaml">api/v1/query_range?
remote_read:
  - url: "https://prometheus-c1-warp10-clevercloud-customers.services.clever-cloud.com/prometheus/remote_read/"
  basic_auth:
    username: "metrics"
    password: "TOKEN"
</code></pre>
<div></div>
<div>Restart Prometheus, then simply execute a Prometheus query in the UI as below:</div>
<pre><code class="language-shell">{ __name__= "mem.used_percent", app_id="$APP_ID" }
</code></pre>
<div>Our backend is able to correctly resolve <code>.</code>&nbsp; which are invalid prometheus characters. Nonetheless the backend response will always translate those <code>.</code> values in series data (name or labels) into valid <code>_</code>.</div>
</div>
<h2>To Sum Up</h2>
As you can see with this post, you can get metrics of Clever Cloud applications and add-ons. Presently you now have <strong>one more way</strong> to query them, as Erlenmeyer allows the use of <code>PromQL</code>. However the drawback is that you will have to <strong>update regularly your token</strong>, as they expire in a few days. We are working on a solution to improve the user experience. First, we will soon provide our customers with access to a <strong>Grafana</strong> with <strong>configured data source and already pre-filled dashboards</strong>. The <strong>token</strong> will be handled on our side and you will then be able to build your own graphs with <code>PromQL</code> or <code>WarpScript</code> queries.

</div>
</div>
</div>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
