pyformance icon indicating copy to clipboard operation
pyformance copied to clipboard

Does'nt report the timer values in the influx

Open saikiran121993 opened this issue 6 years ago • 4 comments

Hi,

I am using the influx reporter when I run timer function there insertion in record with time but all the values are null, I can see mean value of the function using getmean() but there is no reflection of the timer values in influx DB. The code I am using is given below

reporter = InfluxReporter(registry, reporting_interval=1, database='mydatabase', server='myserver.local', username='myusername', password='mypassword', port='8186')
reporter.start()


time1 = registry.timer("func1_calls")

# def testTimer():
#     with timer("test").time():
#         print("I am from with statement")
#         print(timer("test").get_mean())
#         reporter.report_now()

@time_calls
def func1():
    print("Hey! I am from function 1")

while True:
        time.sleep(1)
        func1()

image

saikiran121993 avatar Mar 15 '19 09:03 saikiran121993

I haven't used this reporter myself. Feel free to offer a pull request with a fix and I'll gladly merge it

omergertel avatar Mar 15 '19 10:03 omergertel

A quick change in Timer Documentation instead of test_calls it should be just alias name when you are using with statement

from time import sleep
from pyformance import timer
with timer("test").time():
   sleep(0.1)
print(timer("test").get_mean())

Output: 0.10001015663146973

saikiran121993 avatar Mar 15 '19 12:03 saikiran121993

Your InfluxReporter is passing a registry to the constructor but the measured code is not creating timers from this registry.

Since you explicitly created a timer in this registry

time1 = registry.timer("func1_calls") but never timed anything against this, the "func1_calls" timer in registry will always have 0 values.

If you use the with style and reference a timer from the registry it will work:

` from time import sleep

from pyformance import timer
with registry.timer("test").time():
  sleep(0.1)
print(registry.timer("test").get_mean())`

bitchkat avatar Mar 15 '19 14:03 bitchkat

Thanks :+1: @bitchkat

saikiran121993 avatar Mar 18 '19 07:03 saikiran121993