PromCheatSheet.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { QueryEditorHelpProps } from '@grafana/data';
  3. import { PromQuery } from '../types';
  4. const CHEAT_SHEET_ITEMS = [
  5. {
  6. title: 'Request Rate',
  7. expression: 'rate(http_request_total[5m])',
  8. label:
  9. 'Given an HTTP request counter, this query calculates the per-second average request rate over the last 5 minutes.',
  10. },
  11. {
  12. title: '95th Percentile of Request Latencies',
  13. expression: 'histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le))',
  14. label: 'Calculates the 95th percentile of HTTP request rate over 5 minute windows.',
  15. },
  16. {
  17. title: 'Alerts Firing',
  18. expression: 'sort_desc(sum(sum_over_time(ALERTS{alertstate="firing"}[24h])) by (alertname))',
  19. label: 'Sums up the alerts that have been firing over the last 24 hours.',
  20. },
  21. {
  22. title: 'Step',
  23. label:
  24. 'Defines the graph resolution using a duration format (15s, 1m, 3h, ...). Small steps create high-resolution graphs but can be slow over larger time ranges. Using a longer step lowers the resolution and smooths the graph by producing fewer datapoints. If no step is given the resolution is calculated automatically.',
  25. },
  26. ];
  27. const PromCheatSheet = (props: QueryEditorHelpProps<PromQuery>) => (
  28. <div>
  29. <h2>PromQL Cheat Sheet</h2>
  30. {CHEAT_SHEET_ITEMS.map((item, index) => (
  31. <div className="cheat-sheet-item" key={index}>
  32. <div className="cheat-sheet-item__title">{item.title}</div>
  33. {item.expression ? (
  34. <div
  35. className="cheat-sheet-item__example"
  36. onClick={(e) => props.onClickExample({ refId: 'A', expr: item.expression })}
  37. >
  38. <code>{item.expression}</code>
  39. </div>
  40. ) : null}
  41. <div className="cheat-sheet-item__label">{item.label}</div>
  42. </div>
  43. ))}
  44. </div>
  45. );
  46. export default PromCheatSheet;