Skip to content

Commit 6881db8

Browse files
committed
Merge branch 'alerting' into thresholds_v3
2 parents fbb8f8e + 8878a55 commit 6881db8

File tree

9 files changed

+132
-19
lines changed

9 files changed

+132
-19
lines changed

docs/sources/installation/mac.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,17 @@ brew update
2424
brew reinstall grafana
2525
```
2626

27+
-------------
2728

29+
You can also install the latest unstable grafana from git:
30+
31+
32+
```
33+
brew install --HEAD grafana/grafana/grafana
34+
```
35+
36+
To upgrade grafana if you've installed from HEAD:
37+
38+
```
39+
brew reinstall --HEAD grafana/grafana/grafana
40+
```

docs/sources/plugins/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ page_keywords: grafana, plugins, documentation
99
The easiest way to install plugins is by using the CLI tool grafana-cli which is bundled with grafana. Before any modification take place after modifying plugins, grafana-server needs to be restarted.
1010

1111
### Grafana plugin directory
12-
On Linux systems the grafana-cli will assume that the grafana plugin directory is `/var/lib/grafana/plugins`. It's possible to override the directory which grafana-cli will operate on by specifying the --path flag. On Windows systems this parameter have to be specified for every call.
12+
On Linux systems the grafana-cli will assume that the grafana plugin directory is `/var/lib/grafana/plugins`. It's possible to override the directory which grafana-cli will operate on by specifying the --pluginsDir flag. On Windows systems this parameter have to be specified for every call.
1313

1414
### Grafana-cli commands
1515

packaging/mac/bin/grafana

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
DAEMON=grafana-server
3+
EXECUTABLE=/usr/local/bin/grafana-server
4+
CONFIG=/usr/local/etc/grafana/grafana.ini
5+
HOMEPATH=/usr/local/share/grafana
6+
LOGPATH=/usr/local/var/log/grafana
7+
DATAPATH=/usr/local/var/lib/grafana
8+
PLUGINPATH=/usr/local/var/lib/grafana/plugins
9+
10+
case "$1" in
11+
start)
12+
$EXECUTABLE --config=$CONFIG --homepath=$HOMEPATH cfg:default.paths.logs=$LOGPATH cfg:default.paths.data=$DATAPATH cfg:default.paths.plugins=$PLUGINPATH 2> /dev/null &
13+
[ $? -eq 0 ] && echo "$DAEMON started"
14+
;;
15+
stop)
16+
killall $DAEMON
17+
[ $? -eq 0 ] && echo "$DAEMON stopped"
18+
;;
19+
restart)
20+
$0 stop
21+
$0 start
22+
;;
23+
*)
24+
echo "Usage: $0 (start|stop|restart)"
25+
;;
26+
esac

pkg/services/alerting/conditions/reducer.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) float64 {
1919
value += point[0]
2020
}
2121
value = value / float64(len(series.Points))
22+
case "sum":
23+
for _, point := range series.Points {
24+
value += point[0]
25+
}
26+
case "min":
27+
for i, point := range series.Points {
28+
if i == 0 {
29+
value = point[0]
30+
}
31+
32+
if value > point[0] {
33+
value = point[0]
34+
}
35+
}
36+
case "max":
37+
for _, point := range series.Points {
38+
if value < point[0] {
39+
value = point[0]
40+
}
41+
}
42+
case "mean":
43+
meanPosition := int64(len(series.Points) / 2)
44+
value = series.Points[meanPosition][0]
2245
}
2346

2447
return value
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package conditions
2+
3+
import (
4+
"testing"
5+
6+
"github.com/grafana/grafana/pkg/tsdb"
7+
. "github.com/smartystreets/goconvey/convey"
8+
)
9+
10+
func TestSimpleReducer(t *testing.T) {
11+
Convey("Test simple reducer by calculating", t, func() {
12+
Convey("avg", func() {
13+
result := testReducer("avg", 1, 2, 3)
14+
So(result, ShouldEqual, float64(2))
15+
})
16+
17+
Convey("sum", func() {
18+
result := testReducer("sum", 1, 2, 3)
19+
So(result, ShouldEqual, float64(6))
20+
})
21+
22+
Convey("min", func() {
23+
result := testReducer("min", 3, 2, 1)
24+
So(result, ShouldEqual, float64(1))
25+
})
26+
27+
Convey("max", func() {
28+
result := testReducer("max", 1, 2, 3)
29+
So(result, ShouldEqual, float64(3))
30+
})
31+
32+
Convey("mean odd numbers", func() {
33+
result := testReducer("mean", 1, 2, 3000)
34+
So(result, ShouldEqual, float64(2))
35+
})
36+
37+
})
38+
}
39+
40+
func testReducer(typ string, datapoints ...float64) float64 {
41+
reducer := NewSimpleReducer(typ)
42+
var timeserie [][2]float64
43+
dummieTimestamp := float64(521452145)
44+
45+
for _, v := range datapoints {
46+
timeserie = append(timeserie, [2]float64{v, dummieTimestamp})
47+
}
48+
49+
tsdb := &tsdb.TimeSeries{
50+
Name: "test time serie",
51+
Points: timeserie,
52+
}
53+
return reducer.Reduce(tsdb)
54+
}

pkg/services/alerting/evaluator.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

public/app/core/services/alert_srv.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@ export class AlertSrv {
2727
this.set(alert[0], alert[1], 'success', 3000);
2828
}, this.$rootScope);
2929

30+
appEvents.on('alert-error', options => {
31+
this.set(options[0], options[1], 'error', 7000);
32+
});
33+
3034
appEvents.on('confirm-modal', this.showConfirmModal.bind(this));
3135
}
3236

3337
set(title, text, severity, timeout) {
38+
if (_.isObject(text)) {
39+
console.log('alert error', text);
40+
if (text.statusText) {
41+
text = `HTTP Error (${text.status}) ${text.statusText}`;
42+
}
43+
}
44+
3445
var newAlert = {
3546
title: title || '',
3647
text: text || '',

public/app/features/dashboard/dashnav/dashnav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class DashNavCtrl {
209209
$scope.viewJson = function() {
210210
var clone = $scope.dashboard.getSaveModelClone();
211211
var html = angular.toJson(clone, true);
212-
var uri = "data:application/json," + encodeURIComponent(html);
212+
var uri = "data:application/json;charset=utf-8," + encodeURIComponent(html);
213213
var newWindow = window.open(uri);
214214
};
215215

public/app/plugins/datasource/graphite/query_ctrl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import moment from 'moment';
99
import gfunc from './gfunc';
1010
import {Parser} from './parser';
1111
import {QueryCtrl} from 'app/plugins/sdk';
12+
import appEvents from 'app/core/app_events';
1213

1314
export class GraphiteQueryCtrl extends QueryCtrl {
1415
static templateUrl = 'partials/query.editor.html';
@@ -141,7 +142,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
141142
}
142143
}
143144
}).catch(err => {
144-
this.error = err.message || 'Failed to issue metric query';
145+
appEvents.emit('alert-error', ['Error', err]);
145146
});
146147
}
147148

@@ -178,7 +179,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
178179
altSegments.unshift(this.uiSegmentSrv.newSegment('*'));
179180
return altSegments;
180181
}).catch(err => {
181-
this.error = err.message || 'Failed to issue metric query';
182+
appEvents.emit('alert-error', ['Error', err]);
182183
return [];
183184
});
184185
}

0 commit comments

Comments
 (0)