Skip to content

odis-labs/refana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Refana

Define Grafana dashboards with ReasonML.

Usage

Defining metrics

let cpu = (~name) =>
  Grafana.(Query.prometheus(Prometheus_query {
    "id": "CPU",
    "expr": fmt("rate(cpu_seconds{container_name=~'%s'}[30s])", name),
    "format": "time_series",
    "legend": "cpu_seconds@{{pod_name}}"
  }));

let mem = (~name) =>
  Grafana.(Query.prometheus(Prometheus_query {
    "id": "MEM",
    "expr": fmt("sum(memory_rss{container_name=~'%s'}) by (pod_name)", name),
    "format": "time_series",
    "legend": "memory_rss@{{pod_name}}"
  }));

Creating panels

let name = "my-app";

let metrics = Grafana.[
  Panel.row(Row {
    "title": "My metrics",
    "position": size(~width=24, ~height=1),
  }),

  Panel.graph(Graph {
    "title": "Container CPU usage",
    "position": size(~width=12, ~height=9),
    "queries": [cpu(~name)]
  }),
  Panel.graph(Graph {
    "title": "Container memory usage",
    "position": size(~width=12, ~height=9),
    "queries": [Std.Grafana.Metrics.mem(~name)]
  })
];

Creating dashboards

let dash = Grafana.Dashboard {
  "title": "My Monitoring Dashboard",
  "panels": Grafana.panels([metrics])
}

Releases

No releases published

Packages

No packages published