【问题标题】:Grahite, Carbon, CollectD, StatsD - Tagged Series in Python ProgramGraphite、Carbon、CollectD、StatsD - Python 程序中的标记系列
【发布时间】:2018-10-19 17:13:07
【问题描述】:

我正在尝试运行一些 python/其他语言模块模块/工作流/工作负载,并使用 Grahite、Carbon、CollectD、StatsD 收集它们的 CPU、Mem、I/O 等资源使用情况。我已阅读有关创建标记系列的文档(请参阅:here),但我似乎无法找到如何标记特定模块。例如,我有两个模块

第一个模块

def firstModule:
    # Initialize a list
    primes = []

    for possiblePrime in range(2, 21):
       # Assume number is prime until shown it is not. 

       isPrime = True

       for num in range(2, possiblePrime):
          if possiblePrime % num == 0:
          isPrime = False

    if isPrime:
        primes.append(possiblePrime)

第二模块

def secondModule:
    # Initialize a list

    primes = []

    for possiblePrime in range(2, 21):

        # Assume number is prime until shown it is not. 

        isPrime = True

        for num in range(2, possiblePrime):
            if possiblePrime % num == 0:
            isPrime = False
            break

    if isPrime:
        primes.append(possiblePrime)

这里我想调用这两个模块,然后标记资源使用指标,以便我可以将其发送到 Whisper 数据库,如下面的代码所示:我该如何实现?

firstModule() # assign some tag say A
secondModule() # assign some tag say B

【问题讨论】:

    标签: python resources metrics graphite graphite-carbon


    【解决方案1】:

    虽然我最终没有使用带标签的系列,但我已经通过编写 bash 脚本并在石墨中使用 render api 解决了上述问题。这是解决方案:

        #!/bin/bash   
    
        #Remove previous records. Be careful not to remove useful files!
        rm cpu.json, mem.json
    
        #clear variables for storing time 
        unset start
        unset finish
    
        #log start time of process using absolute time, if using relative time check doc at https://graphite.readthedocs.io/en/latest/render_api.html for rules
        start=$(date '+%H:%M_%Y%m%d')
    
        #call first module
        firstModule()
    
        #sleep 1 minute or more because you will get an error that start time and end time are equal
        sleep 100
    
        #call second module
        secondModule()
    
        #log finish date using absolute time, if using relative time check  doc at https://graphite.readthedocs.io/en/latest/render_api.html) for rules
        finish=$(date '+%H:%M_%Y%m%d')
    
        #collect data using curl here cpu usage and memusage, adjust to fit your setup and Voila!
        curl "http://host/render?target=carbon.agents.*.cpuUsage&width=500&height=300&from={$start}&until={$finish}&format=json" > cpu.json
        sudo curl "http://host/render?target=collectdlocalhost.memory.memory-used&width=500&height=300&from={$start}&until={$finish}&format=json" > mem.json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多