Example #1
0
def test_custom_template_dont_override_options():
    t = G.Template(
        name='test',
        query='1,2,3',
        default='1',
        options=[
            {
                "value": '1',
                "selected": True,
                "text": 'some text 1',
            },
            {
                "value": '2',
                "selected": False,
                "text": 'some text 2',
            },
            {
                "value": '3',
                "selected": False,
                "text": 'some text 3',
            },
        ],
        type='custom',
    )

    assert len(t.to_json_data()['options']) == 3
    assert t.to_json_data()['current']['text'] == 'some text 1'
    assert t.to_json_data()['current']['value'] == '1'
Example #2
0
def test_template_defaults():
    t = G.Template(
        name='test',
        query='1m,5m,10m,30m,1h,3h,12h,1d',
        type='interval',
        default='1m',
    )

    assert t.to_json_data()['current']['text'] == '1m'
    assert t.to_json_data()['current']['value'] == '1m'
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")
            ]
        )
    )
Example #4
0
def test_custom_template_ok():
    t = G.Template(
        name='test',
        query='1,2,3',
        default='1',
        type='custom',
    )

    assert len(t.to_json_data()['options']) == 3
    assert t.to_json_data()['current']['text'] == '1'
    assert t.to_json_data()['current']['value'] == '1'
    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())
Example #6
0
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()
 rows=[
     d.Row(title="API call latency", panels=extended_copy(API_CALL_LATENCY_PANELS)),
     d.Row(title="API call latency aggregated with quantile", panels=extended_copy(QUANTILE_API_CALL_LATENCY_PANELS), collapse=True),
     d.Row(title="P&F metrics", panels=extended_copy(PAF_PANELS), collapse=True),
     d.Row(title="Overall cluster health", panels=extended_copy(HEALTH_PANELS), collapse=True),
     d.Row(title="etcd", panels=extended_copy(ETCD_PANELS), collapse=True),
     d.Row(title="kube-apiserver", panels=extended_copy(APISERVER_PANELS), collapse=True),
     d.Row(title="kube-controller-manager", panels=extended_copy(CONTROLLER_MANAGER_PANELS), collapse=True),
     d.Row(title="Master VM", panels=extended_copy(VM_PANELS), collapse=True),
 ],
 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,
Example #8
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re
import attr
from grafanalib import core as g

DECREASING_ORDER_TOOLTIP = g.Tooltip(sort=g.SORT_DESC)
PANEL_HEIGHT = g.Pixels(300)
QUANTILES = [0.99, 0.9, 0.5]

SOURCE_TEMPLATE = g.Template(name="source",
                             type="datasource",
                             query="prometheus")


@attr.s
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]))


# Graph is a g.Graph with reasonable defaults applied.
@attr.s
class Graph(g.Graph):
    dataSource = attr.ib(default="$source")
    span = attr.ib(default=g.TOTAL_SPAN)
Example #9
0
                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,
Example #10
0
    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())