在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):brancz/kubernetes-grafana开源软件地址(OpenSource Url):https://github.com/brancz/kubernetes-grafana开源编程语言(OpenSource Language):Jsonnet 93.7%开源软件介绍(OpenSource Introduction):Kubernetes GrafanaThis project is about running Grafana on Kubernetes with Prometheus as the datasource in a very opinionated and entirely declarative way. This allows easily operating Grafana highly available as if it was a stateless application - no need to run a clustered database for your dashboarding solution anymore! Note that at this point this is primarily about getting into the same state as kube-prometheus currently is. It is about packaging up Grafana as a reusable component, without dashboards. Dashboards are to be defined when using this Grafana package. What and why is happening here?This repository exists because the Grafana stack in kube-prometheus has gotten close to unmaintainable due to the many steps of generation and it's a very steep learning curve for newcomers. Since Grafana v5, Grafana can be provisioned with dashboards from files. This project is primarily about generating a set of useful Grafana dashboards for use with and on Kubernetes using with Prometheus as the datasource. In this repository everything is generated via jsonnet:
With a single jsonnet command the whole stack is generated and can be applied against a Kubernetes cluster. PrerequisitesYou need a running Kubernetes cluster in order to try this out, with the kube-prometheus stack deployed on it as have Docker installed to and be able to mount volumes correctly (this is not the case when using the Docker host of minikube). For trying this out provision minikube with these settings:
UsageUse this package in your own infrastructure using
An example of how to use it could be: local grafana = import 'grafana/grafana.libsonnet';
{
_config:: {
namespace: 'monitoring-grafana',
},
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
},
} This builds the entire Grafana stack with your own dashboards and a configurable namespace. Simply run:
CustomizingAdding dashboardsThis setup is optimized to work best when Grafana is used declaratively, so when adding dashboards they are added declaratively as well. In jsonnet there are libraries available to avoid having to repeat boilerplate of Grafana dashboard json. An example with the grafana/grafonnet-lib: local grafonnet = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet';
local dashboard = grafonnet.dashboard;
local row = grafonnet.row;
local prometheus = grafonnet.prometheus;
local template = grafonnet.template;
local graphPanel = grafonnet.graphPanel;
local grafana = import 'grafana/grafana.libsonnet';
{
_config:: {
namespace: 'monitoring-grafana',
dashboards+: {
'my-dashboard.json':
dashboard.new('My Dashboard')
.addTemplate(
{
current: {
text: 'Prometheus',
value: 'Prometheus',
},
hide: 0,
label: null,
name: 'datasource',
options: [],
query: 'prometheus',
refresh: 1,
regex: '',
type: 'datasource',
},
)
.addRow(
row.new()
.addPanel(
graphPanel.new('My Panel', span=6, datasource='$datasource')
.addTarget(prometheus.target('vector(1)')),
)
),
},
},
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
},
} Organizing dashboardsIf you have many dashboards and would like to organize them into folders, you can do that as well by specifying them in local grafonnet = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet';
local dashboard = grafonnet.dashboard;
local row = grafonnet.row;
local prometheus = grafonnet.prometheus;
local template = grafonnet.template;
local graphPanel = grafonnet.graphPanel;
local grafana = import 'grafana/grafana.libsonnet';
{
_config:: {
namespace: 'monitoring-grafana',
folderDashboards+: {
Services: {
'regional-services-dashboard.json': (import 'dashboards/regional-services-dashboard.json'),
'global-services-dashboard.json': (import 'dashboards/global-services-dashboard.json'),
},
AWS: {
'aws-ec2-dashboard.json': (import 'dashboards/aws-ec2-dashboard.json'),
'aws-rds-dashboard.json': (import 'dashboards/aws-rds-dashboard.json'),
'aws-sqs-dashboard.json': (import 'dashboards/aws-sqs-dashboard.json'),
},
ISTIO: {
'istio-citadel-dashboard.json': (import 'dashboards/istio-citadel-dashboard.json'),
'istio-galley-dashboard.json': (import 'dashboards/istio-galley-dashboard.json'),
'istio-mesh-dashboard.json': (import 'dashboards/istio-mesh-dashboard.json'),
'istio-pilot-dashboard.json': (import 'dashboards/istio-pilot-dashboard.json'),
},
},
},
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
},
} Dashboards mixinsUsing the kubernetes-mixins, simply install:
And apply the mixin: local kubernetesMixin = import 'github.com/kubernetes-monitoring/kubernetes-mixin/mixin.libsonnet';
local grafana = import 'grafana/grafana.libsonnet';
{
_config:: {
namespace: 'monitoring-grafana',
dashboards: kubernetesMixin.grafanaDashboards,
},
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
},
} To generate, again simply run:
This yields a fully configured Grafana stack with useful Kubernetes dashboards. Config customizationGrafana can be run with many different configurations. Different organizations have different preferences, therefore the Grafana configuration can be arbitrary modified. The configuration happens via the the For example to modify Grafana configuration and set up LDAP use: local grafana = import 'grafana/grafana.libsonnet';
{
local customIni =
grafana({
_config+:: {
namespace: 'monitoring-grafana',
grafana+:: {
config: {
sections: {
metrics: { enabled: true },
'auth.ldap': {
enabled: true,
config_file: '/etc/grafana/ldap.toml',
allow_sign_up: true,
},
},
},
ldap: |||
[[servers]]
host = "127.0.0.1"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
bind_dn = "cn=admin,dc=grafana,dc=org"
bind_password = 'grafana'
search_filter = "(cn=%s)"
search_base_dns = ["dc=grafana,dc=org"]
|||,
},
},
}),
apiVersion: 'v1',
kind: 'List',
items:
customIni.dashboardDefinitions.items +
[
customIni.config,
customIni.dashboardSources,
customIni.dashboardDatasources,
customIni.deployment,
customIni.serviceAccount,
customIni.service {
spec+: { ports: [
port {
nodePort: 30910,
}
for port in super.ports
] },
},
],
} PluginsThe config object allows specifying an array of plugins to install at startup. local grafana = import 'grafana/grafana.libsonnet';
{
_config:: {
namespace: 'monitoring-grafana',
plugins: ['camptocamp-prometheus-alertmanager-datasource'],
},
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
},
} RoadmapThere are a number of things missing for the Grafana stack and tooling to be fully migrated. If you are interested in working on any of these, please open a respective issue to avoid duplicating efforts.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论