Commit 09cb0f37 by bergquist

dashboards as cfg: minor tweaks

parent 93e1d8a1
...@@ -20,10 +20,11 @@ func Provision(ctx context.Context, configDirectory string) (*DashboardProvision ...@@ -20,10 +20,11 @@ func Provision(ctx context.Context, configDirectory string) (*DashboardProvision
ctx: ctx, ctx: ctx,
} }
return d, d.Init(ctx) err := d.Provision(ctx)
return d, err
} }
func (provider *DashboardProvisioner) Init(ctx context.Context) error { func (provider *DashboardProvisioner) Provision(ctx context.Context) error {
cfgs, err := provider.cfgReader.readConfig() cfgs, err := provider.cfgReader.readConfig()
if err != nil { if err != nil {
return err return err
......
...@@ -42,7 +42,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade ...@@ -42,7 +42,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
} }
func (fr *fileReader) ReadAndListen(ctx context.Context) error { func (fr *fileReader) ReadAndListen(ctx context.Context) error {
ticker := time.NewTicker(time.Second * 10) ticker := time.NewTicker(time.Second * 5)
if err := fr.walkFolder(); err != nil { if err := fr.walkFolder(); err != nil {
fr.log.Error("failed to search for dashboards", "error", err) fr.log.Error("failed to search for dashboards", "error", err)
...@@ -105,11 +105,10 @@ func (fr *fileReader) walkFolder() error { ...@@ -105,11 +105,10 @@ func (fr *fileReader) walkFolder() error {
} }
if cmd.Result.Updated.Unix() >= f.ModTime().Unix() { if cmd.Result.Updated.Unix() >= f.ModTime().Unix() {
fr.log.Debug("already using latest version", "dashboard", dash.Dashboard.Slug)
return nil return nil
} }
fr.log.Debug("no dashboard in cache. Loading dashboard from disk into database.", "file", path) fr.log.Debug("no dashboard in cache. loading dashboard from disk into database.", "file", path)
return fr.saveDashboard(dash) return fr.saveDashboard(dash)
}) })
} }
...@@ -141,16 +140,16 @@ func (fr *fileReader) readDashboardFromFile(path string) (*DashboardJson, error) ...@@ -141,16 +140,16 @@ func (fr *fileReader) readDashboardFromFile(path string) (*DashboardJson, error)
return dash, nil return dash, nil
} }
func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { func (fr *fileReader) saveDashboard(json *DashboardJson) error {
dash := dashboardJson.Dashboard dashboard := json.Dashboard
if dash.Title == "" { if dashboard.Title == "" {
return models.ErrDashboardTitleEmpty return models.ErrDashboardTitleEmpty
} }
validateAlertsCmd := alerting.ValidateDashboardAlertsCommand{ validateAlertsCmd := alerting.ValidateDashboardAlertsCommand{
OrgId: dashboardJson.OrgId, OrgId: json.OrgId,
Dashboard: dash, Dashboard: dashboard,
} }
if err := bus.Dispatch(&validateAlertsCmd); err != nil { if err := bus.Dispatch(&validateAlertsCmd); err != nil {
...@@ -158,11 +157,11 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { ...@@ -158,11 +157,11 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error {
} }
cmd := models.SaveDashboardCommand{ cmd := models.SaveDashboardCommand{
Dashboard: dash.Data, Dashboard: dashboard.Data,
Message: "Dashboard created from file.", Message: "Dashboard created from file.",
OrgId: dashboardJson.OrgId, OrgId: json.OrgId,
Overwrite: true, Overwrite: true,
UpdatedAt: dashboardJson.ModTime, UpdatedAt: json.ModTime,
} }
err := bus.Dispatch(&cmd) err := bus.Dispatch(&cmd)
...@@ -171,7 +170,7 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { ...@@ -171,7 +170,7 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error {
} }
alertCmd := alerting.UpdateDashboardAlertsCommand{ alertCmd := alerting.UpdateDashboardAlertsCommand{
OrgId: dashboardJson.OrgId, OrgId: json.OrgId,
Dashboard: cmd.Result, Dashboard: cmd.Result,
} }
......
[] []
{ {
"title": "Grafana", "title": "Grafana",
"tags": [],
"style": "dark",
"timezone": "browser",
"editable": true,
"rows": [
{
"title": "New row",
"height": "150px",
"collapse": false,
"editable": true,
"panels": [
{
"id": 1,
"span": 12,
"editable": true,
"type": "text",
"mode": "html",
"content": "<div class=\"text-center\" style=\"padding-top: 15px\">\n<img src=\"img/logo_transparent_200x.png\"> \n</div>",
"style": {},
"title": "Welcome to"
}
]
},
{
"title": "Welcome to Grafana",
"height": "210px",
"collapse": false,
"editable": true,
"panels": [
{
"id": 2,
"span": 6,
"type": "text",
"mode": "html",
"content": "<br/>\n\n<div class=\"row-fluid\">\n <div class=\"span6\">\n <ul>\n <li>\n <a href=\"http://grafana.org/docs#configuration\" target=\"_blank\">Configuration</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/troubleshooting\" target=\"_blank\">Troubleshooting</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/support\" target=\"_blank\">Support</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/features/intro\" target=\"_blank\">Getting started</a> (Must read!)\n </li>\n </ul>\n </div>\n <div class=\"span6\">\n <ul>\n <li>\n <a href=\"http://grafana.org/docs/features/graphing\" target=\"_blank\">Graphing</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/features/annotations\" target=\"_blank\">Annotations</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/features/graphite\" target=\"_blank\">Graphite</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/features/influxdb\" target=\"_blank\">InfluxDB</a>\n </li>\n <li>\n <a href=\"http://grafana.org/docs/features/opentsdb\" target=\"_blank\">OpenTSDB</a>\n </li>\n </ul>\n </div>\n</div>",
"style": {},
"title": "Documentation Links"
},
{
"id": 3,
"span": 6,
"type": "text",
"mode": "html",
"content": "<br/>\n\n<div class=\"row-fluid\">\n <div class=\"span12\">\n <ul>\n <li>Ctrl+S saves the current dashboard</li>\n <li>Ctrl+F Opens the dashboard finder</li>\n <li>Ctrl+H Hide/show row controls</li>\n <li>Click and drag graph title to move panel</li>\n <li>Hit Escape to exit graph when in fullscreen or edit mode</li>\n <li>Click the colored icon in the legend to change series color</li>\n <li>Ctrl or Shift + Click legend name to hide other series</li>\n </ul>\n </div>\n</div>\n",
"style": {},
"title": "Tips & Shortcuts"
}
]
},
{
"title": "test",
"height": "250px",
"editable": true,
"collapse": false,
"panels": [
{
"id": 4,
"span": 12,
"type": "graph",
"x-axis": true,
"y-axis": true,
"scale": 1,
"y_formats": [
"short",
"short"
],
"grid": {
"max": null,
"min": null,
"leftMax": null,
"rightMax": null,
"leftMin": null,
"rightMin": null,
"threshold1": null,
"threshold2": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"resolution": 100,
"lines": true,
"fill": 1,
"linewidth": 2,
"dashes": false,
"dashLength": 10,
"spaceLength": 10,
"points": false,
"pointradius": 5,
"bars": false,
"stack": true,
"spyable": true,
"options": false,
"legend": {
"show": true,
"values": false,
"min": false,
"max": false,
"current": false,
"total": false,
"avg": false
},
"interactive": true,
"legend_counts": true,
"timezone": "browser",
"percentage": false,
"nullPointMode": "connected",
"steppedLine": false,
"tooltip": {
"value_type": "cumulative",
"query_as_alias": true
},
"targets": [
{
"target": "randomWalk('random walk')",
"function": "mean",
"column": "value"
}
],
"aliasColors": {},
"aliasYAxis": {},
"title": "First Graph (click title to edit)",
"datasource": "graphite",
"renderer": "flot",
"annotate": {
"enable": false
}
}
]
}
],
"nav": [
{
"type": "timepicker",
"collapse": false,
"enable": true,
"status": "Stable",
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
],
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"now": true
}
],
"time": {
"from": "now-6h",
"to": "now"
},
"templating": {
"list": []
},
"version": 5
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment