cdk8sgrafana

package module
v0.1.642 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

cdk8s-grafana

View on Construct Hub

cdk8s-grafana is a library that lets you easily define a Grafana service for your kubernetes cluster along with associated dashboards and datasources, using a high level API.

Usage

To apply the resources generated by this construct, the Grafana operator must be installed on your cluster. See https://operatorhub.io/operator/grafana-operator for full installation instructions.

The following will define a Grafana cluster connected to a Prometheus datasource:

import { Grafana } from 'cdk8s-grafana';

// inside your chart:
const grafana = new Grafana(this, 'my-grafana', {
  defaultDataSource: {
    name: 'Prometheus',
    type: 'prometheus',
    access: 'proxy',
    url: 'http://prometheus-service:9090',
  }
});

Basic aspects of a dashboard can be customized:

const github = grafana.addDatasource('github', ...);
const dashboard = grafana.addDashboard('my-dashboard', {
  title: 'My Dashboard',
  refreshRate: Duration.seconds(10),
  timeRange: Duration.hours(6), // show metrics from now-6h to now
  plugins: [
    {
      name: 'grafana-piechart-panel',
      version: '1.3.6',
    }
  ],
});

Note: the kubernetes grafana operator only supports one Grafana instance per namespace (see https://github.com/grafana-operator/grafana-operator/issues/174). This may require specifying namespaces explicitly, e.g.:

const devGrafana = new Grafana(this, 'my-grafana', {
  namespace: 'dev',
});
const prodGrafana = new Grafana(this, 'my-grafana', {
  namespace: 'prod',
});

The grafana operator must be installed in each namespace for the resources in that namespace to be recognized.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Documentation

Overview

Grafana construct for cdk8s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dashboard_IsConstruct

func Dashboard_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

func DataSource_IsConstruct

func DataSource_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

func Grafana_IsConstruct

func Grafana_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

func NewDashboard_Override

func NewDashboard_Override(d Dashboard, scope constructs.Construct, id *string, props *DashboardProps)

func NewDataSource_Override

func NewDataSource_Override(d DataSource, scope constructs.Construct, id *string, props *DataSourceProps)

func NewGrafana_Override

func NewGrafana_Override(g Grafana, scope constructs.Construct, id *string, props *GrafanaProps)

Types

type AccessType

type AccessType string

Mode for accessing a data source. See: https://grafana.com/docs/grafana/latest/administration/provisioning/#example-data-source-config-file

const (
	// Access via proxy.
	AccessType_PROXY AccessType = "PROXY"
	// Access directly (via server or browser in UI).
	AccessType_DIRECT AccessType = "DIRECT"
)

type Dashboard

type Dashboard interface {
	constructs.Construct
	// The tree node.
	Node() constructs.Node
	// Adds one or more plugins.
	AddPlugins(plugins ...*GrafanaPlugin)
	// Returns a string representation of this construct.
	ToString() *string
}

A Grafana dashboard. See: https://grafana.com/docs/grafana/latest/http_api/dashboard/

func NewDashboard

func NewDashboard(scope constructs.Construct, id *string, props *DashboardProps) Dashboard

type DashboardProps

type DashboardProps struct {
	// Title of the dashboard.
	Title *string `field:"required" json:"title" yaml:"title"`
	// Specify a mapping from data source variables to data source names.
	//
	// This is only needed if you are importing an existing dashboard's JSON
	// and it specifies variables within an "__inputs" field.
	//
	// Example:
	//   { DS_PROMETHEUS: "my-prometheus-ds" }
	//
	// Default: - no data source variables.
	//
	DataSourceVariables *map[string]*string `field:"optional" json:"dataSourceVariables" yaml:"dataSourceVariables"`
	// Group dashboards into folders.
	// Default: - default folder.
	//
	Folder *string `field:"optional" json:"folder" yaml:"folder"`
	// All other dashboard customizations.
	// See: https://grafana.com/docs/grafana/latest/dashboards/json-model/
	//
	JsonModel *map[string]interface{} `field:"optional" json:"jsonModel" yaml:"jsonModel"`
	// Labels to apply to the kubernetes resource.
	//
	// When adding a dashboard to a Grafana instance using `grafana.addDashboard`,
	// labels provided to Grafana will be automatically applied. Otherwise,
	// labels must be added manually.
	// Default: - no labels.
	//
	Labels *map[string]*string `field:"optional" json:"labels" yaml:"labels"`
	// Namespace to apply to the kubernetes resource.
	//
	// When adding a dashboard to a Grafana instance using `grafana.addDashboard`,
	// the namespace will be automatically inherited.
	// Default: - undefined (will be assigned to the 'default' namespace).
	//
	Namespace *string `field:"optional" json:"namespace" yaml:"namespace"`
	// Specify plugins required by the dashboard.
	Plugins *[]*GrafanaPlugin `field:"optional" json:"plugins" yaml:"plugins"`
	// Auto-refresh interval.
	// Default: - 5 seconds.
	//
	RefreshRate cdk8s.Duration `field:"optional" json:"refreshRate" yaml:"refreshRate"`
	// Time range for the dashboard, e.g. last 6 hours, last 7 days, etc.
	// Default: - 6 hours.
	//
	TimeRange cdk8s.Duration `field:"optional" json:"timeRange" yaml:"timeRange"`
}

type DataSource

type DataSource interface {
	constructs.Construct
	// Name of the data source.
	Name() *string
	// The tree node.
	Node() constructs.Node
	// Returns a string representation of this construct.
	ToString() *string
}

A Grafana data source. See: https://grafana.com/docs/grafana/latest/administration/provisioning/#example-data-source-config-file

func NewDataSource

func NewDataSource(scope constructs.Construct, id *string, props *DataSourceProps) DataSource

type DataSourceProps

type DataSourceProps struct {
	// Access type of the data source.
	Access AccessType `field:"required" json:"access" yaml:"access"`
	// Name of the data source.
	Name *string `field:"required" json:"name" yaml:"name"`
	// Type of the data source.
	Type *string `field:"required" json:"type" yaml:"type"`
	// Description of the data source.
	// Default: - no description.
	//
	Description *string `field:"optional" json:"description" yaml:"description"`
	// Labels to apply to the kubernetes resource.
	//
	// When adding a data source to a Grafana instance using `grafana.addDataSource`,
	// labels provided to Grafana will be automatically applied. Otherwise,
	// labels must be added manually.
	// Default: - no labels.
	//
	Labels *map[string]*string `field:"optional" json:"labels" yaml:"labels"`
	// Namespace to apply to the kubernetes resource.
	//
	// When adding a data source to a Grafana instance using `grafana.addDataSource`,
	// the namespace will be automatically inherited.
	// Default: - undefined (will be assigned to the 'default' namespace).
	//
	Namespace *string `field:"optional" json:"namespace" yaml:"namespace"`
	// URL of the data source.
	//
	// Most resources besides the 'testdata' data source
	// type require this field in order to retrieve data.
	// Default: - default url for data source type.
	//
	Url *string `field:"optional" json:"url" yaml:"url"`
}

type Grafana

type Grafana interface {
	constructs.Construct
	// The tree node.
	Node() constructs.Node
	// Creates a dashboard associated with a particular data source.
	//
	// By default,
	// labels are automatically added so that the data source is detected by
	// Grafana.
	AddDashboard(id *string, props *DashboardProps) Dashboard
	// Adds a data source.
	//
	// By default, labels are automatically added so that
	// the data source is detected by Grafana.
	AddDataSource(id *string, props *DataSourceProps) DataSource
	// Returns a string representation of this construct.
	ToString() *string
}

A Grafana instance.

func NewGrafana

func NewGrafana(scope constructs.Construct, id *string, props *GrafanaProps) Grafana

type GrafanaPlugin

type GrafanaPlugin struct {
	// Name of the plugin, e.g. "grafana-piechart-panel".
	Name *string `field:"required" json:"name" yaml:"name"`
	// Version of the plugin, e.g. "1.3.6".
	Version *string `field:"required" json:"version" yaml:"version"`
}

type GrafanaProps

type GrafanaProps struct {
	// Default admin password.
	// Default: "secret".
	//
	AdminPassword *string `field:"optional" json:"adminPassword" yaml:"adminPassword"`
	// Default admin username.
	// Default: "root".
	//
	AdminUser *string `field:"optional" json:"adminUser" yaml:"adminUser"`
	// Default data source - equivalent to calling `grafana.addDataSource`.
	// Default: - no data source added.
	//
	DefaultDataSource *DataSourceProps `field:"optional" json:"defaultDataSource" yaml:"defaultDataSource"`
	// Specify a custom image for Grafana.
	// Default: "public.ecr.aws/ubuntu/grafana:latest"
	//
	Image *string `field:"optional" json:"image" yaml:"image"`
	// Create an ingress to provide external access to the Grafana cluster.
	// Default: true.
	//
	Ingress *bool `field:"optional" json:"ingress" yaml:"ingress"`
	// Labels to apply to all Grafana resources.
	// Default: - { app: "grafana" }.
	//
	Labels *map[string]*string `field:"optional" json:"labels" yaml:"labels"`
	// Namespace to apply to all Grafana resources.
	//
	// The Grafana Operator must be
	// installed in this namespace for resources to be recognized.
	// Default: - undefined (will be assigned to the 'default' namespace).
	//
	Namespace *string `field:"optional" json:"namespace" yaml:"namespace"`
	// Require login in order to view or manage dashboards.
	// Default: false.
	//
	RequireLogin *bool `field:"optional" json:"requireLogin" yaml:"requireLogin"`
	// Type of service to be created (NodePort, ClusterIP or LoadBalancer).
	// Default: ClusterIP.
	//
	ServiceType *string `field:"optional" json:"serviceType" yaml:"serviceType"`
}

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL