Tools to make Grafana dashboards from templates
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

singlestat.py 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2015 Red Hat, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. import voluptuous as v
  15. from grafana_dashboards.schema.panel.base import Base
  16. class Singlestat(Base):
  17. def get_schema(self):
  18. # TODO(pabelanger): This is pretty ugly, there much be a better way to
  19. # set default values.
  20. sparkline_defaults = {
  21. 'fillColor': 'rgba(31, 118, 189, 0.18)',
  22. 'full': False,
  23. 'lineColor': 'rgb(31, 120, 193)',
  24. 'show': False,
  25. }
  26. sparkline = {
  27. v.Required(
  28. 'fillColor', default=sparkline_defaults['fillColor']
  29. ): v.All(str),
  30. v.Required('full', default=False): v.All(bool),
  31. v.Required(
  32. 'lineColor', default=sparkline_defaults['lineColor']
  33. ): v.All(str),
  34. v.Required('show', default=False): v.All(bool),
  35. }
  36. singlestat = {
  37. v.Required('colorBackground', default=False): v.All(bool),
  38. v.Required('colorValue', default=False): v.All(bool),
  39. v.Required('maxDataPoints', default=100): v.All(int),
  40. v.Required('postfix', default=''): v.All(str),
  41. # Support 0% to 200% by 10
  42. v.Required(
  43. 'postfixFontSize', default='50%'): v.All(
  44. v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
  45. v.Required('prefix', default=''): v.All(str),
  46. # Support 0% to 200% by 10
  47. v.Required(
  48. 'prefixFontSize', default='50%'): v.All(
  49. v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
  50. v.Required('sparkline', default=sparkline_defaults): sparkline,
  51. v.Required('targets', default=[]): v.All(list),
  52. v.Required('thresholds', default=''): v.All(str),
  53. # Support 0% to 200% by 10
  54. v.Required(
  55. 'valueFontSize', default='80%'): v.All(
  56. v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
  57. v.Required('valueName', default='avg'): v.Any(
  58. 'avg', 'current', 'max', 'min', 'total'),
  59. v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)),
  60. }
  61. singlestat.update(self.base)
  62. return v.Schema(singlestat)