{"id":15286500,"url":"https://github.com/szmg/grafana-dashboard-generator-java","last_synced_at":"2025-04-13T03:32:41.413Z","repository":{"id":57743679,"uuid":"89956253","full_name":"szmg/grafana-dashboard-generator-java","owner":"szmg","description":"Generate and publish Grafana dashboards in Java. Build your own \"blocks\" and use auto-complete!","archived":false,"fork":false,"pushed_at":"2017-05-31T20:15:39.000Z","size":144,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:49:32.220Z","etag":null,"topics":["dashboard","generator","grafana","grafana-dashboard"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/szmg.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-01T19:37:17.000Z","updated_at":"2023-05-18T08:55:11.000Z","dependencies_parsed_at":"2022-09-11T09:40:08.694Z","dependency_job_id":null,"html_url":"https://github.com/szmg/grafana-dashboard-generator-java","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szmg%2Fgrafana-dashboard-generator-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szmg%2Fgrafana-dashboard-generator-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szmg%2Fgrafana-dashboard-generator-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szmg%2Fgrafana-dashboard-generator-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szmg","download_url":"https://codeload.github.com/szmg/grafana-dashboard-generator-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248659671,"owners_count":21141156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dashboard","generator","grafana","grafana-dashboard"],"created_at":"2024-09-30T15:15:12.483Z","updated_at":"2025-04-13T03:32:41.385Z","avatar_url":"https://github.com/szmg.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grafana dashboard builder in Java\n\n[![Build Status](https://travis-ci.org/szmg/grafana-dashboard-generator-java.svg?branch=master)](https://travis-ci.org/szmg/grafana-dashboard-generator-java)\n[![Maven Central](https://img.shields.io/maven-central/v/uk.co.szmg.grafana/grafana-dashboard-generator.svg)](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22grafana-dashboard-generator%22)\n\n\n```\nThis is Work in progress\n```\n\nCode your Grafana dashboards in Java, more or less type-safe, with auto-complete. Then upload them to Grafana. As part of your build process if you fancy.\n\n## Features\n\n* create dashboards in Java\n* create and _reuse_ your own frequently used components\n* upload your dashboards to Grafana\n* ApiKey or session cookie authentication\n* upload as part of your build process (Maven plugin)\n* upload with a nice command line tool\n* do not get stuck if the lib is missing a property or a type: add it without needing to recompile the lib (see [below](#flexible-domain-objects))\n* [PLAN] watch code and generate+upload on change (with the fast but limited Janino compiler)\n\n\n## Usage\n\nTODO different use cases, development mode, CD\n\n### Maven\n\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003euk.co.szmg.grafana\u003c/groupId\u003e\n    \u003cartifactId\u003egrafana-dashboard-generator\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Basics\n\nI suggest you play with this and learn it that way. It's really straightforward if you are familiar with Grafana. `uk.co.szmg.grafana.domain.DomainFactories` is a good place to start.\n\n```java\n//import static uk.co.szmg.grafana.domain.DomainFactories.*\n\nTarget target = newTarget()\n        .withTarget(\"maxSeries(humidity.peti.test.sensors)\");\n\nRow row1 = newRow()\n        .withHeight(\"100px\")\n        .addPanel(newSingleStat()\n                .withTitle(\"Single stat test\")\n                .addTarget(target)\n                .withSpan(2))\n        .addPanel(newText()\n                .withContent(\"\u003cdiv class=\\\"text-center dashboard-header\\\"\u003e\u003cspan\u003eThis is the test\u003c/span\u003e\u003c/div\u003e\")\n                .withMode(\"html\")\n                .withTransparent(true)\n                .withSpan(8))\n        .addPanel(newSingleStat()\n                .withTitle(\"Single stat test\")\n                .addTarget(target)\n                .withSpan(2));\n\nRow row2 = newRow()\n        .addPanel(newGraph()\n                .addTarget(target)\n                .withSpan(12));\n\nDashboard dashboard = newDashboard()\n        .withTitle(\"Test dashboard\")\n        .addRow(row1)\n        .addRow(row2);\n\n```\n\n### Higher level bits and bobs\n\nTODO document\n\n### Write to stream (optional)\n\nConvert to string or write onto a stream:\n\n```java\nDashboardSerializer serializer = new DashboardSerializer();\n\n// to String\nSystem.out.println(serializer.toString(dashboard));\n\n// write to Stream\nserializer.write(testDashboard(), System.out);\n```\n\n### Upload to Grafana\n\nIt's easy to update your dashboards from code.\n\n```java\n\n// Create an endpoint first...\n// Can use either API key or session cookie auth.\nGrafanaEndpoint endpoint = new GrafanaEndpoint();\nendpoint.setBaseUrl(\"https://grafana.mydomain.com\");\n\n// see http://docs.grafana.org/http_api/auth/\nendpoint.setApiKey(\"some api key\");\n\n// copy \"grafana_sess\" cookie\n//endpoint.setSessionCookie(\"123456789asd\");\n\n// for insecure Grafana installations...\nendpoint.setSkipSSLValidation(true);\n\n\n// ...then the uploader...\nDashboardUploader uploader = new DashboardUploader(endpoint);\n\n\n// ...and upload, overwriting any existing dashboard with\n// that title. (\"Test dashboard\")\nuploader.upload(dashboard, true);\n\n\n```\n\n## Flexible domain objects\n\nIf a field that you want to use is missing or its type has changed (e.g., a new type of panel), you can\nquickly add/override it without changing the library code itself. (Although a PR is welcomed.)\n\nSo no one have to clone/modify/compile/raise PR/wait for trying out an unusual/new/forgotten field/type.\n\nEvery domain object has a generic setter, getter and \"with\" method:\n\n```java\n\n// setter\ndashboard.setField(\"templateInstance\", \"my favorite\");\nassert dashboard.getField(\"templateInstance\") == \"my favorite\";\n\n// \"with\" method\nDashboard sameDashboard = dashboard.withField(\"templateInstance\", \"my other favorite\");\nassert dashboard.getField(\"templateInstance\") == \"my other favorite\"; // it's not immutable\nassert sameDashboard.getField(\"templateInstance\") == \"my other favorite\";\n\n// use a new type of panel\nrow1.addPanel(new Panel.Generic()\n        .withValue(\"type\", \"new type\")\n        .withValue(\"newField\", \"value\"));\n```\n\nTechnical stuff: every domain object is a `Map\u003cString, Object\u003e` wrapped into their class; every typed property reads and writes that map. By using the generic setters/getter, you can write that map, too.\n\nYou might want to look at the source of e.g., `Graph` to see how it works. And look for the file `graph.yaml` to see what it is generated from.\n\n## License\n\nApache License Version 2.0\n\nCopyright (c) 2017 Mate Gabor Szvoboda\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszmg%2Fgrafana-dashboard-generator-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszmg%2Fgrafana-dashboard-generator-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszmg%2Fgrafana-dashboard-generator-java/lists"}