项目作者: yoheimuta

项目描述 :
Monitor each process metrics avg using each pidfile
高级语言: Perl
项目地址: git://github.com/yoheimuta/Linux-GetPidstat.git
创建时间: 2016-05-28T02:09:21Z
项目社区:https://github.com/yoheimuta/Linux-GetPidstat

开源协议:Other

下载




NAME

Linux::GetPidstat - Monitor each process metrics avg using each pidfile

SYNOPSIS

  1. use Linux::GetPidstat;
  2. my $stat = Linux::GetPidstat->new;
  3. $stat->run(%opt);

DESCRIPTION

Run pidstat -h -u -r -s -d -w -p $pid $interval $count commands in parallel to monitor each process metrics avg/1min.

Output to a specified file [and|or] mackerel service https://mackerel.io.

Motivation

A batch server runs many batch scripts at the same time.

When this server suffers by a resource short, it’s difficult to grasp which processes are heavy quickly.

Running pidstat manually is not appropriate in this situation, because

  • the target processes are changed by starting each job.
  • the target processes may run child processes recursively.

Requirements

pidstat
pstree

Usage

Prepare pid files in a specified directory.

  1. $ mkdir /tmp/pid_dir
  2. $ echo 1234 > /tmp/pid_dir/target_script
  3. $ echo 1235 > /tmp/pid_dir/target_script2
  4. # In production, this file is made and removed by the batch script itself for instance.

Run the script every 1 mininute.

  1. # vi /etc/cron.d/linux-get-pidstat
  2. * * * * * user carton exec -- linux-get-pidstat --no-dry_run --pid_dir=/tmp/pid_dir --res_dir=/tmp/bstat.log

Done, you can monitor the result.

  1. $ tail -f /tmp/bstat.log
  2. # start(datetime),start(epoch),pidfilename,name,value
  3. 2016-04-02T19:49:32,1459594172,target_script,cswch_per_sec,19.87
  4. 2016-04-02T19:49:32,1459594172,target_script,stk_ref,25500
  5. 2016-04-02T19:49:32,1459594172,target_script,memory_percent,34.63
  6. 2016-04-02T19:49:32,1459594172,target_script,memory_rss,10881534000
  7. 2016-04-02T19:49:32,1459594172,target_script,stk_size,128500
  8. 2016-04-02T19:49:32,1459594172,target_script,nvcswch_per_sec,30.45
  9. 2016-04-02T19:49:32,1459594172,target_script,cpu,21.2
  10. 2016-04-02T19:49:32,1459594172,target_script,disk_write_per_sec,0
  11. 2016-04-02T19:49:32,1459594172,target_script,disk_read_per_sec,0
  12. 2016-04-02T19:49:32,1459594172,target_script2,memory_rss,65289204000
  13. 2016-04-02T19:49:32,1459594172,target_script2,memory_percent,207.78
  14. 2016-04-02T19:49:32,1459594172,target_script2,stk_ref,153000
  15. 2016-04-02T19:49:32,1459594172,target_script2,cswch_per_sec,119.22
  16. 2016-04-02T19:49:32,1459594172,target_script2,nvcswch_per_sec,182.7
  17. 2016-04-02T19:49:32,1459594172,target_script2,cpu,127.2
  18. 2016-04-02T19:49:32,1459594172,target_script2,disk_read_per_sec,0
  19. 2016-04-02T19:49:32,1459594172,target_script2,disk_write_per_sec,0
  20. 2016-04-02T19:49:32,1459594172,target_script2,stk_size,771000

Mackerel

Post the results to service metrics.

  1. $ carton exec -- linux-get-pidstat \
  2. --no-dry_run \
  3. --pid_dir=/tmp/pid_dir \
  4. --mackerel_api_key=yourkey \
  5. --mackerel_service_name=yourservice

Help

Display how to use.

  1. $ carton exec -- linux-get-pidstat --help
  2. Usage:
  3. linux-get-pidstat - command description
  4. Usage: command [options]
  5. Options:
  6. --pid_dir A directory path for pid files
  7. --res_file A file path to be stored results
  8. --interval Interval second to be given as a pidstat argument (default:1)
  9. --count Count number to be given as a pidstat argument (default:60)
  10. --dry_run Dry run mode. not run the side-effects operation (default:1) (--no-dry_run is also supported)
  11. --datetime Datetime (ex. '2016-06-10 00:00:00') to be recorded
  12. --include_child Flag to be enabled to include child process metrics (default:1) (--no-include_child is also suppoted)
  13. --max_child_limit Number to be used for limiting pidstat multi processes (default:30) (skip this limit if 0 is specified)
  14. --mackerel_metric_type Metric type of mackerel (default:service) (only use one of 'service' or 'host')
  15. --mackerel_api_key An api key to be used for posting to mackerel
  16. --mackerel_service_name An mackerel service name
  17. --mackerel_metric_key_prefix Key prefix of mackerel metric name (default:batch_)
  18. --mackerel_host_id An mackerel host id
  19. Requirement Programs: pidstat and pstree commands

LICENSE

Copyright (C) yoheimuta.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

AUTHOR

yoheimuta yoheimuta@gmail.com