Skip to content

Commit

Permalink
Copy Prometheus guide to all versions (#1190)
Browse files Browse the repository at this point in the history
* re-org, add asset

* remove asset due to filter syntax issue

see sensu/sensu-prometheus-collector#14

* landing page fixups

* articles

* fixups

* copy to all versions
  • Loading branch information
apaskulin authored Feb 12, 2019
1 parent 86abc89 commit eb093ff
Show file tree
Hide file tree
Showing 8 changed files with 1,219 additions and 85 deletions.
215 changes: 131 additions & 84 deletions content/sensu-go/5.0/getting-started/prometheus-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ product: "Sensu Go"
platformContent: false
---

- [What is the Sensu Prometheus Collector?](#what-is-the-sensu-prometheus-collector)
- [Why use Sensu with Prometheus?](#why-use-sensu-with-prometheus)
- [Install and configure Prometheus](#install-and-configure-prometheus)
- [Install and configure Sensu Go](#install-and-configure-sensu-go)
- [Install Sensu Prometheus Collector](#install-sensu-prometheus-collector)
- [Install Sensu InfluxDB Handler](#install-sensu-influxdb-handler)
- [Install and configure InfluxDB](#install-and-configure-influxdb)
- [Install and configure Grafana](#install-and-configure-grafana)
- [Set up](#set-up)
- [Install and configure Prometheus](#install-and-configure-prometheus)
- [Install and configure Sensu Go](#install-and-configure-sensu-go)
- [Install and configure InfluxDB](#install-and-configure-influxdb)
- [Install and configure Grafana](#install-and-configure-grafana)
- [Create a Sensu InfluxDB pipeline](#create-a-sensu-influxdb-pipeline)
- [Install Sensu InfluxDB handler](#install-sensu-influxdb-handler)
- [Create a Sensu handler](#create-a-sensu-handler)
- [Collect Prometheus metrics with Sensu](#collect-prometheus-metrics-with-sensu)
- [Install Sensu Prometheus Collector](#install-sensu-prometheus-collector)
- [Add a Sensu check to complete the pipeline](#add-a-sensu-check-to-complete-the-pipeline)
- [Visualize metrics with Grafana](#visualize-metrics-with-grafana)
- [Configure a dashboard in Grafana](#configure-a-dashboard-in-grafana)
- [View metrics in Grafana](#view-metrics-in-grafana)

## What is the Sensu Prometheus Collector?

Expand All @@ -29,7 +35,9 @@ This guide uses CentOS 7 as the operating system with all components running on

At the end, you will have Prometheus scraping metrics. The Sensu Prometheus Collector will then query the Prometheus API as a Sensu check, send those to an InfluxDB Sensu handler, which will send metrics to an InfluxDB instance. Finally, Grafana will query InfluxDB to display those collected metrics.

### Install and Configure Prometheus
## Set up

### Install and configure Prometheus

Download and extract Prometheus.

Expand Down Expand Up @@ -94,32 +102,6 @@ systemctl status sensu-backend
systemctl status sensu-agent
{{< /highlight >}}

### Install Sensu Prometheus Collector

{{< highlight shell >}}
wget -q -nc https://github.com/sensu/sensu-prometheus-collector/releases/download/1.1.4/sensu-prometheus-collector_1.1.4_linux_386.tar.gz -P /tmp/

tar xvfz /tmp/sensu-prometheus-collector_1.1.4_linux_386.tar.gz -C /tmp/

cp /tmp/bin/sensu-prometheus-collector /usr/local/bin/
{{< /highlight >}}

Confirm the collector can get metrics from Prometheus.

{{< highlight shell >}}
/usr/local/bin/sensu-prometheus-collector -prom-url http://localhost:9090 -prom-query up
{{< /highlight >}}

### Install Sensu InfluxDB handler

{{< highlight shell >}}
wget -q -nc https://github.com/sensu/sensu-influxdb-handler/releases/download/3.0.1/sensu-influxdb-handler_3.0.1_linux_amd64.tar.gz -P /tmp/

tar xvfz /tmp/sensu-influxdb-handler_3.0.1_linux_amd64.tar.gz -C /tmp/

cp /tmp/bin/sensu-influxdb-handler /usr/local/bin/
{{< /highlight >}}

### Install and configure InfluxDB

Add InfluxDB repo.
Expand Down Expand Up @@ -163,33 +145,63 @@ influx -execute "CREATE USER sensu WITH PASSWORD 'sensu'"
influx -execute "GRANT ALL ON sensu TO sensu"
{{< /highlight >}}

### Add Sensu check and handler to complete the pipeline
### Install and configure Grafana

Given the following resource definition in a file called `resources.json`:
Install Grafana.

{{< highlight shell >}}
sudo yum install -y https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.4-1.x86_64.rpm
{{< /highlight >}}

Change Grafana's listen port to not conflict with the Sensu Dashboard.

{{< highlight shell >}}
sudo sed -i 's/^;http_port = 3000/http_port = 4000/' /etc/grafana/grafana.ini
{{< /highlight >}}

Create a `/etc/grafana/provisioning/datasources/influxdb.yaml` file, and add an InfluxDB data source.

{{< highlight yml >}}
apiVersion: 1

deleteDatasources:
- name: InfluxDB
orgId: 1

datasources:
- name: InfluxDB
type: influxdb
access: proxy
orgId: 1
database: sensu
user: grafana
password: grafana
url: http://localhost:8086
{{< /highlight >}}

Start Grafana.

{{< highlight shell >}}
systemctl start grafana-server
{{< /highlight >}}

## Create a Sensu InfluxDB pipeline

### Install Sensu InfluxDB handler

{{< highlight shell >}}
wget -q -nc https://github.com/sensu/sensu-influxdb-handler/releases/download/3.0.1/sensu-influxdb-handler_3.0.1_linux_amd64.tar.gz -P /tmp/

tar xvfz /tmp/sensu-influxdb-handler_3.0.1_linux_amd64.tar.gz -C /tmp/

cp /tmp/bin/sensu-influxdb-handler /usr/local/bin/
{{< /highlight >}}

### Create a Sensu handler

Given the following handler definition in a file called `handler.json`:

{{< highlight shell >}}
{
"type": "CheckConfig",
"api_version": "core/v2",
"metadata": {
"name": "prometheus_metrics",
"namespace": "default"
},
"spec": {
"command": "/usr/local/bin/sensu-prometheus-collector -prom-url http://localhost:9090 -prom-query up",
"handlers": [
"influxdb"
],
"interval": 10,
"publish": true,
"output_metric_format": "influxdb_line",
"output_metric_handlers": [],
"subscriptions": [
"app_tier"
],
"timeout": 0
}
}
{
"type": "Handler",
"api_version": "core/v2",
Expand All @@ -206,64 +218,99 @@ Given the following resource definition in a file called `resources.json`:
}
{{< /highlight >}}

Use `sensuctl` to add the check and handler to the Sensu backend.
Use `sensuctl` to add the handler to Sensu.

{{< highlight shell >}}
sensuctl create -f resources.json
sensuctl create --file handler.json
{{< /highlight >}}

### Install and configure Grafana
## Collect Prometheus metrics with Sensu

Install Grafana.
### Install Sensu Prometheus Collector

{{< highlight shell >}}
sudo yum install -y https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.4-1.x86_64.rpm
wget -q -nc https://github.com/sensu/sensu-prometheus-collector/releases/download/1.1.4/sensu-prometheus-collector_1.1.4_linux_386.tar.gz -P /tmp/

tar xvfz /tmp/sensu-prometheus-collector_1.1.4_linux_386.tar.gz -C /tmp/

cp /tmp/bin/sensu-prometheus-collector /usr/local/bin/
{{< /highlight >}}

Change Grafana's listen port to not conflict with the Sensu Dashboard.
Confirm the collector can get metrics from Prometheus.

{{< highlight shell >}}
sudo sed -i 's/^;http_port = 3000/http_port = 4000/' /etc/grafana/grafana.ini
/usr/local/bin/sensu-prometheus-collector -prom-url http://localhost:9090 -prom-query up
up,instance=localhost:9090,job=prometheus value=1 1549991087
{{< /highlight >}}

Add an InfluxDB data source in `/etc/grafana/provisioning/datasources/influxdb.yaml`.
### Add a Sensu check to complete the pipeline

{{< highlight yml >}}
apiVersion: 1
Given the following check definition in a file called `check.json`:

deleteDatasources:
- name: InfluxDB
orgId: 1
{{< highlight shell >}}
{
"type": "CheckConfig",
"api_version": "core/v2",
"metadata": {
"name": "prometheus_metrics",
"namespace": "default"
},
"spec": {
"command": "/usr/local/bin/sensu-prometheus-collector -prom-url http://localhost:9090 -prom-query up",
"handlers": [
"influxdb"
],
"interval": 10,
"publish": true,
"output_metric_format": "influxdb_line",
"output_metric_handlers": [],
"subscriptions": [
"app_tier"
],
"timeout": 0
}
}
{{< /highlight >}}

datasources:
- name: InfluxDB
type: influxdb
access: proxy
orgId: 1
database: sensu
user: grafana
password: grafana
url: http://localhost:8086
_PRO TIP: `sensuctl create -f` also accepts files containing multiple resources definitions._

Use `sensuctl` to add the check to Sensu.

{{< highlight shell >}}
sensuctl create --file check.json
{{< /highlight >}}

Start Grafana.
We can see the events generated by the `prometheus_metrics` check in the Sensu dashboard.
Visit http://127.0.0.1:3000, and log in as the default admin user: username `admin` and password `P@ssw0rd!`.

We can also see the metric event data using sensuctl.

{{< highlight shell >}}
systemctl start grafana-server
sensuctl event list
Entity Check Output Status Silenced Timestamp
────────────── ──────────────────── ──────────────────────────────────────────────────────────────────────── ──────── ────────── ───────────────────────────────
sensu-centos keepalive Keepalive last sent from sensu-centos at 2019-02-12 01:01:37 +0000 UTC 0 false 2019-02-12 01:01:37 +0000 UTC
sensu-centos prometheus_metrics up,instance=localhost:9090,job=prometheus value=1 1549933306 0 false 2019-02-12 01:01:46 +0000 UTC
{{< /highlight >}}

## Visualize metrics with Grafana

### Configure a dashboard in Grafana

Download the Grafana dashboard configuration file from the Sensu docs.

{{< highlight shell >}}
wget https://docs.sensu.io/sensu-go/5.0/files/up_or_down_dashboard.json
{{< /highlight >}}

Using the just created file, add the dashboard to Grafana using an API call.
Using the downloaded file, add the dashboard to Grafana using an API call.

{{< highlight shell >}}
curl -s -XPOST -H 'Content-Type: application/json' -d@up_or_down_dashboard.json HTTP://admin:admin@127.0.0.1:4000/api/dashboards/db
{{< /highlight >}}

### View metrics in Grafana

Confirm metrics in Grafana with `admin:admin` login at http://127.0.0.1:4000.

Once logged in, click on Home in the upper left corner, then below click on the Up or Down Sample 2 dashboard. Once there, you should see a graph that has started showing metrics like this
Expand Down
5 changes: 4 additions & 1 deletion content/sensu-go/5.0/getting-started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ Welcome to the Sensu sandbox! The sandbox is the best place to get started with
- [Start here](../learn-sensu): Building your first monitoring workflow

### Container monitoring
- [Container and application monitoring with Sensu](../sample-app): Monitoring a sample app on Kubernetes
- [Container and application monitoring with Sensu](../sample-app): Monitoring a Kubernetes sample app

### Metrics
- [Sensu + Prometheus](../prometheus-metrics): Collecting Prometheus metrics with Sensu

### Upgrading from Sensu 1.x to Sensu Go
- [Sensu translator](https://github.com/sensu/sandbox/tree/master/sensu-go/lesson_plans/check-upgrade): Translating check configuration
Loading

0 comments on commit eb093ff

Please sign in to comment.