Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Grafana Redis Datasource
# Redis Data Source for Grafana

![Dashboard](https://raw.githubusercontent.com/RedisTimeSeries/grafana-redis-datasource/master/src/img/redis-dashboard.png)

Expand All @@ -21,33 +21,33 @@

## Introduction

### What is the Grafana Redis Datasource?
### What is the Redis Data Source for Grafana?

The Grafana Redis Datasource, is a plugin that allows users to connect to Redis database and build dashboards in Grafana to easily monitor Redis data. It provides out-of-the box predefined dashboards - but the plugin allows to build entirely customized dashboards, tuned to your needs.
If you’re not familiar with Grafana, it’s a very popular tool used to build dashboards to monitor applications, infrastructures, and software components. The Redis Data Source for Grafana is a plug-in that allows users to connect to the Redis database and build dashboards in Grafana to easily monitor Redis data. It provides an out-of-the-box predefined dashboard, but also lets you build customized dashboards tuned to your specific needs.

### What is Grafana?
### What Grafana version is supported?

If you are not familiar with Grafana yet, it is a very popular tool used to build dashboards allowing to monitor applications, infrastructures and any kind of software components.
Grafana 7.1 and later with a new plug-in platform supported.

### What Grafana version is supported?
### Does this Data Source require anything special configured on the Redis databases?

Only Grafana 7.0 and later with a new plugin platform supported.
Data Source can connect to any Redis database. No special configuration is required.

### Does this datasource require anything special configured on the Redis databases?
### Does this Data Source support [Redis Cluster](https://redis.io/topics/cluster-tutorial) and [Sentinel](https://redis.io/topics/sentinel)?

Datasource can connect to any Redis database. No special configuration is required.
Yes, Redis Cluster and Sentinel supported since version 1.2.

### How to connect to Redis logical database?

Please use `/db-number` or `?db=db-number` in the datasource URL to specify the database number as defined in the [Schema](https://www.iana.org/assignments/uri-schemes/prov/redis).
Please use `/db-number` or `?db=db-number` in the Data Source URL to specify the database number as defined in the [Schema](https://www.iana.org/assignments/uri-schemes/prov/redis).

```
redis://redis-server:6379/0
```

### Build datasource
### Build Data Source

To learn step by step how to build Redis Datasource from scratch and register in new or existing Grafana please take a look at [BUILD](https://github.com/RedisTimeSeries/grafana-redis-datasource/blob/master/BUILD.md) instructions.
To learn step by step how to build Redis Data Source from scratch and register in new or existing Grafana please take a look at [BUILD](https://github.com/RedisTimeSeries/grafana-redis-datasource/blob/master/BUILD.md) instructions.

## Getting Started

Expand All @@ -73,14 +73,14 @@ Project provides `docker-compose.yml` to start Redis with RedisTimeSeries module
docker-compose up
```

Open Grafana in your browser [http://localhost:3000](http://localhost:3000) and configure datasource. You can add as many datasources as you want to support multiple Redis databases.
Open Grafana in your browser [http://localhost:3000](http://localhost:3000) and configure Redis Data Source. You can add as many data sources as you want to support multiple Redis databases.

![Datasource](https://raw.githubusercontent.com/RedisTimeSeries/grafana-redis-datasource/master/src/img/datasource.png)

There are certain settings that can be configured based on your own setup:

- Grafana port
- Datasource URL
- Data Source URL

#### Configure Grafana port in `docker-compose.yml`

Expand All @@ -91,7 +91,7 @@ If standard port 3000 is occupied by another application update the port to bind
- '3000:3000'
```

#### Configure Datasource url in `provisioning/datasources/redis.yaml`
#### Configure Data Source URL in `provisioning/datasources/redis.yaml`

If Redis is running and listening on localhost:6379 no changes are required

Expand All @@ -107,15 +107,15 @@ If Redis is running as Docker container on MacOS, please update host to `host.do

### Run using `docker-compose` for development

Datasource have to be built following [BUILD](https://github.com/RedisTimeSeries/grafana-redis-datasource/blob/master/BUILD.md) instructions before starting using `docker-compose-dev.yml` file.
Data Source have to be built following [BUILD](https://github.com/RedisTimeSeries/grafana-redis-datasource/blob/master/BUILD.md) instructions before starting using `docker-compose-dev.yml` file.

```bash
docker-compose -f docker-compose-dev.yml up
```

## Supported Commands

Datasource supports many Redis commands using custom components and provide unified interface to query any command.
Data Source supports many Redis commands using custom components and provide unified interface to query any command.

![Query](https://raw.githubusercontent.com/RedisTimeSeries/grafana-redis-datasource/master/src/img/query.png)

Expand Down
13 changes: 10 additions & 3 deletions pkg/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ func newDataSourceInstance(setting backend.DataSourceInstanceSettings) (instance
}

// Certificate and Key
cert, err := tls.X509KeyPair([]byte(secureData["tlsClientCert"]), []byte(secureData["tlsClientKey"]))
if err == nil {
tlsConfig.Certificates = []tls.Certificate{cert}
if secureData["tlsClientCert"] != "" {
cert, err := tls.X509KeyPair([]byte(secureData["tlsClientCert"]), []byte(secureData["tlsClientKey"]))
if err == nil {
tlsConfig.Certificates = []tls.Certificate{cert}
} else {
log.DefaultLogger.Error("X509KeyPair", "Error", err)
return nil, err
}
}

// Add TLS Config
Expand All @@ -200,6 +205,8 @@ func newDataSourceInstance(setting backend.DataSourceInstanceSettings) (instance
switch jsonData.Client {
case "cluster":
client, err = radix.NewCluster(strings.Split(setting.URL, ","), radix.ClusterPoolFunc(poolFunc))
case "sentinel":
client, err = radix.NewSentinel(jsonData.SentinelName, strings.Split(setting.URL, ","), radix.SentinelPoolFunc(poolFunc))
default:
client, err = poolFunc("tcp", setting.URL)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type dataModel struct {
TLSAuth bool `json:"tlsAuth"`
TLSSkipVerify bool `json:"tlsSkipVerify"`
Client string `json:"client"`
SentinelName string `json:"sentinelName"`
}

/*
Expand Down
21 changes: 18 additions & 3 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent, PureComponent } from 'react';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { Button, InlineFormLabel, LegacyForms, RadioButtonGroup, TextArea } from '@grafana/ui';
import { ClientTypeValue, ClientType, RedisDataSourceOptions, RedisSecureJsonData } from '../types';
import { ClientType, ClientTypeValue, RedisDataSourceOptions, RedisSecureJsonData } from '../types';

/**
* Form Field
Expand Down Expand Up @@ -198,6 +198,21 @@ export class ConfigEditor extends PureComponent<Props, State> {
/>
</div>

{jsonData.client === ClientTypeValue.SENTINEL && (
<div className="gf-form">
<FormField
label="Master Name"
labelWidth={10}
inputWidth={10}
value={jsonData.sentinelName}
tooltip="Provide Master Name to connect to."
onChange={(event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({ ...options, jsonData: { ...options.jsonData, sentinelName: event.target.value } });
}}
/>
</div>
)}

<div className="gf-form">
<FormField
label="URL"
Expand All @@ -206,7 +221,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
onChange={this.onURLChange}
value={url || ''}
tooltip="Accepts host:port address or a URI, as defined in https://www.iana.org/assignments/uri-schemes/prov/redis.
For Redis Cluster can contain multiple values with comma."
For Redis Cluster and Sentinel can contain multiple values with comma."
placeholder="redis://..."
/>
</div>
Expand All @@ -219,7 +234,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
placeholder="Database password"
labelWidth={10}
inputWidth={20}
tooltip="When specified AUTH command will be used to authenticate with the provided password"
tooltip="When specified AUTH command will be used to authenticate with the provided password."
onReset={this.onResetPassword}
onChange={this.onPasswordChange}
/>
Expand Down
Binary file modified src/img/datasource.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/img/redis-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ export interface RedisDataSourceOptions extends DataSourceJsonData {
/**
* Client Type
*
* @type {string}
* @type {ClientTypeValue}
*/
client: ClientTypeValue;

/**
* Sentinel Master group name
*
* @type {string}
*/
sentinelName: string;
}

/**
Expand Down Expand Up @@ -101,6 +108,6 @@ export enum ClientTypeValue {
*/
export const ClientType = [
{ label: 'Redis Cluster', value: ClientTypeValue.CLUSTER },
// { label: 'Sentinel', value: ClientTypeValue.SENTINEL },
{ label: 'Sentinel', value: ClientTypeValue.SENTINEL },
{ label: 'Standalone', value: ClientTypeValue.STANDALONE },
];