Linux下安装代码统计工具git_stats

(一)、简介
git_stats:仓库代码统计工具之一,可以按git提交人、提交次数、修改文件数、代码行数、注释量在时间维度上进行统计,亦可按各文件类型进行简单的统计,非常方便.

虽然以代码行数来衡量项目或者程序员并不是一件靠谱的事,但是从统计角度看趋势对于技术管理人员还是很有帮助的!GitStats就是这样的工具,它能生成以下统计数据,并以图表形式进行对比

  • 常规的统计:文件总数,行数,提交量,作者数。
  • 活跃性:每天中每小时的、每周中每天的、每周中每小时的、每年中每月的、每年的提交量。
  • 作者数:列举所有的作者(提交数,第一次提交日期,最近一次的提交日期),并按月和年来划分。
  • 文件数:按日期划分,按扩展名名划分。
  • 行数:按日期划分。

(二)、安装和相关的配置
1、下载安装ruby,由于节省时间才有yum进行安装。

[root@zabbix-server data]# yum install ruby -y
已加载插件:fastestmirror
base                                                                    | 3.6 kB  00:00:00     
epel                                                                    | 5.3 kB  00:00:00     
extras                                                                  | 3.4 kB  00:00:00     
nginx                                                                   | 2.9 kB  00:00:00     
nux-dextop                                                              | 2.9 kB  00:00:00     
rpmfusion-free-updates                                                  | 3.0 kB  00:00:00     
rpmfusion-nonfree-updates                                               | 3.0 kB  00:00:00     
updates                                                                 | 3.4 kB  00:00:00     
  验证中      : rubygem-io-console-0.4.2-35.el7_6.x86_64                                   9/9 

已安装:
  ruby.x86_64 0:2.0.0.648-35.el7_6                                                             

作为依赖被安装:
  ruby-irb.noarch 0:2.0.0.648-35.el7_6           ruby-libs.x86_64 0:2.0.0.648-35.el7_6         
  rubygem-bigdecimal.x86_64 0:1.2.0-35.el7_6     rubygem-io-console.x86_64 0:0.4.2-35.el7_6    
  rubygem-json.x86_64 0:1.7.7-35.el7_6           rubygem-psych.x86_64 0:2.0.0-35.el7_6         
  rubygem-rdoc.noarch 0:4.0.0-35.el7_6           rubygems.noarch 0:2.0.14.1-35.el7_6           

完毕!
[root@zabbix-server data]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux

2、添加ruby国内阿里云仓库来提高访问速度,并删除国外访问的仓库。

[root@zabbix-server data]# gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/
[root@zabbix-server data]# gem sources -a http://mirrors.aliyun.com/rubygems/ --remove https://rubygems.org/
http://mirrors.aliyun.com/rubygems/ added to sources
https://rubygems.org/ removed from sources
[root@zabbix-server data]# gem sources -l
*** CURRENT SOURCES ***
http://mirrors.aliyun.com/rubygems/

3、安装RAM管理工具。RAM(Ruby Version Manager )是一款RAM的命令行工具,可以使用RAM轻松安装,管理Ruby版本。RVM包含了Ruby的版本管理和Gem库管理(gemset)
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable

[root@zabbix-server data]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: 下载密钥‘D39DC0E3’,从 hkp 服务器 keys.gnupg.net
gpg: 下载密钥‘39499BDB’,从 hkp 服务器 keys.gnupg.net
gpg: 密钥 D39DC0E3:“Michal Papis (RVM signing) <[email protected]>”2 个新的用户标识
gpg: 密钥 D39DC0E3:“Michal Papis (RVM signing) <[email protected]>”101 个新的签名
gpg: 密钥 D39DC0E3:“Michal Papis (RVM signing) <[email protected]>”2 个新的子钥
gpg: 密钥 39499BDB:公钥“Piotr Kuczynski <[email protected]>”已导入
gpg: 没有找到任何绝对信任的密钥
gpg: 合计被处理的数量:2
gpg:           已导入:1  (RSA: 1)
gpg:       新用户标识:2
gpg:         新的子钥:2
gpg:         新的签名:101

[root@zabbix-server data]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.8.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.8/1.29.8.tar.gz.asc
gpg: 于 2019年05月08日 星期三 22时14分49秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB
gpg: 完好的签名,来自于“Piotr Kuczynski <[email protected]>”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg:       没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.8.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM 

4、升级ruby版本

###########查看ruby相关信息,由于后边需要升级先可以升级ruby版本
[root@zabbix-server ]# source /etc/profile.d/rvm.sh 
[root@zabbix-server ]# rvm -v
rvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
[root@zabbix-server common.git]# rvm list known
####### MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
ruby-head
[root@zabbix-server]# rvm install 2.5        ####安装ruby2.5
[root@zabbix-server]# ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
[root@zabbix-server common.git]# gem source -l     #####rvm下载只保留阿里云的镜像
*** CURRENT SOURCES ***
http://mirrors.aliyun.com/rubygems/

5、通过gem安装git_stats

[root@zabbix-serve]# gem install git_stats
Successfully installed git_stats-1.0.17
Parsing documentation for git_stats-1.0.17
Done installing documentation for git_stats after 0 seconds
1 gem installed

6、安装locate

[root@zabbix-server]# yum install mlocate -y
[root@zabbix-server]# updatedb 

7、添加git_stats中文支持,目录在config/locales/下

[root@zabbix-server]# find / -name 'git_stats'
/usr/local/rvm/gems/ruby-2.5.5/wrappers/git_stats
/usr/local/rvm/gems/ruby-2.5.5/gems/git_stats-1.0.17/lib/git_stats
/usr/local/rvm/gems/ruby-2.5.5/gems/git_stats-1.0.17/bin/git_stats
/usr/local/rvm/gems/ruby-2.5.5/bin/git_stats
/data/git_stats
[root@zabbix-server]# cd /usr/local/rvm/gems/ruby-2.5.5/gems/git_stats-1.0.17/config/locales 
[root@zabbix-server locales]# cp zh_tw_default.yml zh_default.yml
[root@zabbix-server locales]# vim zh_default.yml     ######修改最上边的zh_tw为zh_cn其他不变
zh_cn:
  date:
    abbr_day_names:
[root@zabbix-server locales]# vim zh.yml          ######修改最上边的zh_tw为zh_cn其他不变   
zh_cn:
  project_name: 项目名称
    [root@zabbix-server]# updatedb            #####更新下索引

7、为指定工程指定生成分析报告

[root@zabbix-server user.git]#                       ######切换到生产 报告的工程下面
[root@zabbix-server user.git]# git_stats generate -o /data/status7/ --language zh_cn           #######指定生成相关的分析报告。-o指定生成报告的路径  --language指定生成的语言。

8、通过nginx把生成的报告展示出来,nginx的相关配置如下:

扫描二维码关注公众号,回复: 6649062 查看本文章
[root@zabbix-server locales]# cat /etc/nginx/conf.d/git_stats.conf 
server {
         listen    8888;
         server_name  localhost;
    access_log  /data/nginx/log/git.log;
      location / {
            root   /data/status6;
            index  index.html index.htm;
    }
         location /status2 {
                root   /data;
                index  index.html index.htm;
    }
         location /status5 {
        root   /data;
                index  index.html index.htm;
    }
         location /status3 {
                root   /data;
                index  index.html index.htm;
    }
}

9、相关图形展示如下。
Linux下安装代码统计工具git_stats
Linux下安装代码统计工具git_stats

10切换到其他按照如上步骤进行生成相关的报告。本文是通过脚本进行批量生成的。

[root@zabbix-server]# cat git_status.sh
#!/bin/bash
#author:lqb write by 2019.06.11
#function:定时任务统计代码工具
source /etc/profile
source /etc/profile.d/rvm.sh
source ~/.bash_profile
date +%F-%T;
cd /data/repositories/baidu_admin.git
git_stats generate -o /data/status/baidu_admin/ --language zh_cn
cd /data/repositories/baidu_web_v2.git
git_stats generate -o /data/status/baidu_web_v2/ --language zh_cn
cd /data/repositories/baidu_wxapp.git
git_stats generate -o /data/status/baidu_wxapp/ --language zh_cn
cd /data/repositories/html5.git
git_stats generate -o /data/status/html5/ --language zh_cn

转载于:https://blog.51cto.com/liqingbiao/2407268

猜你喜欢

转载自blog.csdn.net/weixin_34390105/article/details/92814873