How to use the grafanalib.core.YAxes function in grafanalib

To help you get started, we’ve selected a few grafanalib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mesosphere / spark-build / scale-tests / sdk.dashboard.py View on Github external
resolution = "1m"

    return G.Row(
        title="Task statistics",
        panels=[
            W.prometheus.PromGraph(
                data_source=PROMETHEUS_DATA_SOURCE,
                title="cumulative task statistic",
                expressions=[
                    {"expr": sum(service_metric(m)), "legendFormat": m}
                    for m in task_metrics
                ],
                span=3,
                steppedLine=True,
                yAxes=G.YAxes(left=G.YAxis(format="short", decimals=0)),
            ),
            W.prometheus.PromGraph(
                data_source=PROMETHEUS_DATA_SOURCE,
                title="task events per second [{} rate]".format(resolution),
                expressions=[
                    {
                        "expr": sum(service_metric(m, "rate", resolution)),
                        "legendFormat": m,
                    }
                    for m in task_metrics
                ],
                span=3,
                steppedLine=True,
            ),
github mesosphere / spark-build / scale-tests / sdk.dashboard.py View on Github external
"legendFormat": m,
                    }
                    for m in offer_metrics
                ],
                span=3,
                steppedLine=True,
            ),
            W.prometheus.PromGraph(
                data_source=PROMETHEUS_DATA_SOURCE,
                title="offer processing time",
                expressions=[
                    {"expr": sum(service_metric(m)), "legendFormat": m}
                    for m in offer_timers
                ],
                span=3,
                yAxes=G.YAxes(left=G.YAxis(format="ns")),
            ),
github weaveworks / grafanalib / grafanalib / core.py View on Github external
def to_y_axes(data):
    """Backwards compatibility for 'YAxes'.

    In grafanalib 0.1.2 and earlier, Y axes were specified as a list of two
    elements. Now, we have a dedicated `YAxes` type.

    This function converts a list of two `YAxis` values to a `YAxes` value,
    silently passes through `YAxes` values, warns about doing things the old
    way, and errors when there are invalid values.
    """
    if isinstance(data, YAxes):
        return data
    if not isinstance(data, (list, tuple)):
        raise ValueError(
            "Y axes must be either YAxes or a list of two values, got %r"
            % data)
    if len(data) != 2:
        raise ValueError(
            "Must specify exactly two YAxes, got %d: %r"
            % (len(data), data))
    warnings.warn(
        "Specify Y axes using YAxes or single_y_axis, rather than a "
        "list/tuple",
        DeprecationWarning, stacklevel=3)
    return YAxes(left=data[0], right=data[1])
github prometheus-operator / prometheus-operator / contrib / kube-prometheus / assets / grafana / _grafanalib.py View on Github external
def Graph(
    id, title, targets, dashLength=None, dashes=False, spaceLength=None,
    xAxis=None, yAxes=None, nullPointMode='connected',
):
    def merge_target(target):
        return {**{
            'intervalFactor': 2,
            'legendFormat': '',
            'refId': 'A',
            'step': 600,
        }, **target}

    targets = [merge_target(t) for t in targets]
    assert isinstance(yAxes, YAxes)
    return core.Graph(
        id=id, title=title, dashLength=dashLength, dashes=dashes,
        spaceLength=spaceLength, targets=targets, xAxis=xAxis, yAxes=yAxes,
        dataSource='${DS_PROMETHEUS}', nullPointMode=nullPointMode, editable=False,
    )
github weaveworks / grafanalib / grafanalib / core.py View on Github external
def single_y_axis(**kwargs):
    """Specify that a graph has a single Y axis.

    Parameters are those passed to `YAxis`. Returns a `YAxes` object (i.e. a
    pair of axes) that can be used as the yAxes parameter of a graph.
    """
    axis = YAxis(**kwargs)
    return YAxes(left=axis)
github weaveworks / grafanalib / grafanalib / weave.py View on Github external
:param title: Title of the graph.
    :param expressions: List of Prometheus expressions. Must be 5.
    :param kwargs: Passed on to Graph.
    """
    if len(expressions) != 5 and len(expressions) != 7:
        raise ValueError('Expected 5 or 7 expressions, got {}: {}'.format(
            len(expressions), expressions))
    legends = sorted(ALIAS_COLORS.keys())
    exprs = zip(legends, expressions)
    return stacked(prometheus.PromGraph(
        data_source=data_source,
        title=title,
        expressions=exprs,
        aliasColors=ALIAS_COLORS,
        yAxes=G.YAxes(
            G.YAxis(format=G.OPS_FORMAT),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
        **kwargs
    ))
github weaveworks / grafanalib / grafanalib / core.py View on Github external
span = attr.ib(default=None)
    stack = attr.ib(default=False, validator=instance_of(bool))
    steppedLine = attr.ib(default=False, validator=instance_of(bool))
    timeFrom = attr.ib(default=None)
    timeShift = attr.ib(default=None)
    tooltip = attr.ib(
        default=attr.Factory(Tooltip),
        validator=instance_of(Tooltip),
    )
    transparent = attr.ib(default=False, validator=instance_of(bool))
    xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis))
    # XXX: This isn't a *good* default, rather it's the default Grafana uses.
    yAxes = attr.ib(
        default=attr.Factory(YAxes),
        converter=to_y_axes,
        validator=instance_of(YAxes),
    )
    alert = attr.ib(default=None)

    def to_json_data(self):
        graphObject = {
            'aliasColors': self.aliasColors,
            'bars': self.bars,
            'datasource': self.dataSource,
            'description': self.description,
            'editable': self.editable,
            'error': self.error,
            'fill': self.fill,
            'grid': self.grid,
            'id': self.id,
            'isNew': self.isNew,
            'legend': self.legend,