Console templates

Console templates allow for creation of arbitrary consoles using the Gotemplating language. These are servedfrom the Prometheus server.

Console templates are the most powerful way to create templates that can beeasily managed in source control. There is a learning curve though, so users newto this style of monitoring should try outGrafana first.

Getting started

Prometheus comes with an example set of consoles to get you going. These can befound at /consoles/index.html.example on a running Prometheus and willdisplay Node Exporter consoles if Prometheus is scraping Node Exporters with ajob="node" label.

The example consoles have 5 parts:

  • A navigation bar on top
  • A menu on the left
  • Time controls on the bottom
  • The main content in the center, usually graphs
  • A table on the rightThe navigation bar is for links to other systems, such as other Prometheis1,documentation, and whatever else makes sense to you. The menu is for navigationinside the same Prometheus server, which is very useful to be able to quicklyopen a console in another tab to correlate information. Both are configured inconsole_libraries/menu.lib.

The time controls allow changing of the duration and range of the graphs.Console URLs can be shared and will show the same graphs for others.

The main content is usually graphs. There is a configurable JavaScript graphinglibrary provided that will handle requesting data from Prometheus, and renderingit via Rickshaw.

Finally, the table on the right can be used to display statistics in a morecompact form than graphs.

Example Console

This is a basic console. It shows the number of tasks, how many of them are up,the average CPU usage, and the average memory usage in the right-hand-sidetable. The main content has a queries-per-second graph.

  1. {{template "head" .}}
  2. {{template "prom_right_table_head"}}
  3. <tr>
  4. <th>MyJob</th>
  5. <th>{{ template "prom_query_drilldown" (args "sum(up{job='myjob'})") }}
  6. / {{ template "prom_query_drilldown" (args "count(up{job='myjob'})") }}
  7. </th>
  8. </tr>
  9. <tr>
  10. <td>CPU</td>
  11. <td>{{ template "prom_query_drilldown" (args
  12. "avg by(job)(rate(process_cpu_seconds_total{job='myjob'}[5m]))"
  13. "s/s" "humanizeNoSmallPrefix") }}
  14. </td>
  15. </tr>
  16. <tr>
  17. <td>Memory</td>
  18. <td>{{ template "prom_query_drilldown" (args
  19. "avg by(job)(process_resident_memory_bytes{job='myjob'})"
  20. "B" "humanize1024") }}
  21. </td>
  22. </tr>
  23. {{template "prom_right_table_tail"}}
  24. {{template "prom_content_head" .}}
  25. <h1>MyJob</h1>
  26. <h3>Queries</h3>
  27. <div id="queryGraph"></div>
  28. <script>
  29. new PromConsole.Graph({
  30. node: document.querySelector("#queryGraph"),
  31. expr: "sum(rate(http_query_count{job='myjob'}[5m]))",
  32. name: "Queries",
  33. yAxisFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
  34. yHoverFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
  35. yUnits: "/s",
  36. yTitle: "Queries"
  37. })
  38. </script>
  39. {{template "prom_content_tail" .}}
  40. {{template "tail"}}

The prom_right_table_head and prom_right_table_tail templates contain theright-hand-side table. This is optional.

prom_query_drilldown is a template that will evaluate the expression passed to it, format it,and link to the expression in the expression browser. The firstargument is the expression. The second argument is the unit to use. The thirdargument is how to format the output. Only the first argument is required.

Valid output formats for the third argument to prom_query_drilldown:

  • Not specified: Default Go display output.
  • humanize: Display the result using metric prefixes.
  • humanizeNoSmallPrefix: For absolute values greater than 1, display theresult using metric prefixes. Forabsolute values less than 1, display 3 significant digits. This is usefulto avoid units such as milliqueries per second that can be produced byhumanize.
  • humanize1024: Display the humanized result using a base of 1024 rather than 1000.This is usually used with B as the second argument to produce units such as KiB and MiB.
  • printf.3g: Display 3 significant digits.Custom formats can be defined. Seeprom.lib for examples.

Graph Library

The graph library is invoked as:

  1. <div id="queryGraph"></div>
  2. <script>
  3. new PromConsole.Graph({
  4. node: document.querySelector("#queryGraph"),
  5. expr: "sum(rate(http_query_count{job='myjob'}[5m]))"
  6. })
  7. </script>

The head template loads the required Javascript and CSS.

Parameters to the graph library:

NameDescription
exprRequired. Expression to graph. Can be a list.
nodeRequired. DOM node to render into.
durationOptional. Duration of the graph. Defaults to 1 hour.
endTimeOptional. Unixtime the graph ends at. Defaults to now.
widthOptional. Width of the graph, excluding titles. Defaults to auto-detection.
heightOptional. Height of the graph, excluding titles and legends. Defaults to 200 pixels.
minOptional. Minimum x-axis value. Defaults to lowest data value.
maxOptional. Maximum y-axis value. Defaults to highest data value.
rendererOptional. Type of graph. Options are line and area (stacked graph). Defaults to line.
nameOptional. Title of plots in legend and hover detail. If passed a string, [[ label ]] will be substituted with the label value. If passed a function, it will be passed a map of labels and should return the name as a string. Can be a list.
xTitleOptional. Title of the x-axis. Defaults to Time.
yUnitsOptional. Units of the y-axis. Defaults to empty.
yTitleOptional. Title of the y-axis. Defaults to empty.
yAxisFormatterOptional. Number formatter for the y-axis. Defaults to PromConsole.NumberFormatter.humanize.
yHoverFormatterOptional. Number formatter for the hover detail. Defaults to PromConsole.NumberFormatter.humanizeExact.
colorSchemeOptional. Color scheme to be used by the plots. Can be either a list of hex color codes or one of the color scheme names supported by Rickshaw. Defaults to 'colorwheel'.

If both expr and name are lists, they must be of the same length. The namewill be applied to the plots for the corresponding expression.

Valid options for the yAxisFormatter and yHoverFormatter:

  • PromConsole.NumberFormatter.humanize: Format using metric prefixes.
  • PromConsole.NumberFormatter.humanizeNoSmallPrefix: For absolute valuesgreater than 1, format using using metric prefixes.For absolute values less than 1, format with 3 significant digits. This isuseful to avoid units such as milliqueries per second that can be produced byPromConsole.NumberFormatter.humanize.
  • PromConsole.NumberFormatter.humanize1024: Format the humanized result using a base of 1024 rather than 1000.