Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
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
11 changes: 11 additions & 0 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type Conf struct {
ElasticHosts expr.ElasticHosts // CSV Elastic Hosts (All part of the same cluster), i.e http://ny-elastic01:9200. Only works with elastic v2+, and unlike logstash it is designed to be able to use various elastic schemas.
InfluxConfig client.Config

AnnotateElasticHosts []string // CSV of Elastic Hosts, currently the only backend in annotate
AnnotateIndex string // name of index / table

tree *parse.Tree
node parse.Node
unknownTemplate string
Expand Down Expand Up @@ -176,6 +179,10 @@ func (c *Conf) error(err error) {
c.errorf(err.Error())
}

func (c *Conf) AnnotateEnabled() bool {
return len(c.AnnotateElasticHosts) != 0
}

// errorf formats the error and terminates processing.
func (c *Conf) errorf(format string, args ...interface{}) {
if c.node == nil {
Expand Down Expand Up @@ -564,6 +571,10 @@ func (c *Conf) loadGlobal(p *parse.PairNode) {
c.error(err)
}
c.RedisDb = i
case "annotateElasticHosts":
c.AnnotateElasticHosts = strings.Split(v, ",")
case "annotationIndex":
c.AnnotateIndex = v
case "minGroupSize":
i, err := strconv.Atoi(v)
if err != nil {
Expand Down
31 changes: 29 additions & 2 deletions cmd/bosun/web/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
svg "github.com/ajstarks/svgo"
"github.com/bradfitz/slice"
"github.com/gorilla/mux"
"github.com/kylebrandt/annotate"
"github.com/vdobler/chart"
"github.com/vdobler/chart/svgg"
)
Expand Down Expand Up @@ -59,19 +60,36 @@ func Graph(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interf
}
queries := make([]string, len(oreq.Queries))
var start, end string
var startT, endT time.Time
if s, ok := oreq.Start.(string); ok && strings.Contains(s, "-ago") {
startT, err = opentsdb.ParseTime(s)
if err != nil {
return nil, err
}
start = strings.TrimSuffix(s, "-ago")
}
if s, ok := oreq.End.(string); ok && strings.Contains(s, "-ago") {
endT, err = opentsdb.ParseTime(s)
if err != nil {
return nil, err
}
end = strings.TrimSuffix(s, "-ago")
}
if start == "" && end == "" {
s, sok := oreq.Start.(int64)
e, eok := oreq.End.(int64)
if sok && eok {
start = fmt.Sprintf("%vs", e-s)
startT = time.Unix(s, 0)
endT = time.Unix(e, 0)
if err != nil {
return nil, err
}
}
}
if endT.Equal(time.Time{}) {
endT = time.Now().UTC()
}
m_units := make(map[string]string)
for i, q := range oreq.Queries {
if ar[i] {
Expand Down Expand Up @@ -163,12 +181,21 @@ func Graph(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interf
s.End()
return nil, nil
}
var a []annotate.Annotation
if schedule.Conf.AnnotateEnabled() {
a, err = annotateBackend.GetAnnotations(&startT, &endT, "", "", "", "", "")
if err != nil {
return nil, err
}
}
return struct {
Queries []string
Series []*chartSeries
Queries []string
Series []*chartSeries
Annotations []annotate.Annotation
}{
queries,
cs,
a,
}, nil
}

Expand Down
1,331 changes: 704 additions & 627 deletions cmd/bosun/web/static.go

Large diffs are not rendered by default.

69 changes: 65 additions & 4 deletions cmd/bosun/web/static/js/0-bosun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ bosunApp.config(['$routeProvider', '$locationProvider', '$httpProvider', functio
templateUrl: 'partials/graph.html',
controller: 'GraphCtrl',
resolve: {
'version' : function($http) {
'version': function($http) {
return $http({
method: 'GET',
url: '/api/opentsdb/version'
});
}
},
'annotateEnabled': function($http) {
return $http({
method: 'GET',
url: '/api/annotate'
});
},
}
}).
when('/host', {
Expand Down Expand Up @@ -227,7 +233,7 @@ bosunControllers.controller('BosunCtrl', ['$scope', '$route', '$http', '$q', '$r
.attr('height', sz)
.attr('width', sz);
svg.selectAll('rect.bg')
.data([[0, light], [sz/2, dark]])
.data([[0, light], [sz / 2, dark]])
.enter()
.append('rect')
.attr('class', 'bg')
Expand Down Expand Up @@ -300,7 +306,7 @@ bosunControllers.controller('BosunCtrl', ['$scope', '$route', '$http', '$q', '$r
animateCount--;
}
};
var short: any= $('#shortlink')[0];
var short: any = $('#shortlink')[0];
$scope.shorten = () => {
$http.get('/api/shorten').success((data: any) => {
if (data.id) {
Expand Down Expand Up @@ -386,6 +392,22 @@ function setUser(name) {
createCookie('action-user', name, 1000);
}

function getOwner() {
return readCookie('action-owner');
}

function setOwner(name) {
createCookie('action-owner', name, 1000);
}

function getShowAnnotations() {
return readCookie('annotations-show');
}

function setShowAnnotations(yes) {
createCookie('annotations-show', yes, 1000);
}

// from: http://stackoverflow.com/a/15267754/864236

bosunApp.filter('reverse', function() {
Expand All @@ -396,3 +418,42 @@ bosunApp.filter('reverse', function() {
return items.slice().reverse();
};
});

var timeFormat = 'YYYY-MM-DDTHH:mm:ssZ';

class Annotation {
Id: string;
Message: string;
StartDate: string; // RFC3999
EndDate: string; // RFC3999
CreationUser: string;
Url: string;
Source: string;
Host: string;
Owner: string;
Category: string;

constructor(a?) {
a = a || {};
this.Id = a.Id || "";
this.Message = a.Message || "";
this.StartDate = a.StartDate || "";
this.EndDate = a.EndDate || "";
this.CreationUser = a.CreationUser || getUser() || "";
this.Url = a.Url || "";
this.Source = a.Source || "bosun-ui";
this.Host = a.Host || "";
this.Owner = a.Owner || getOwner() || "";
this.Category = a.Category || "";
}
setTimeUTC() {
var now = moment().utc().format(timeFormat)
this.StartDate = now;
this.EndDate = now;
}
setTime() {
var now = moment().format(timeFormat)
this.StartDate = now;
this.EndDate = now;
}
}
Loading