Grahite, Carbon, CollectD, StatsD - Помеченные серии в программе Python - PullRequest
0 голосов
/ 19 октября 2018

Я пытаюсь запустить некоторые модули / рабочие процессы / рабочие нагрузки некоторых модулей Python / других языков и собрать данные об использовании ресурсов процессора, памяти, ввода-вывода и т. Д. С помощью Grahite, Carbon, CollectD, StatsD.Я прочитал документацию (см .: здесь ) о создании помеченных серий, но я не могу найти, как пометить определенные луки.Например, у меня есть два модуля

Первый модуль

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

1 Ответ

0 голосов
/ 26 октября 2018

Несмотря на то, что я не использовал помеченную серию, я решил описанную выше проблему, написав скрипт bash и используя рендер 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
...