Linux下安裝代碼統計工具git_stats

(一)、簡介
git_stats:倉庫代碼統計工具之一,能夠按git提交人、提交次數、修改文件數、代碼行數、註釋量在時間維度上進行統計,亦可按各文件類型進行簡單的統計,很是方便.html

雖然以代碼行數來衡量項目或者程序員並非一件靠譜的事,可是從統計角度看趨勢對於技術管理人員仍是頗有幫助的!GitStats就是這樣的工具,它能生成如下統計數據,並以圖表形式進行對比html5

  • 常規的統計:文件總數,行數,提交量,做者數。
  • 活躍性:天天中每小時的、每週中天天的、每週中每小時的、每一年中每個月的、每一年的提交量。
  • 做者數:列舉全部的做者(提交數,第一次提交日期,最近一次的提交日期),並按月和年來劃分。
  • 文件數:按日期劃分,按擴展名名劃分。
  • 行數:按日期劃分。

(二)、安裝和相關的配置
一、下載安裝ruby,因爲節省時間纔有yum進行安裝。linux

[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

二、添加ruby國內阿里雲倉庫來提升訪問速度,並刪除國外訪問的倉庫。nginx

[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/

三、安裝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 stablegit

[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) <mpapis@gmail.com>」2 個新的用戶標識
gpg: 密鑰 D39DC0E3:「Michal Papis (RVM signing) <mpapis@gmail.com>」101 個新的簽名
gpg: 密鑰 D39DC0E3:「Michal Papis (RVM signing) <mpapis@gmail.com>」2 個新的子鑰
gpg: 密鑰 39499BDB:公鑰「Piotr Kuczynski <piotr.kuczynski@gmail.com>」已導入
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 <piotr.kuczynski@gmail.com>」
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

四、升級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/

五、經過gem安裝git_statsgithub

[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

六、安裝locateweb

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

七、添加git_stats中文支持,目錄在config/locales/下shell

[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            #####更新下索引

七、爲指定工程指定生成分析報告json

[root@zabbix-server user.git]#                       ######切換到生產 報告的工程下面
[root@zabbix-server user.git]# git_stats generate -o /data/status7/ --language zh_cn           #######指定生成相關的分析報告。-o指定生成報告的路徑  --language指定生成的語言。

八、經過nginx把生成的報告展現出來,nginx的相關配置以下:

[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;
    }
}

九、相關圖形展現以下。
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
相關文章
相關標籤/搜索