Skip to content

Commit

Permalink
Release v2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Dec 4, 2023
1 parent fc8f6fc commit c75b3f2
Show file tree
Hide file tree
Showing 6 changed files with 892 additions and 583 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### Changelog

next:
2.0.4 2023-12-04
- remove time filter restriction
- update grafana toolkit to 10.1.5

2.0.3 2023-07-14
- make drag/drop more obvious
Expand Down
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ DOCKER=docker run \
-w "/src" \
-u $(shell id -u):$(shell id -g) \
-e "HOME=/src" \
-e "GRAFANA_API_KEY=$(GRAFANA_API_KEY)"
NODEVERSION=16
-e "GRAFANA_ACCESS_POLICY_TOKEN=$(GRAFANA_API_KEY)"
NODEVERSION=20
export NODE_PATH=$(shell pwd)/node_modules
YARN=yarn

Expand All @@ -25,7 +25,7 @@ buildaudit:
$(DOCKER) --name $(PLUGINNAME)-buildupgrade node:$(NODEVERSION) bash -c "$(YARN) install && $(YARN) audit"

buildsign:
$(DOCKER) --name $(PLUGINNAME)-buildsign node:$(NODEVERSION) npx --legacy-peer-deps @grafana/toolkit plugin:sign
$(DOCKER) --name $(PLUGINNAME)-buildsign node:$(NODEVERSION) bash -c "$(YARN) install && npx @grafana/sign-plugin"

prettier:
$(DOCKER) --name $(PLUGINNAME)-buildpret node:$(NODEVERSION) npx prettier --write --ignore-unknown src/
Expand All @@ -43,15 +43,20 @@ dev:

clean:
-docker compose rm -f
-sudo chown $(shell id -u):$(shell id -g) -R dist node_modules
rm -rf dist
rm -rf node_modules
rm -rf .yarnrc
rm -rf .npm

releasebuild:
@if [ "x$(TAGVERSION)" = "x" ]; then echo "ERROR: must be on a git tag, got: $(shell git describe --tag --dirty)"; exit 1; fi
make clean
make GRAFANA_API_KEY=$(GRAFANA_API_KEY) build buildsign
$(MAKE) clean
$(MAKE) build
$(MAKE) GRAFANA_ACCESS_POLICY_TOKEN=$(GRAFANA_API_KEY) buildsign
mv dist/ $(PLUGINNAME)
rm -f $(PLUGINNAME)-$(TAGVERSION).zip
zip $(PLUGINNAME)-$(TAGVERSION).zip $(PLUGINNAME) -r
rm -rf $(PLUGINNAME)
@echo "release build successful: $(TAGVERSION)"
ls -la $(PLUGINNAME)-$(TAGVERSION).zip
74 changes: 31 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
## Thruk Grafana Datasource - a Grafana backend datasource using Thruks REST API

# Thruk Grafana Datasource - a Grafana backend datasource using Thruks REST API

![Thruk Grafana Datasource](https://raw.githubusercontent.com/sni/grafana-thruk-datasource/master/src/img/screenshot.png "Thruk Grafana Datasource")


### Installation
## Installation

Search for `thruk` in the Grafana plugins directory or simply use the grafana-cli command:

Expand All @@ -21,33 +19,32 @@ Otherwise follow these steps:

Replace `release-1.0.4` with the last available release branch.

### Create Datasource
## Create Datasource

Add a new datasource and select:

Use the Grafana proxy.

- Type 'Thruk'
- Url to Thruk, ex.: 'https://localhost/sitename/thruk'
- Type 'Thruk'
- Url to Thruk, ex.: 'https://localhost/sitename/thruk'

## Table Queries

### Table Queries
Using the table panel, you can display most data from the rest api. However
only text, numbers and timestamps can be displayed in a sane way. Support for nested
data structures is limited.

Select the rest path from where you want to display data. Then choose all columns. Aggregation
functions can be added as well and always affect the column following afterwards.

### Variable Queries
## Variable Queries

Thruks rest api can be used to fill grafana variables. For example to get all
hosts of a certain hostgroup, use this example query:

```
SELECT name FROM hosts WHERE groups >= 'linux'
```
SELECT name FROM hosts WHERE groups >= 'linux'

### Annotation Queries
## Annotation Queries

Annotation queries can be used to add logfile entries into your graphs.
Please note that annotations are shared across all graphs in a dashboard.
Expand All @@ -56,40 +53,37 @@ It is important to use at least a time filter.

![Annotations](https://raw.githubusercontent.com/sni/grafana-thruk-datasource/master/src/img/annotations.png "Annotations Editor")

### Single Stat Queries
## Single Stat Queries

Single stats are best used with REST endpoints which return aggregated values
already or use aggregation functions like, `avg`, `sum`, `min`, `max` or `count`.

### Timeseries based panels
## Timeseries based panels

Althouth Thruk isn't a timeseries databases und usually only returns table
data, some queries can be converted to fake timeseries if the panel cannot
handle table data.

You can either use queries which have 2 columns (name, value) or queries
which only return a single result row with numeric values only.

#### Statistic Data Pie Chart
### Statistic Data Pie Chart

For example the pie chart plugin can be used with stats queries like this:

```
SELECT count() state, state FROM /hosts
```
SELECT count() state, state FROM /hosts

The query is expected to fetch 2 columns. The first is the value, the second is the name.


#### Single Host Pie Chart
### Single Host Pie Chart

Ex.: Use statistics data for a single host to put it into a pie chart:

```
SELECT num_services_ok, num_services_warn, num_services_crit, num_services_unknown FROM /hosts WHERE name = '$name' LIMIT 1
```
SELECT num_services_ok, num_services_warn, num_services_crit, num_services_unknown FROM /hosts WHERE name = '$name' LIMIT 1

![Pie Chart](https://raw.githubusercontent.com/sni/grafana-thruk-datasource/master/src/img/piechart.png "Pie Chart")

### Using Variables
## Using Variables

Dashboard variables can be used in almost all queries. For example if you
define a dashboard variable named `host` you can then use `$host` in your
Expand All @@ -99,20 +93,15 @@ There is a special syntax for time filter: `field = $time` which will be
replaced by `(field >= starttime AND field <= endtime)`. This can be used to
reduce results to the dashboards timeframe.

```
SELECT time, message FROM /hosts/$host/alerts WHERE time = $time
```
SELECT time, message FROM /hosts/$host/alerts WHERE time = $time

which is the same as

```
SELECT time, message FROM /alerts WHERE host_name = "$host" AND time = $time
```
SELECT time, message FROM /alerts WHERE host_name = "$host" AND time = $time

![Variables](https://raw.githubusercontent.com/sni/grafana-thruk-datasource/master/src/img/variables.png "Variables Editor")


### Development
## Development

To test and improve the plugin you can run Grafana instance in Docker using
following command (in the source directory of this plugin):
Expand All @@ -122,19 +111,19 @@ following command (in the source directory of this plugin):
This will start a grafana container and a build watcher which updates the
plugin is the dist/ folder.

The dev instance can be accessed at http://localhost:3000
The dev instance can be accessed at `http://localhost:3000``

You need to add the datasource manually.
Note: You need to add the datasource manually and you need to run "make build" once
before starting the dev container, otherwise Grafana won't find the datasource.


#### Testing
### Testing

For testing you can use the demo Thruk instance at:

- URL: https://demo.thruk.org/demo/thruk/
- Basic Auth: test / test
- URL: https://demo.thruk.org/demo/thruk/
- Basic Auth: test / test

#### Create Release
### Create Release

How to create a new release:

Expand All @@ -144,11 +133,10 @@ How to create a new release:
%> vi CHANGELOG.md # add changelog entry
%> git commit -am "Release v${RELVERSION}"
%> git tag -a v${RELVERSION} -m "Create release tag v${RELVERSION}"
%> make GRAFANA_API_KEY=${GRAFANA_API_KEY} clean releasebuild
%> make GRAFANA_API_KEY=${GRAFANA_API_KEY} releasebuild
# create release here https://github.com/sni/grafana-thruk-datasource/releases/new
# submit plugin update here https://grafana.com/orgs/sni/plugins


### Changelog
## Changelog

see CHANGELOG.md
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
context: ./.config
args:
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
grafana_version: ${GRAFANA_VERSION:-9.5.3}
grafana_version: ${GRAFANA_VERSION:-10.2.2}
ports:
- 3000:3000/tcp
volumes:
Expand All @@ -16,7 +16,7 @@ services:
environment:
- GF_USERS_DEFAULT_THEME=light
buildwatch:
image: node:16
image: node:20
command: bash -c "yarn install && yarn run dev"
working_dir: /src
volumes:
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-thruk-datasource",
"version": "2.0.3",
"version": "2.0.4",
"description": "grafana thruk datasource",
"author": "Sven Nierlein",
"license": "MIT",
Expand Down Expand Up @@ -62,9 +62,10 @@
},
"dependencies": {
"@emotion/css": "^11.1.3",
"@grafana/data": "^10.0.2",
"@grafana/runtime": "^10.0.2",
"@grafana/ui": "^10.0.2",
"@grafana/data": "^10.1.5",
"@grafana/runtime": "^10.1.5",
"@grafana/ui": "^10.1.5",
"@grafana/sign-plugin": "^2.2.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"tslib": "2.5.3"
Expand Down
Loading

0 comments on commit c75b3f2

Please sign in to comment.