PromCheatSheet.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import { ExploreStartPageProps, DataQuery } from '@grafana/ui';
  3. const CHEAT_SHEET_ITEMS = [
  4. {
  5. title: 'Request Rate',
  6. expression: 'rate(http_request_total[5m])',
  7. label:
  8. 'Given an HTTP request counter, this query calculates the per-second average request rate over the last 5 minutes.',
  9. },
  10. {
  11. title: '95th Percentile of Request Latencies',
  12. expression: 'histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le))',
  13. label: 'Calculates the 95th percentile of HTTP request rate over 5 minute windows.',
  14. },
  15. {
  16. title: 'Alerts Firing',
  17. expression: 'sort_desc(sum(sum_over_time(ALERTS{alertstate="firing"}[24h])) by (alertname))',
  18. label: 'Sums up the alerts that have been firing over the last 24 hours.',
  19. },
  20. ];
  21. export default (props: ExploreStartPageProps) => (
  22. <div>
  23. <h2>PromQL Cheat Sheet</h2>
  24. {CHEAT_SHEET_ITEMS.map(item => (
  25. <div className="cheat-sheet-item" key={item.expression}>
  26. <div className="cheat-sheet-item__title">{item.title}</div>
  27. <div
  28. className="cheat-sheet-item__example"
  29. onClick={e => props.onClickExample({ refId: 'A', expr: item.expression } as DataQuery)}
  30. >
  31. <code>{item.expression}</code>
  32. </div>
  33. <div className="cheat-sheet-item__label">{item.label}</div>
  34. </div>
  35. ))}
  36. </div>
  37. );