graphite custom functions

曲珂發表於2019-01-26

尊重作者的勞動,轉載請註明作者及原文地址 http://www.cnblogs.com/txwsqk/p/6522854.html 

參考 https://graphite.readthedocs.io/en/latest/functions.html#function-plugins

/opt/graphite/webapp/graphite/settings.py 

# Function plugins
FUNCTION_PLUGINS = ['linkedme.aliasByMap',]

 

/opt/graphite/webapp/graphite/functions/custom# ls
__init__.py  __init__.pyc  linkedme.py  linkedme.pyc

我新增了一個自定義函式  cat linkedme.py

#coding:utf-8
from graphite.functions.params import Param, ParamTypes

def aliasByMap(requestContext, seriesList):
  kv = {
    '4000054':'你想展示的內容',
  }
  for series in seriesList:
    series.name = kv[series.name]
  return seriesList

aliasByMap.group = 'Alias'
aliasByMap.params = [
  Param('seriesList', ParamTypes.seriesList, required=True),
]

SeriesFunctions = {
  'aliasByMap': aliasByMap,
}

這樣 grafana 中就可以使用了

 

相關文章