前言:
现时咱们对“jenkins执行python”大约比较重视,小伙伴们都需要知道一些“jenkins执行python”的相关内容。那么小编同时在网摘上网罗了一些对于“jenkins执行python””的相关知识,希望同学们能喜欢,你们快快来了解一下吧!监控Jenkins,我们需要到Jenkins机器上面部署一个Jenkins-exporter。
这个是官网提供的链接,只能针对Jenkin http的连接。相对于开启HTTPS连接的Jenkins,还是建议用jenkins 插件的方式。
1.下载jenkins-exporter
使用pyhotn2就可以了,但是要有pip命令,用下面命令安装pipsudo easy_install pip下载jenkins-exportergit clone git@github.com:lovoo/jenkins_exporter.gitcd jenkins_exporter安装python依赖prometheus-client 和requestspip install -r requirements.txt如果外网环境,需要手工下载包安装2.安装Jenkins
安装java环境yum install java-1.8.0-openjdk-devel下载jenkins源wget -O /etc/yum.repos.d/jenkins.repo 导入keyrpm --import 安装jenkinsyum install jenkins -y启动jenkinssystemctl start jenkinssystemctl status jenkins检查端口是否起来netstat -an|grep 80803.Jenkins初始化
登陆 jenkins 页面
3.启动jenkins-exporter
前面下载了jenkins-exporter脚本,这里我们可以手工运行一下。
cd jenkins_exporterpython jenkins_exporter.py -j --user admin --password admin -p 9118 Polling . Serving at port: 9118说明:-j jenkin的URL--user 登陆用户--passowrd 密码-p jenkins_exporter暴露端口,供Prometheus连接
设置jenkins_exporter启动服务
echo '[Unit]Description=Jenkins_expoter[Service]ExecStart=/bin/python /root/prometheus/jenkins_exporter/jenkins_exporter.py -j --user admin --password admin -p 9118 [Install]WantedBy=multi-user.target' >/etc/systemd/system/jenkins_exporter.service启动添加后的系统服务systemctl daemon-reloadsystemctl restart jenkins_exporter.servicenetstat -an|grep 91184.修改Prometheus配置文件
Prometheus配置文件/etc/prometheus/prometheus.yml,添加如下内容:
scrape_configs: - job_name: 'jenkins' # 静态添加node static_configs: # 指定监控端 - targets: ['localhost:9118']
重启Prometheus
systemctl restart prometheus
查看Prometheus Target ,看到如下界面,说明配置成功。
查看
# HELP jenkins_collector_collect_seconds Time spent to collect metrics from Jenkins# TYPE jenkins_collector_collect_seconds summaryjenkins_collector_collect_seconds_count 111.0jenkins_collector_collect_seconds_sum 18.111268043518066# HELP process_virtual_memory_bytes Virtual memory size in bytes.# TYPE process_virtual_memory_bytes gaugeprocess_virtual_memory_bytes 463200256.0# HELP process_resident_memory_bytes Resident memory size in bytes.# TYPE process_resident_memory_bytes gaugeprocess_resident_memory_bytes 19058688.0# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.# TYPE process_start_time_seconds gaugeprocess_start_time_seconds 1611292574.2# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.# TYPE process_cpu_seconds_total counterprocess_cpu_seconds_total 4.36# HELP process_open_fds Number of open file descriptors.# TYPE process_open_fds gaugeprocess_open_fds 8.0# HELP process_max_fds Maximum number of open file descriptors.# TYPE process_max_fds gaugeprocess_max_fds 1024.0# HELP python_info Python platform information# TYPE python_info gaugepython_info{implementation="CPython",major="2",minor="7",patchlevel="5",version="2.7.5"} 1.0
笔者有话要说:
由于jenkins-exporter这个方法抓取的数据比较少,而且grafana上面的模板也没有,不建议用这个方法。后面还会出Jenkins插件安装exporter的方法。
标签: #jenkins执行python