使用Prometheus监视短暂的python批处理作业过程

时间:2019-02-28 07:15:19

标签: prometheus

如何使用Prometheus监视我的python进程(例如由cron守护程序定期触发的某些脚本)?

请注意,这不是Web应用程序,而是cron守护程序定期启动的短暂进程。该脚本启动,执行工作并终止。相同的python脚本一天被cron守护程序启动多次(大约10万次)。我想从该脚本的各种运行中捕获多个统计信息(例如:运行某个特定功能所花费的时间,所消耗的CPU和内存量等)

2 个答案:

答案 0 :(得分:1)

您可能想看看Prometheus' Pushgateway:每当脚本完成时,它就可以推送其收集的指标(例如,函数调用花费的时间,总CPU使用率,峰值内存使用率等的直方图)。

您似乎在说您的脚本大约每秒运行一次。我希望这意味着“每300名租户每5分钟一次”。在这种情况下,您可以使用tenant_id标签来推送指标,并能够查看按租户或汇总的指标。

如果您的脚本使用相同的参数/配置每秒运行一次,那么您可能会丢失一些指标,因为多个脚本可能会在同一秒内终止,所有脚本都按其指标,并且仅收集最后一个指标由Prometheus提供(我相信您不能将Prometheus中的收集间隔设置为低于1秒)。

答案 1 :(得分:1)

您可以使用pushgateway和prometheus_client

/usr/include/c++/9/bits/stl_vector.h:1061:34: runtime error: reference binding to null pointer of   type 'const struct value_type'
../../demos/ip_demo.cc:185:33: runtime error: member access within null pointer of type 'const struct   value_type'
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3862==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000020 (pc 0x00000047a8b4 bp   0x7ffe9e0042c0 sp 0x7ffe9e0042a0 T0)
==3862==The signal is caused by a READ memory access.
==3862==Hint: address points to the zero page.
    #0 0x47a8b3 in std::__uniq_ptr_impl<char, seastar::free_deleter>::_M_ptr() const /usr/include/c++/  9/bits/unique_ptr.h:154
    #1 0x465ac5 in std::unique_ptr<char [], seastar::free_deleter>::get() const /usr/include/c++/9/ bits/unique_ptr.h:612
    #2 0x46635d in std::unique_ptr<char [], seastar::free_deleter>::operator[](unsigned long) const (/  home/onqtam/seastar/build/debug/demos/ip_demo+0x46635d)
    #3 0x45b146 in sorter::get_next_temp_record(unsigned long) const (/home/onqtam/seastar/build/   debug/demos/ip_demo+0x45b146)
    #4 0x45b3fe in sorter::temp_cmp_functor::operator()(unsigned long, unsigned long) const (/home/ onqtam/seastar/build/debug/demos/ip_demo+0x45b3fe)
    #5 0x420298 in operator() ../../demos/ip_demo.cc:421
相关问题