Skip to content

[WIP] Add/exporters #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb250d1
Added different config templates for exporters.
SCHKN May 2, 2019
cd3eeac
Added the exporter option to the create command.
SCHKN May 2, 2019
cc57643
Moved the watchme template base file to the templates folder.
SCHKN May 2, 2019
f7ea250
Added a regex option when performing a get_task
SCHKN May 4, 2019
88329c7
First round of changes to add exporters
SCHKN May 5, 2019
a9755e2
Infering exporter instance given its declared type
SCHKN May 5, 2019
a2d724f
Helper function to retrieve the exporter type
SCHKN May 5, 2019
5d9168e
Removed exporter specific function from task classes
SCHKN May 5, 2019
8a8d155
Handling multiple export format in the exporter
SCHKN May 5, 2019
cce9297
Catching exceptions thrown when exporters are not available.
SCHKN May 5, 2019
1d4b890
Handling regex on get_url_selection + error message when exporter doe…
SCHKN May 5, 2019
c90015f
merge conflict
vsoch May 6, 2019
3a08ca4
initial bulk changes working on exporter
vsoch May 6, 2019
434e562
first round of work to add exporters (nothing is tested yet!)
vsoch May 6, 2019
67f5221
tweaks in setup.py (still not tested)
vsoch May 6, 2019
0b47358
config directory does not have templates subfolder
vsoch May 6, 2019
a1b1bbd
adding bulk of new work for exporters, need to write push function an…
vsoch May 7, 2019
c180c0c
add dummy push function, need to think about it
vsoch May 7, 2019
dbd68bd
adding push
vsoch May 7, 2019
dd89f29
resolving merge conflicts
vsoch May 8, 2019
3494d12
seems to be a circle blip
vsoch May 8, 2019
4618b35
Merge branch 'master' into add/exporters
vsoch May 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install_python_3: &install_python_3
fi

install_python_2: &install_python_2
name: install Python 3.5 dependencies
name: install Python 2 dependencies
command: |
ls $HOME
if [ ! -d "/home/circleci/conda" ]; then
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Critical items to know are:
- changed behaviour

## [master](https://github.com/vsoch/watchme/tree/master)
- Addition of exporters (0.0.17)
- Adding option for regular expression for URL wachers, user agent header (0.0.16)
- requests is missing from install dependencies (0.0.15)
- small bug fixes (0.0.14)
Expand Down
2 changes: 2 additions & 0 deletions docs/_data/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ navigation:
url: watchers/
- name: Examples
url: examples/
- name: Exporters
url: exporters/
- name: Contributing
url: contributing/
115 changes: 115 additions & 0 deletions docs/_docs/exporters/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: WatchMe Exporters
category: Exporters
permalink: /exporters/index.html
order: 1
---

Once you've followed the [getting started]({{ site.baseurl }}/getting-started/)
guide to [install]({{ site.baseurl }}/install/) watchme and have created your first
set of watchers, you might want to do more! Specifically, you can add
extra exporters to push your data to custom locations. The following exporters
are available:

- [pushgateway]({{ site.baseurl }}/exporters/pushgateway/) to push data to a Prometheus gateway.

And instructions for using a general exporter, either in sync with running a task
or separately, are provided below.


## List Exporters

To see exporters available, you can list them:

```bash
$ watchme list --exporters
watchme: exporters
pushgateway
```

An exporter is like a task in that it can be activated
(or not), and you can define more than one for any particular watcher.

## Add an Exporter

The most basic thing to do is to add an exporter to a watcher. You should
read the documentation for your exporter of interest (linked above) to
know the required parameters for the exporter (it varies).
Adding an exporter is similar to adding a task! The command asks you to
name the exporter, and the watcher to which you are adding it:

```bash
$ watchme add-exporter <watcher> <exporter>
```

Most likely the exporter requires parameters, so you add these in the same way
you added parameters to a task. Notice that "type" is essential to designate the
type that you want (the list at the top of the page):

```bash
$ watchme add-exporter <watcher> exporter-<name> param@value type@<exporter_type>
```

If you already have tasks defined that you want the exporter added to, just add them to the command:

```bash
$ watchme add-exporter <watcher> exporter-<name> param@value type@<exporter_type> <tasks>
```

If you've already added the exporter to the watcher and want to add it to a task:

```bash
$ watchme add-exporter <watcher> <exporter> <task>
```

Watchme will know that you aren't adding a new exporter (but instead using
an existing one) because you haven't provided a `type@<exporter_type>`
variable. If you want to re-create an exporter that already exists, you
can issue the same command but you'll need `--force`.

```bash
$ watchme add-exporter <watcher> exporter-<name> param@value type@<exporter_type> --force
```

## Remove an Exporter

If you change your mind, you can remove an exporter from a watcher entirely:

```bash
$ watchme remove <watcher> <exporter>
```

You can also remove it from a specific task (but not from the watcher entirely)

```bash
$ watchme remove <watcher> <exporter> <task>
```


## Run the Exporter

By default, an exporter will run with a task. This means that you should
run the task to run the exporter. If the watcher is active, and the task
is active, and the exporter is defined for the task, it will run.

```bash
$ watchme activate <watcher>
$ watchme run <watcher> <task>
```

If an exporter doesn't run successfully, it will be disabled for the task.
This is in case you forget about it.


## Push Manually

Optionally, you can choose to push data to an exporter manually.
This will ignore if the exporter is active, and only check that it's
defined for the task and is valid.

```bash
$ watchme push <watcher> <exporter> <task> <filename>
```

If you want to customize how the export works (e.g., what commits)
then you can use the python functions directly.
Binary file added docs/_docs/exporters/pushgateway/pushed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
243 changes: 243 additions & 0 deletions docs/_docs/exporters/pushgateway/pushgateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
---
title: Pushgateway
category: Exporters
permalink: /exporters/pushgateway/
order: 2
---

The [pushgateway](https://github.com/prometheus/pushgateway) exporter
will allow you to export data for a watcher to a Prometheus gateway.
To install the exporter, you will need to install its dependencies:

```bash
pip install watchme[exporter-pushgateway]
```

The dependencies include the [prometheus client](https://github.com/prometheus/client_python).

<br>

## Quick Start

Setup a gateway

```bash
$ docker run -d -p 9091:9091 prom/pushgateway
```

Create and add the exporter to an existing task. The only required parameter is the
url for the gateway (above we use http://localhost:9091).

```bash
$ watchme add-exporter <watcher> exporter-pushgateway url@http://localhost:9091 type@pushgateway task-<task>
```

<br>

## Detailed Start

### 1. Setup a Gateway

To set up a gateway, you can find full instructions (section "Run It")
at [https://github.com/prometheus/pushgateway](https://github.com/prometheus/pushgateway).
A brief summary using Docker is provided here. First, bring up the gateway:

```bash
$ docker run -d -p 9091:9091 prom/pushgateway
```

The image will pull and run, exposing the gateway on port 9091. First use
`docker ps` to ensure that it's running without issue:

```bash
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd6e3d3fb8db prom/pushgateway "/bin/pushgateway" 7 seconds ago Up 6 seconds 0.0.0.0:9091->9091/tcp gifted_merkle
```

Then, open your browser to [http://localhost:9091/](http://localhost:9091/). You should
see an empty portal.

![pushgateway.png]({{ site.url }}{{ site.baseurl }}/exporters/pushgateway/pushgateway.png)

It's a fairly boring interface, but that's okay - we will fix it up when we push data to it!


### 2. Create a Watcher

Next, let's create a watcher that will collect the data that we want to push to the
exporter. Imagine that we are interested in monitoring the temperate for a region.
Let's call the watcher "weather-watcher"

```bash
$ watchme create temp-watcher
Adding watcher /home/vanessa/.watchme/temp-watcher...
Generating watcher config /home/vanessa/.watchme/temp-watcher/watchme.cfg
```

This is an empty watcher in that there aren't any tasks to run.

### 3. Create a Task
Let's create a task to get the temperature for Luxembourg.

```bash
$ watchme add-task temp-watcher task-luxembourg url@https://www.accuweather.com/en/lu/luxembourg/228714/weather-forecast/228714 [email protected] get_text@true func@get_url_selection type@urls regex@[0-9]+

[task-luxembourg]
url = https://www.accuweather.com/en/lu/luxembourg/228714/weather-forecast/228714
selection = .local-temp
get_text = true
func = get_url_selection
regex = [0-9]+
active = true
type = urls
```

Above, we create a task called "task-luxembourg" that will go to the URL with the weather,
select the class ".local-temp" on the page, get the text for the class, and filter to the regular expression
for one or more numbers (`[0-9]+`). If you are interested in these details, see the
[urls watcher tasks]({{ site.url }}/watchers/urls/).

#### Test the task

We haven't scheduled it to run, but we might try testing it out to make sure
that it runs as we expect.

```bash
$ watchme run temp-watcher task-luxembourg --test
Found 1 contender tasks.
[1/1] |===================================| 100.0%
{
"task-luxembourg": [
"54"
]
}
```

The `--test` flag will ensure that the data is not saved and written to git.
The above worked great, because we see that the temperature is 54.

### 4. Add an Exporter

Let's now add an exporter. An exporter is like a task in that it can be activated
(or not), and you can define more than one for any particular watcher.
If you want to see the exporters available:

```bash
$ watchme list --exporters
watchme: exporters
pushgateway
```

Adding an exporter is similar to adding a task! The command asks you to
name the exporter, and the watcher to which you are adding it:

```bash
$ watchme add-exporter <watcher> <exporter>
```

And you can follow these labels by any parameters required for the exporter.
For the pushgateway exporter, along with specifying the type,
you are only required one parameter (url) that must start with http.


```bash
$ watchme add-exporter temp-watcher exporter-pushgateway url@http://localhost:9091 type@pushgateway
```

Along with seeing it on the screen, you can inspect the watcher to see that
the exporter is added:

```bash
$ watchme inspect temp-watcher
[watcher]
active = false
type = urls

[task-luxembourg]
url = https://www.accuweather.com/en/lu/luxembourg/228714/weather-forecast/228714
selection = .local-temp
get_text = true
func = get_url_selection
regex = [0-9]+
active = true
type = urls

[exporter-pushgateway]
url = http://localhost:9091
active = true
type = pushgateway
```

But notice how the exporter isn't added to the task? We can add it manually:

```bash
# watchme add-exporter <watcher> <exporter> <task>
$ watchme add-exporter temp-watcher exporter-pushgateway task-luxembourg
```

Or you could have added it when you first created the exporter. Let's show you
the command to remove the exporter:

```bash
$ watchme remove temp-watcher exporter-pushgateway
Removing exporter-pushgateway from task-luxembourg
exporter-pushgateway removed successfully.
```

And then add it again, not only to the watcher but also to the task, with one command!

```bash
$ watchme add-exporter temp-watcher exporter-pushgateway url@http://localhost:9091 type@pushgateway task-luxembourg
[exporter-pushgateway]
url = http://localhost:9091
active = true
type = pushgateway
```

You can then inspect the watcher to see the full addition (note that "exporter-pushgateway" is added
to exporters for task-luxembourg:

```bash
vanessa@vanessa-ThinkPad-T460s:~/Documents/Dropbox/Code/Python/watchme$ watchme inspect temp-watcher[watcher]
active = false
type = urls

[task-luxembourg]
url = https://www.accuweather.com/en/lu/luxembourg/228714/weather-forecast/228714
selection = .local-temp
get_text = true
func = get_url_selection
regex = [0-9]+
active = true
type = urls
exporters = exporter-pushgateway

[exporter-pushgateway]
url = http://localhost:9091
active = true
type = pushgateway
```

### 5. Run the Exporter

We can see that pushgateway is active, so when we run the task, it should push
data there. To do it fully, we need to activate the watcher:

```bash
$ watchme activate temp-watcher
[watcher|temp-watcher] active: true
```

And then run the task.

```bash
$ watchme run temp-watcher task-luxembourg
Exporting list to exporter-pushgateway
```

If all goes well, you can return to the web interface and see your data added!

![pushed.png]({{ site.url }}{{ site.baseurl }}/exporters/pushgateway/pushed.png)

Great job! You can learn more about the use cases for [push gateway here](https://prometheus.io/docs/practices/pushing/).
Binary file added docs/_docs/exporters/pushgateway/pushgateway.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading