Enter code here...
# ...
# Open Txt file
file_loc = join(receive_dir, filename)
f = open(file_loc, "r")
I'm using some counters and summary... but they not incrementing, assuming the problem is because the multi processing is happening in a memory space where they can't get access to my counter objects.
Hi guysBattling to get this working, some assistance would be appreciated.I'm watching a directory, when files land I kick off independent threaded multiprocessing jobs to load in parallel the files, code below.I'm using some counters and summary... but they not incrementing, assuming the problem is because the multi processing is happening in a memory space where they can't get access to my counter objects.Neither FILE_GESTER_TIME nor FILE_GESTER_LINE_COUNT is incrementing when I hit the url:8000Please advise how I need to change the code to make this work,
--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/bb1b1937-9df6-4750-a443-1d4c4280a26a%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/1bf23637-461d-45e0-84e6-a9450599f1fb%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/843f35f3-0a6d-47f1-bf4e-c1cfb68f408a%40googlegroups.com.
Enter code here...
import logging, sys, time
import random
from datetime import datetime
from prometheus_client import start_http_server, Summary, Counter, multiprocess
import multiprocessing
# Prometheus metrics
FILE_GESTER_TIME = Summary('BSA_file_gester_eft_worker', 'Time spent loading eft files')
FILE_GESTER_LINE_COUNT = Counter('BSA_file_gester_eft_line_count', 'Running counter of eft lines loaded')
@FILE_GESTER_TIME.time()
def worker( random_count ):
counter = 0
while counter < random_count:
FILE_GESTER_LINE_COUNT.inc()
counter += 1
print(random_count, ' ', counter)
time.sleep(1/5)
return
# end worker
def main():
start_time = datetime.now()
print('* Start Time :', start_time)
print('')
try:
# Start up the server to expose the metrics.
start_http_server(8010)
# Step 1: Init multiprocessing.Pool()
pool = multiprocessing.Pool(4)
x = 0
while x < 4:
# This works, this ends as a serial completing, worker one after the other
#worker(random.randint(10, 120))
# This does not increment counters, this is suppose to place the working each in his own work space, so that all 4 basically run in parrallel
pool.apply_async(worker, ( random.randint(10, 120), ))
x += 1
pool.close()
pool.join() # Sleep here until all workers are done
except KeyboardInterrupt:
print('Shutting Down Unexpectedly')
sys.stdout.flush()
sys.exit(-1)
except Exception as ex:
print("Failed to create worker {err}".format(err=ex))
finally:
print('')
print('Shutting Down')
finish_time = datetime.now()
run_time = finish_time - start_time
print('* Total Run Time :', run_time)
# end main(
if __name__ == '__main__':
logging.basicConfig(
format='%(asctime)s.%(msecs)s:%(name)s:%(thread)d:%(levelname)s:%(process)d:%(message)s',
level=logging.INFO
)
main()
# end __name__ == '__main__'
Hi BrianOk So i've seen this note/link before... I'll just call myself stupid, don't need someone else to confirm it, I've not been able to map whats there onto my example and get it working.That app module, is that my worker module, or is that a module i leave as is in the code. I use summary and count variables with their build in functions, time and count as per Prometheus design,If anyone is willing to help me with a more complete example, decorate my code with how to map this to mine would really be appreciated.G
On Wed, Jan 22, 2020 at 10:27 PM Brian Candler <b.ca...@pobox.com> wrote:
Brian B is right: I'd completely forgotten about the multiprocess support built into the python client.--It's used, for example, by Netbox.
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/843f35f3-0a6d-47f1-bf4e-c1cfb68f408a%40googlegroups.com.
Enter code here...