1.查看环境https://www.cndba.cn/hbhe0316/article/106580
https://www.cndba.cn/hbhe0316/article/106580
[root@njmon home]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@njmon home]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.131 njmon
2.安装njmonhttps://sourceforge.net/projects/nmon/files/
[root@njmon home]# wget http://sourceforge.net/projects/nmon/files/njmon_linux_binaries_v53.zip
[root@njmon home]# unzip njmon_linux_binaries_v53.zip
[root@njmon home]# mv njmon_linux_RHEL7_AMD64_v53 /usr/local/bin/njmon
[root@njmon home]# chmod +x /usr/local/bin/njmon
[root@njmon home]# njmon -?
njmon: help information. Version:53@10/02/2020
- Performance stats collector outputing JSON format. Default is stdout
- Core syntax: njmon -s seconds -c count
- File output: -m directory -f
- njmon collector output: -i host -p port -X secret
- All options: -?
-s seconds : seconds between snapshots of data (default 60 seconds)
-c count : number of snapshots (default forever)
-m directory : Program will cd to the directory before output
-f : Output to file (not stdout) to two files below
: Data: hostname_<year><month><day>_<hour><minutes>.json
: Error: hostname_<year><month><day>_<hour><minutes>.err
-k : Read /tmp/njmon.pid for a running njmon PID & if found running then this copy exits
-P : Add process stats (take CPU cycles and large stats volume)
-t percent : Set ignore process percent threshold (default 0.01%)
-? or -h : This output and stop
-d : Switch on debug tracing (output will no longer be JSON format)
-w : Switch off warning messages in error output stream
-r : Random pause at the start. Stops cron starting every njmon in sync.
Push data to collector:
-i ip : IP address or hostname of the njmon central collector
-p port : port number on collector host
-X secret : Set the remote collector secret or use shell NJMON_SECRET
Examples:
1 Every 5 mins all day
/home/nag/njmon -s 300 -c 288 -f -m /home/perf
2 Piping to data handler using half a day
/home/nag/njmon -s 30 -c 1440 | myprog
3 Use the defaults (-s 60 forever) and save to a file
./njmon > my_server_today.json
4 Crontab entry
0 4 * * * /home/nag/njmon -s 300 -c 288 -f -m /home/perf
5 Crontab - hourly check/restart remote njmon, pipe stats back & insert into local DB
* 0 * * * /usr/bin/ssh nigel@server /usr/lbin/njmon -k -s 300 -c 288 | /usr/local/bin/injector
6 Crontab - for pumping data to the njmon central collector
* 0 * * * /usr/local/bin/njmon -s 300 -c 288 -i admin.acme.com -p 8181 -X SECRET42
* 0 * * * export NJMON_SECRET=abc123 && /usr/local/bin/njmon -s 300 -c 288 -i influx -p 8181
* 0 * * * export NJMON_SECRET=abc123 && /usr/local/bin/njmon -s 60 -k -i influx -p 8181
[root@njmon home]# yum install jq python3 -y
[root@njmon home]# njmon -c 1 -s 1 | jq keys
[
"cpu_total",
"cpuinfo",
"cpus",
"disks",
"filesystems",
"identity",
"lscpu",
"networks",
"os_release",
"proc_meminfo",
"proc_version",
"proc_vmstat",
"stat_counters",
"timestamp",
"uptime_output"
]
安装njmon_toolshttps://www.cndba.cn/hbhe0316/article/106580
[root@njmon home]# wget http://sourceforge.net/projects/nmon/files/njmon_tools_v50.zip
[root@njmon home]# unzip njmon_tools_v50.zip
[root@njmon njmon_tools_v50]# cat njmond.conf
{
"njmon_port": 8181,
"njmon_secret": "ignore",
"data_inject": false,
"data_json": true,
"directory": "/home/data",
"influx_host": "localhost",
"influx_port": 8086,
"influx_user": "admin",
"influx_password": "wwwwww",
"influx_dbname": "njmon",
"workers": 2,
"debug": true,
# for njmon2influx.py
"batch": 100
}
采集数据https://www.cndba.cn/hbhe0316/article/106580https://www.cndba.cn/hbhe0316/article/106580https://www.cndba.cn/hbhe0316/article/106580https://www.cndba.cn/hbhe0316/article/106580
[root@njmon njmon_tools_v50]# njmon -s 5 | ./njmon2influx.py njmond.conf
{'njmon_port': 8181, 'njmon_secret': 'ignore', 'data_inject': False, 'data_json': True, 'directory': '/home/data', 'influx_host': 'localhost', 'influx_port': 8086, 'influx_user': 'admin', 'influx_password': 'wwwwww', 'influx_dbname': 'njmon', 'workers': 2, 'debug': True, 'batch': 100}
Traceback (most recent call last):
File "./njmon2influx.py", line 225, in <module>
from influxdb import InfluxDBClient
ModuleNotFoundError: No module named 'influxdb'
[root@njmon ~]# pip3 install influxdb
[root@njmon njmon_tools_v50]# nohup njmon -s 5 | ./njmon2influx.py njmond.conf >/dev/null 2>&1 &
[root@njmon data]# tail -f /home/njmon/data/njmon2influx.log
2022-01-20 20:49:58,snap=100,njmon,db=njmon,json-size=10722,measure-size=,3700
InfluxDB查询数据
https://www.cndba.cn/hbhe0316/article/106580
https://www.cndba.cn/hbhe0316/article/106580
https://www.cndba.cn/hbhe0316/article/106580
[root@njmon njmon_tools_v50]# influx -username admin -password wwwwww
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> use njmon
Using database njmon
> show measurements
name: measurements
name
----
cpu_total
cpuinfo
cpus
disks
filesystems
identity
lscpu
networks
os_release
proc_meminfo
proc_version
proc_vmstat
stat_counters
timestamp
uptime_output
版权声明:本文为博主原创文章,未经博主允许不得转载。
LINUX