GithubHelp home page GithubHelp logo

joshuakwan / grafana-api-java-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from appnexus/grafana-api-java-client

0.0 3.0 0.0 216 KB

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

License: Other

Java 100.00%

grafana-api-java-client's Introduction

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

grafana-api-java-client's People

Contributors

simpandev avatar ashtynlynne avatar skoka-anx avatar

Watchers

James Cloos avatar Joshua Guan avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.