class Dashboard(g.Dashboard): time = attr.ib(default=g.Time("now-30d", "now")) templating = attr.ib( default=g.Templating( list=[ # Make it possible to use $source as a source. g.Template(name="source", type="datasource", query="prometheus") ] ) )
def run(self): templateList = [ G.Template(default="", dataSource="default", name="serverid", label="ServerID", query="label_values(serverid)") ] dashboard = G.Dashboard(title=self.options.title, templating=G.Templating(list=templateList)) # Simple table processing - could be enhanced to use GridPos etc. for metric in metrics: if 'section' in metric: dashboard.rows.append( G.Row(title=metric['section'], showTitle=True)) continue if 'row' in metric: dashboard.rows.append(G.Row(title='', showTitle=False)) continue graph = G.Graph(title=metric['title'], dataSource='default', maxDataPoints=1000, legend=G.Legend(show=True, alignAsTable=True, min=True, max=True, avg=True, current=True, total=True, sort='max', sortDesc=True), yAxes=G.single_y_axis()) ref_id = 'A' for texp in metric['expr']: graph.targets.append(G.Target(expr=texp, refId=ref_id)) ref_id = chr(ord(ref_id) + 1) dashboard.rows[-1].panels.append(graph) # Auto-number panels - returns new dashboard dashboard = dashboard.auto_panel_ids() s = io.StringIO() write_dashboard(dashboard, s) print("""{ "dashboard": %s } """ % s.getvalue())
def Dashboard(**kwargs): """Standard Weave Cloud dashboard. Automatically sets panel ids and applies events from Weave Cloud as annotations. """ defaultTemplates = [G.Template( label="Datasource", name="datasource", type="datasource", query="prometheus", )] if "templating" in kwargs: extraTemplates = kwargs["templating"].list else: extraTemplates = [] kwargs["templating"] = G.Templating(list=defaultTemplates + extraTemplates) return G.Dashboard( refresh='1m', # Override the default of 10s **kwargs ).auto_panel_ids()
templating=g.Templating( list=[ d.SOURCE_TEMPLATE, g.Template( name="secondary_source", type="datasource", query="prometheus", ), g.Template( name="timeshift", type="interval", query="", ), g.Template( name="etcd_type", type="query", dataSource="$source", regex=r"\*\[+\]+(.*)", query="label_values(etcd_request_duration_seconds_count, type)", multi=True, includeAll=True, refresh=g.REFRESH_ON_TIME_RANGE_CHANGE, ), g.Template( name="etcd_operation", type="query", dataSource="$source", query="label_values(etcd_request_duration_seconds_count, operation)", multi=True, includeAll=True, refresh=g.REFRESH_ON_TIME_RANGE_CHANGE, ), g.Template( name="verb", type="query", dataSource="$source", query="label_values(apiserver_request_duration_seconds_count, verb)", multi=True, includeAll=True, refresh=g.REFRESH_ON_TIME_RANGE_CHANGE, ), g.Template( name="resource", type="query", dataSource="$source", regex="(.*)s", query="label_values(apiserver_request_duration_seconds_count, resource)", multi=True, includeAll=True, refresh=g.REFRESH_ON_TIME_RANGE_CHANGE, ), ] ),
class Dashboard(g.Dashboard): time = attr.ib(default=g.Time("now-30d", "now")) # Make it possible to use $source as a source. templating = attr.ib(default=g.Templating(list=[SOURCE_TEMPLATE]))
g.Target( expr= "sum(rate(node_netstat_Tcp_RetransSegs[1m])) by (instance)", legendFormat="RetransSegs {{instance}}", ), ], yAxes=g.single_y_axis(format=g.SHORT_FORMAT, logBase=10), ), ] # The final dashboard must be named 'dashboard' so that grafanalib will find it. dashboard = g.Dashboard( title="Master dashboard", time=g.Time("now-30d", "now"), templating=g.Templating(list=[ # Make it possible to use $source as a source. g.Template(name="source", type="datasource", query="prometheus") ]), rows=[ g.Row( title="Clusterloader", height=DEFAULT_PANEL_HEIGHT, panels=CLUSTERLOADER_PANELS, ), g.Row( title="Overall cluster health", height=DEFAULT_PANEL_HEIGHT, panels=HEALTH_PANELS, ), g.Row(title="etcd", height=DEFAULT_PANEL_HEIGHT, panels=ETCD_PANELS), g.Row(title="kube-apiserver", height=DEFAULT_PANEL_HEIGHT,
def run(self): templateList = [] if self.options.use_sdp: templateList.append( G.Template(default="1", dataSource="default", name="sdpinst", label="SDPInstance", query="label_values(sdpinst)")) if self.options.customer: templateList.append( G.Template(default="1", dataSource="default", name="customer", label="Customer", query="label_values(customer)")) templateList.append( G.Template(default="", dataSource="default", name="serverid", label="ServerID", query="label_values(serverid)")) dashboard = G.Dashboard(title=self.options.title, templating=G.Templating(list=templateList)) for metric in metrics: if 'section' in metric: dashboard.rows.append( G.Row(title=metric['section'], showTitle=True)) continue if 'row' in metric: dashboard.rows.append(G.Row(title='', showTitle=False)) continue if 'type' in metric and metric['type'] == 'gauge': pass # text = G.Text(title=metric['title'], # dataSource='default') # dashboard.rows[-1].panels.append(G.Text) else: yAxis = G.single_y_axis(format="short") if 'yformat' in metric: yAxis = G.single_y_axis(format=metric['yformat']) graph = G.Graph(title=metric['title'], dataSource='default', maxDataPoints=1000, legend=G.Legend(show=True, alignAsTable=True, min=True, max=True, avg=True, current=True, total=True, sort='max', sortDesc=True), yAxes=yAxis) refId = 'A' for targ in metric['target']: texp = targ['expr'] legend = "instance {{instance}}, serverid {{serverid}}" if 'legend' in targ: legend += ' %s' % targ['legend'] # Remove SDP if not self.options.use_sdp: texp = texp.replace('sdpinst="$sdpinst",', '') if self.options.customer: texp = texp.replace('{', '{customer="$customer",') graph.targets.append( G.Target(expr=texp, legendFormat=legend, refId=refId)) refId = chr(ord(refId) + 1) dashboard.rows[-1].panels.append(graph) # Auto-number panels - returns new dashboard dashboard = dashboard.auto_panel_ids() s = io.StringIO() write_dashboard(dashboard, s) print("""{ "dashboard": %s } """ % s.getvalue())