grafana-api-java-client

A simple java client for interacting with Grafana using a fluent interface

License

License

Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

com.appnexus.grafana-client
ArtifactId

ArtifactId

grafana-api-java-client
Last Version

Last Version

1.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

grafana-api-java-client
A simple java client for interacting with Grafana using a fluent interface
Project URL

Project URL

https://github.com/appnexus/grafana-api-java-client
Source Code Management

Source Code Management

https://github.com/appnexus/grafana-api-java-client.git

Download grafana-api-java-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.appnexus.grafana-client/grafana-api-java-client/ -->
<dependency>
    <groupId>com.appnexus.grafana-client</groupId>
    <artifactId>grafana-api-java-client</artifactId>
    <version>1.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.appnexus.grafana-client/grafana-api-java-client/
implementation 'com.appnexus.grafana-client:grafana-api-java-client:1.0.5'
// https://jarcasting.com/artifacts/com.appnexus.grafana-client/grafana-api-java-client/
implementation ("com.appnexus.grafana-client:grafana-api-java-client:1.0.5")
'com.appnexus.grafana-client:grafana-api-java-client:jar:1.0.5'
<dependency org="com.appnexus.grafana-client" name="grafana-api-java-client" rev="1.0.5">
  <artifact name="grafana-api-java-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.appnexus.grafana-client', module='grafana-api-java-client', version='1.0.5')
)
libraryDependencies += "com.appnexus.grafana-client" % "grafana-api-java-client" % "1.0.5"
[com.appnexus.grafana-client/grafana-api-java-client "1.0.5"]

Dependencies

compile (5)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar 2.8.8
com.fasterxml.jackson.core : jackson-annotations jar 2.8.8
com.fasterxml.jackson.core : jackson-databind jar 2.8.8
com.squareup.retrofit2 : retrofit jar 2.2.0
com.squareup.retrofit2 : converter-jackson jar 2.2.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Grafana Client Build Status

A simple java client for interacting with Grafana using a fluent interface.

Usage

Simple Example:

import com.appnexus.grafana.client.GrafanaClient;

//Setup the client
GrafanaConfiguration grafanaConfiguration =
        new GrafanaConfiguration().host("your_grafana_host").apiKey("Bearer your_secret_key");
GrafanaClient grafanaClient = new GrafanaClient(grafanaConfiguration);

//Setup the dashboard
String DASHBOARD_NAME = "new_dashboard";

Dashboard dashboard = new Dashboard()
      .title(DASHBOARD_NAME)
      .version(0);

GrafanaDashboard grafanaDashboard = new GrafanaDashboard().dashboard(dashboard);

//Make API calls
grafanaClient.createDashboard(grafanaDashboard);

grafanaClient.getDashboard(DASHBOARD_NAME);

grafanaClient.deleteDashboard(DASHBOARD_NAME);

Here is a more complex example that sets up a Grafana dashboard with a panel and row:

import com.appnexus.grafana.client.GrafanaClient;

//Setup the client
GrafanaConfiguration grafanaConfiguration =
        new GrafanaConfiguration().host("your_grafana_host").apiKey("Bearer your_secret_key");
GrafanaClient grafanaClient = new GrafanaClient(grafanaConfiguration);

//Setup the dashboard
String DASHBOARD_NAME = "new_dashboard";

DashboardPanelTarget dashboardPanelTarget =
    new DashboardPanelTarget().refId("getSomeMetric").target("*");

DashboardPanelXAxis dashboardPanelXAxis =
    new DashboardPanelXAxis().show(true).mode(DashboardPanelXAxis.Mode.TIME);

DashboardPanelYAxis dashboardPanelYAxis =
    new DashboardPanelYAxis().format(DashboardPanelYAxis.Format.SHORT).logBase(1).show(true);

//Datasource is required or alerts cannot be added
DashboardPanel dashboardPanel =
    new DashboardPanel()
        .targets(new ArrayList<>(Collections.singletonList(dashboardPanelTarget)))
        .datasource(DASHBOARD_DATA_SOURCE)
        .type(DashboardPanel.Type.GRAPH)
        .fill(1)
        .title(dashboardName)
        .linewidth(1)
        .lines(true)
        .height("300px")
        .span(12)
        .xaxis(dashboardPanelXAxis)
        .yaxes(new ArrayList<>(Arrays.asList(dashboardPanelYAxis, dashboardPanelYAxis)));

DashboardRow dashboardRow =
    new DashboardRow()
        .collapse(false)
        .panels(new ArrayList<>(Collections.singletonList(dashboardPanel)));

Dashboard dashboard =
    new Dashboard()
        .title(dashboardName)
        .schemaVersion(1)
        .rows(new ArrayList<>(Collections.singletonList(dashboardRow)));

DashboardMeta dashboardMeta = new DashboardMeta().canSave(true).slug(dashboardName);

GrafanaDashboard grafanaDashboard =
    new GrafanaDashboard().meta(dashboardMeta).dashboard(dashboard);

//create new dashboard
DashboardMeta createdDashboardMeta = createDashboardTest(grafanaDashboard);

Javadocs

Javadocs can be found here.

Contributing

If you would like to contribute, please see our current list of issues and/or feature requests and send us a pull request. If you have something specific that you'd like to add or fix, please open up an issue for discussion. If it is a fix for a bug or everyone agrees that it would be a useful feature, then submit your pull request. Make sure that your pull request's commit message uses one of the appropriate identifiers to link the pull request to the issue.

Style Guide

This project follows the Google Java Style. It is enforced through the spotless gradle plugin which runs as part of each build. To fix any style issues automatically you can run ./gradlew spotlessApply

License

See LICENSE file

Notice

See NOTICE file

com.appnexus.grafana-client

AppNexus

Versions

Version
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0