Skip to content

Commit

Permalink
feat(dashboard): add env var to select panels to be included
Browse files Browse the repository at this point in the history
  • Loading branch information
Atrax1 committed Feb 21, 2024
1 parent 66d3e83 commit 393041d
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 92 deletions.
15 changes: 13 additions & 2 deletions charts/chainlink-cluster/dashboard/cmd/dashboard_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import (
"fmt"
"github.com/smartcontractkit/chainlink/charts/chainlink-cluster/dashboard/dashboard"
"os"
"strings"
)

func main() {
name := os.Getenv("DASHBOARD_NAME")
if name == "" {
panic("DASHBOARD_NAME must be provided")
}
// Can be empty

lokiDataSourceName := os.Getenv("LOKI_DATA_SOURCE_NAME")
if lokiDataSourceName == "" {
fmt.Println("LOKI_DATA_SOURCE_NAME is empty, panels with logs will be disabled")
}

prometheusDataSourceName := os.Getenv("PROMETHEUS_DATA_SOURCE_NAME")
if prometheusDataSourceName == "" {
Expand All @@ -39,6 +43,13 @@ func main() {
panic("INFRA_PLATFORM must be provided, can be either docker|kubernetes")
}

panelsIncluded := os.Getenv("PANELS_INCLUDED")
// can be empty
if panelsIncluded == "" {
fmt.Println("PANELS_INCLUDED can be provided to specify panels groups, value must be separated by comma. Possible values are: core, wasp")
}
panelsIncludedArray := strings.Split(panelsIncluded, ",")

err := dashboard.NewDashboard(
name,
grafanaURL,
Expand All @@ -48,7 +59,7 @@ func main() {
lokiDataSourceName,
prometheusDataSourceName,
infraPlatform,
[]string{"core"},
panelsIncludedArray,
nil,
)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion charts/chainlink-cluster/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func NewDashboard(
}
db.init()
db.addCoreVariables()
db.addCorePanels()
if Contains(db.panels, "core") {
db.addCorePanels()
}

switch db.platform {
case "kubernetes":
Expand Down
212 changes: 123 additions & 89 deletions charts/chainlink-cluster/dashboard/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,107 @@ import (
)

func (m *Dashboard) addMainPanels() {
var podRestartPanel row.Option = nil
var ethBalancePanelSpanSize float32 = 6
var panelsIncluded []row.Option
var goVersionLegend string = "version"

if m.platform == "kubernetes" {
podRestartPanel = row.WithStat(
ethBalancePanelSpanSize = 4
goVersionLegend = "exported_version"
}

globalInfoPanels := []row.Option{
row.WithStat(
"App Version",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Text("name"),
stat.Height("100px"),
stat.WithPrometheusTarget(
`version{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{version}}"),
),
),
row.WithStat(
"Go Version",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Text("name"),
stat.Height("100px"),
stat.WithPrometheusTarget(
`go_info{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+goVersionLegend+"}}"),
),
),
row.WithStat(
"Uptime in days",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Height("100px"),
stat.WithPrometheusTarget(
`uptime_seconds{`+m.panelOption.labelFilter+`=~"$instance"} / 86400`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}}"),
),
),
row.WithStat(
"ETH Balance",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(ethBalancePanelSpanSize),
stat.Height("100px"),
stat.Decimals(2),
stat.WithPrometheusTarget(
`eth_balance{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{account}}"),
),
),
}

additionalPanels := []row.Option{
row.WithTimeSeries(
"Service Components Health",
timeseries.Span(12),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.WithPrometheusTarget(
`health{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{service_id}}"),
),
),
row.WithTimeSeries(
"ETH Balance",
timeseries.Span(12),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.Axis(
axis.Unit(""),
axis.Decimals(2),
),
timeseries.WithPrometheusTarget(
`eth_balance{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{account}}"),
),
),
}

panelsIncluded = append(panelsIncluded, globalInfoPanels...)
if m.platform == "kubernetes" {
panelsIncluded = append(panelsIncluded, row.WithStat(
"Pod Restarts",
stat.Span(2),
stat.Height("100px"),
Expand All @@ -24,97 +121,14 @@ func (m *Dashboard) addMainPanels() {
`sum(increase(kube_pod_container_status_restarts_total{pod=~"$instance.*", namespace=~"${namespace}"}[$__rate_interval])) by (pod)`,
prometheus.Legend("{{pod}}"),
),
)
ethBalancePanelSpanSize = 4
))
}
panelsIncluded = append(panelsIncluded, additionalPanels...)

opts := []dashboard.Option{
dashboard.Row(
"Global health",
row.WithStat(
"App Version",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Text("name"),
stat.Height("100px"),
stat.WithPrometheusTarget(
`version{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{version}}"),
),
),
row.WithStat(
"Go Version",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Text("name"),
stat.Height("100px"),
stat.WithPrometheusTarget(
`go_info{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{exported_version}}"),
),
),
row.WithStat(
"Uptime in days",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(2),
stat.Height("100px"),
stat.WithPrometheusTarget(
`uptime_seconds{`+m.panelOption.labelFilter+`=~"$instance"} / 86400`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}}"),
),
),
row.WithStat(
"ETH Balance",
stat.DataSource(m.PrometheusDataSourceName),
stat.Text(stat.TextValueAndName),
stat.Orientation(stat.OrientationVertical),
stat.TitleFontSize(12),
stat.ValueFontSize(20),
stat.Span(ethBalancePanelSpanSize),
stat.Height("100px"),
stat.Decimals(2),
stat.WithPrometheusTarget(
`eth_balance{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{account}}"),
),
),
podRestartPanel,
row.WithTimeSeries(
"Service Components Health",
timeseries.Span(12),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.WithPrometheusTarget(
`health{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{service_id}}"),
),
),
row.WithTimeSeries(
"ETH Balance",
timeseries.Span(12),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.Axis(
axis.Unit(""),
axis.Decimals(2),
),
timeseries.WithPrometheusTarget(
`eth_balance{`+m.panelOption.labelFilter+`=~"$instance"}`,
prometheus.Legend("{{"+m.panelOption.labelFilter+"}} - {{account}}"),
),
),
panelsIncluded...,
),
}

Expand All @@ -127,14 +141,34 @@ func (m *Dashboard) addKubePanels() {
"Pod health",
row.WithTimeSeries(
"Pod Restarts",
timeseries.Span(12),
timeseries.Span(4),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.WithPrometheusTarget(
`sum(increase(kube_pod_container_status_restarts_total{pod=~"$instance.*", namespace=~"${namespace}"}[$__rate_interval])) by (pod)`,
prometheus.Legend("{{pod}}"),
),
),
row.WithTimeSeries(
"OOM Events",
timeseries.Span(4),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.WithPrometheusTarget(
`sum(increase(container_oom_events_total{pod=~"$instance.*", namespace=~"${namespace}"}[$__rate_interval])) by (pod)`,
prometheus.Legend("{{pod}}"),
),
),
row.WithTimeSeries(
"OOM Killed",
timeseries.Span(4),
timeseries.Height("200px"),
timeseries.DataSource(m.PrometheusDataSourceName),
timeseries.WithPrometheusTarget(
`sum(increase(kube_pod_container_status_last_terminated_reason{reason="OOMKilled", pod=~"$instance.*", namespace=~"${namespace}"}[$__rate_interval])) by (pod)`,
prometheus.Legend("{{pod}}"),
),
),
row.WithTimeSeries(
"CPU Usage",
timeseries.Span(6),
Expand Down
10 changes: 10 additions & 0 deletions charts/chainlink-cluster/dashboard/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dashboard

func Contains[T comparable](arr []T, x T) bool {
for _, v := range arr {
if v == x {
return true
}
}
return false
}

0 comments on commit 393041d

Please sign in to comment.