【问题标题】:Send Pickled data to graphite将腌制数据发送到石墨
【发布时间】:2017-05-30 14:29:55
【问题描述】:

我正在生成具有数千个指标的多个文本文件,我想将它们作为pickled data 发送到石墨,而不是逐行循环以节省时间。我不熟悉python,所以如果有人有一个脚本应该如何做的例子。我对文本文件格式很灵活,我可以生成它以适应 python 和石墨所需的格式。 感谢帮助

【问题讨论】:

    标签: python pickle graphite


    【解决方案1】:
    from carbon_client import CarbonClient
    
    carbon = CarbonClient('localhost', 2004)
    
    pickle = []
    
    # loop through lines and add the metrics to pickle
    
    pickle.append((name, (time, result)))
    
    
    carbon.send_pickle(pickle)
    

    注意泡菜不要太大http://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol

    如果您计算放入泡菜的指标的大小,当泡菜达到一定大小时,您可以发送泡菜

    limit = 10 * 1024
                if size >= limit:
                    carbon.send_pickle(pickle)
                    size = 0
                    pickle = []
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      相关资源
      最近更新 更多