Skip to content

Commit

Permalink
Add steps for query
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisChinchilla <chris@chronosphere.io>
  • Loading branch information
ChrisChinchilla committed Dec 23, 2020
1 parent b62b5c0 commit 2eb1d3f
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 4 deletions.
91 changes: 90 additions & 1 deletion site/content/includes/quickstart-common-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ You can write metrics using one of two endpoints:
- _[{{% apiendpoint %}}prom/remote/write](/docs/m3coordinator/api/remote/)_ - Write a Prometheus remote write query to M3DB with a binary snappy compressed Prometheus WriteRequest protobuf message.
- _{{% apiendpoint %}}json/write_ - Write a JSON payload of metrics data. This endpoint is quick for testing purposes but is not as performant for production usage.

{{< tabs name="prom_http" >}}
{{< tabs name="prom_http_write" >}}
{{< tab name="Prometheus" >}}

{{< fileinclude file="quickstart-prometheus-steps.md" >}}
Expand Down Expand Up @@ -424,6 +424,95 @@ curl -X "POST" -G "{{% apiendpoint %}}query_range" \
{{% /tab %}}
{{< /tabs >}}

#### Values collected from Prometheus

If you followed the steps above for collecting metrics from Prometheus, the examples above work, but don't return any results. To query those results, use the followind commands.

{{< tabs name="example_promql_sum" >}}
{{% tab name="Linux" %}}

<!-- TODO: Check Linux command -->

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue_sum" \
-d "start=$(date "+%s" -d "45 seconds ago")" \
-d "end=$( date +%s )" \
-d "step=500s" | jq .
```

{{% /tab %}}
{{% tab name="macOS/BSD" %}}

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue_sum" \
-d "start=$( date -v -45S +%s )" \
-d "end=$( date +%s )" \
-d "step=500s" | jq .
```

{{% /tab %}}
{{% tab name="Output" %}}

```json
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "third_avenue_sum",
"group": "canary",
"instance": "localhost:8082",
"job": "node",
"monitor": "codelab-monitor"
},
"values": [
[
1608737991,
"5801.45"
]
]
},
{
"metric": {
"__name__": "third_avenue_sum",
"group": "production",
"instance": "localhost:8080",
"job": "node",
"monitor": "codelab-monitor"
},
"values": [
[
1608737991,
"5501.45"
]
]
},
{
"metric": {
"__name__": "third_avenue_sum",
"group": "production",
"instance": "localhost:8081",
"job": "node",
"monitor": "codelab-monitor"
},
"values": [
[
1608737991,
"13480.27"
]
]
}
]
}
}
```

{{% /tab %}}
{{< /tabs >}}
<!-- ## Next Steps
This quickstart covered getting a single-node M3DB cluster running, and writing and querying metrics to the cluster. Some next steps are:
Expand Down
128 changes: 128 additions & 0 deletions site/content/includes/quickstart-http-query-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
To query metrics, use the _{{% apiendpoint %}}query_range_ endpoint with the following data in the request body, all fields are required:

- `query`: A PromQL query
- `start`: Timestamp in `RFC3339Nano` of start range for results
- `end`: Timestamp in `RFC3339Nano` of end range for results
- `step`: A duration or float of the query resolution, the interval between results in the timespan between `start` and `end`.

Below are some examples using the metrics written above.

#### Return results in past 45 seconds

{{< tabs name="example_promql_regex" >}}
{{% tab name="Linux" %}}

<!-- TODO: Check this on Linux -->

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue" \
-d "start=$(date "+%s" -d "45 seconds ago")" \
-d "end=$( date +%s )" \
-d "step=5s" | jq .
```

{{% /tab %}}
{{% tab name="macOS/BSD" %}}

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue" \
-d "start=$( date -v -45S +%s )" \
-d "end=$( date +%s )" \
-d "step=5s" | jq .
```

{{% /tab %}}
{{% tab name="Output" %}}

```json
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "third_avenue",
"checkout": "1",
"city": "new_york"
},
"values": [
[
{{% now %}},
"3347.26"
],
[
{{% now %}},
"5347.26"
],
[
{{% now %}},
"7347.26"
]
]
}
]
}
}
```

{{% /tab %}}
{{< /tabs >}}

#### Values above a certain number

{{< tabs name="example_promql_range" >}}
{{% tab name="Linux" %}}

<!-- TODO: Check Linux command -->

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue > 6000" \
-d "start=$(date "+%s" -d "45 seconds ago")" \
-d "end=$( date +%s )" \
-d "step=5s" | jq .
```

{{% /tab %}}
{{% tab name="macOS/BSD" %}}

```shell
curl -X "POST" -G "{{% apiendpoint %}}query_range" \
-d "query=third_avenue > 6000" \
-d "start=$(date -v -45S "+%s")" \
-d "end=$( date +%s )" \
-d "step=5s" | jq .
```

{{% /tab %}}
{{% tab name="Output" %}}

```json
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "third_avenue",
"checkout": "1",
"city": "new_york"
},
"values": [
[
{{% now %}},
"7347.26"
]
]
}
]
}
}
```

{{% /tab %}}
{{< /tabs >}}
1 change: 1 addition & 0 deletions site/content/includes/quickstart-prometheus-query-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I be content
8 changes: 5 additions & 3 deletions site/content/includes/quickstart-prometheus-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ This quickstart uses [the textfile collector feature](https://github.com/prometh

#### Configure and Start Prometheus



With M3 running and ready to receive metrics, change your Prometheus configuration to add M3 as `remote_read` and `remote_write` URLs, and as a job. With the configuration below, Prometheus scrapes metrics from two local nodes `localhost:8080` and `localhost:8081` in the `production` group, and one local node `localhost:8082` in the `canary` group:

{{< codeinclude file="docs/includes/prometheus.yml" language="yaml" >}}
Expand Down Expand Up @@ -58,4 +56,8 @@ Run node_exporter from it's install location, passing the directory that contain
{{< codeinclude file="docs/includes/quickstart/node-3/node_exporter-3.sh" language="shell" >}}

{{< /tab >}}
{{< /tabs >}}
{{< /tabs >}}

{{% notice tip %}}
You can now confirm that the node_exporter exported metrics to Prometheus by sreaching for `third_avenue` in the Prometheus dashboard.
{{% /notice %}}

0 comments on commit 2eb1d3f

Please sign in to comment.