Skip to content
Snippets Groups Projects
Commit 058d8471 authored by matthu017's avatar matthu017
Browse files

Refactor searches

Add relative time to searches
Pandoc is used to generate docx
parent 1c290140
No related branches found
No related tags found
1 merge request!2Refactored to use splunk
...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin" ...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin"
PASS = ENV["PASS"] || "pass" PASS = ENV["PASS"] || "pass"
DIR = ENV["DIR"] || "./" DIR = ENV["DIR"] || "./"
OUTPUT_DIR = ENV["OUTPUT_DIR"] || "./output/current/#{APP}" APP_DIR = ENV["APP_DIR"] || "./output/current/#{APP}"
SID_DIR = "#{DIR}/sid" SID_DIR = "#{DIR}/sid"
OUTPUT = "#{OUTPUT_DIR}/data.app.txt" OUTPUT = "#{APP_DIR}/data.app.txt"
COUNT = 60000 COUNT = 60000
BASEURL = 'https://splunk.osc.edu:8089' BASEURL = 'https://splunk.osc.edu:8089'
......
...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin" ...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin"
PASS = ENV["PASS"] || "pass" PASS = ENV["PASS"] || "pass"
DIR = ENV["DIR"] || "./" DIR = ENV["DIR"] || "./"
OUTPUT_DIR = ENV["OUTPUT_DIR"] || "./output/current/#{APP}" APP_DIR = ENV["APP_DIR"] || "./output/current/#{APP}"
SID_DIR = "#{DIR}/sid" SID_DIR = "#{DIR}/sid"
OUTPUT = "#{OUTPUT_DIR}/data.client.txt" OUTPUT = "#{APP_DIR}/data.client.txt"
COUNT = 60000 COUNT = 60000
BASEURL = 'https://splunk.osc.edu:8089' BASEURL = 'https://splunk.osc.edu:8089'
......
...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin" ...@@ -23,9 +23,9 @@ USER = ENV["USER"] || "admin"
PASS = ENV["PASS"] || "pass" PASS = ENV["PASS"] || "pass"
DIR = ENV["DIR"] || "./" DIR = ENV["DIR"] || "./"
OUTPUT_DIR = ENV["OUTPUT_DIR"] || "./output/current/#{APP}" APP_DIR = ENV["APP_DIR"] || "./output/current/#{APP}"
SID_DIR = "#{DIR}/sid" SID_DIR = "#{DIR}/sid"
OUTPUT = "#{OUTPUT_DIR}/data.location.txt" OUTPUT = "#{APP_DIR}/data.location.txt"
COUNT = 60000 COUNT = 60000
BASEURL = 'https://splunk.osc.edu:8089' BASEURL = 'https://splunk.osc.edu:8089'
......
...@@ -7,16 +7,15 @@ APP = ENV["APP"] || "ondemand" ...@@ -7,16 +7,15 @@ APP = ENV["APP"] || "ondemand"
HOST = ENV["HOST"] || "ondemand.osc.edu" HOST = ENV["HOST"] || "ondemand.osc.edu"
DIR = ENV["DIR"] || "./" DIR = ENV["DIR"] || "./"
CURRENT = "#{DIR}/output/current" OUTPUT_DIR = ENV["OUTPUT_DIR"] || "#{DIR}/output"
PREVIOUS = "#{DIR}/output/previous"
PROJ_FILE = "#{DIR}/dbreport.txt" PROJ_FILE = "#{DIR}/dbreport.txt"
APP_FILE = "#{CURRENT}/#{APP}/data.app.txt" APP_FILE = "#{OUTPUT_DIR}/current/#{APP}/data.app.txt"
CLIENT_FILE = "#{CURRENT}/#{APP}/data.client.txt" CLIENT_FILE = "#{OUTPUT_DIR}/current/#{APP}/data.client.txt"
LOCATION_FILE = "#{CURRENT}/#{APP}/data.location.txt" LOCATION_FILE = "#{OUTPUT_DIR}/current/#{APP}/data.location.txt"
LAST_APP_FILE = "#{PREVIOUS}/#{APP}/data.app.txt" LAST_APP_FILE = "#{OUTPUT_DIR}/previous/#{APP}/data.app.txt"
LAST_CLIENT_FILE = "#{PREVIOUS}/#{APP}/data.client.txt" LAST_CLIENT_FILE = "#{OUTPUT_DIR}/previous/#{APP}/data.client.txt"
LAST_LOCATION_FILE = "#{PREVIOUS}/#{APP}/data.location.txt" LAST_LOCATION_FILE = "#{OUTPUT_DIR}/previous/#{APP}/data.location.txt"
# #
# Set dependencies here # Set dependencies here
......
...@@ -10,13 +10,14 @@ APP = ENV["APP"] || "ondemand" ...@@ -10,13 +10,14 @@ APP = ENV["APP"] || "ondemand"
USER = ENV["USER"] || "admin" USER = ENV["USER"] || "admin"
PASS = ENV["PASS"] || "pass" PASS = ENV["PASS"] || "pass"
TIME_DIFF = (ENV["TIME_DIFF"] || "1").to_i TIME_DIFF = (ENV["TIME_DIFF"] || "1").to_i
TIME_UNITS = ENV["TIME_UNITS"] || "mon"
DIR = ENV["DIR"] || "." DIR = ENV["DIR"] || "."
SID_DIR = "#{DIR}/sid" SID_DIR = "#{DIR}/sid"
time_params = "earliest=-1mon latest=now" time_params = "earliest=-1#{TIME_UNITS} latest=now"
if (TIME_DIFF > 1) if (TIME_DIFF > 1)
time_params = "earliest=-#{TIME_DIFF}mon@mon latest=-#{TIME_DIFF - 1}mon@mon" time_params = "earliest=-#{TIME_DIFF}#{TIME_UNITS}@#{TIME_UNITS} latest=-#{TIME_DIFF - 1}#{TIME_UNITS}@#{TIME_UNITS}"
elsif (TIME_DIFF <= 0) elsif (TIME_DIFF <= 0)
abort "Incorrect time difference parameter" abort "Incorrect time difference parameter"
end end
......
#!/bin/sh
function generate_docx(){
APP=$1
APP_DIR=$DIR/output/current/$APP
IN_FILE=$APP_DIR/report.md
OUT_FILE=$DATA_DIR/$APP-$SHORT_DATE.docx
#pandoc
pandoc -f markdown -t docx -o $OUT_FILE $IN_FILE
}
function main(){
DIR=$(dirname $(readlink -f "$0"))
SHORT_DATE=$(date +%Y-%m)
#New directory for docx to generate into
DATA_DIR=$DIR/output/reports
mkdir $DATA_DIR
generate_docx 'awesim'
generate_docx 'totalsim'
generate_docx 'ondemand'
generate_docx 'stats'
}
main
...@@ -9,17 +9,16 @@ function start_search(){ ...@@ -9,17 +9,16 @@ function start_search(){
function get_data(){ function get_data(){
export HOST=$1 export HOST=$1
export APP=$2 export APP=$2
export OUTPUT_DIR=$OUTPUT/$APP export APP_DIR=$DATA_DIR/$APP
mkdir $OUTPUT_DIR mkdir $APP_DIR
$DIR/bin/get_data $DIR/bin/get_data
} }
#1 for the past 30 days to now, 6 for six to five months ago(), etc.
function search_month(){ function search_month(){
export TIME_DIFF=$1 export TIME_DIFF=$1
OUTPUT=$2 DATA_DIR=$2
mkdir $OUTPUT mkdir $DATA_DIR
SID_DIR=$DIR/sid #SID directory SID_DIR=$DIR/sid #SID directory
mkdir $SID_DIR mkdir $SID_DIR
...@@ -49,6 +48,7 @@ function generate_monthly_report(){ ...@@ -49,6 +48,7 @@ function generate_monthly_report(){
$DIR/bin/metrics > $CURRENT/$APP/report.md $DIR/bin/metrics > $CURRENT/$APP/report.md
#process docx command
IN_FILE=$CURRENT_DIR/report.md IN_FILE=$CURRENT_DIR/report.md
OUT_FILE=$CURRENT_DIR/$APP-$SHORT_DATE.docx OUT_FILE=$CURRENT_DIR/$APP-$SHORT_DATE.docx
} }
...@@ -61,16 +61,22 @@ function main(){ ...@@ -61,16 +61,22 @@ function main(){
echo echo
export USER=$user export USER=$user
export PASS=$pass export PASS=$pass
export DIR=$(dirname $(readlink -f "$0")) export DIR=$(dirname $(readlink -f "$0"))
mkdir $DIR/output
CURRENT=$DIR/output/current # change here to change output directories
PREVIOUS=$DIR/output/previous
COMPARE_MONTH=6 #input month here to compare last 30 days to #Options
search_month $COMPARE_MONTH $PREVIOUS export OUTPUT_DIR=$DIR/output #change here to change output directories
export TIME_UNITS="d" #splunk time modifiers
COMPARE=6 #input relative time range
mkdir $OUTPUT_DIR
CURRENT=$OUTPUT_DIR/current
PREVIOUS=$OUTPUT_DIR/previous
#run searches and get data
search_month $COMPARE $PREVIOUS
search_month '1' $CURRENT search_month '1' $CURRENT
#generate reports
generate_monthly_report 'apps.awesim.org' 'awesim' generate_monthly_report 'apps.awesim.org' 'awesim'
generate_monthly_report 'apps.totalsim.us' 'totalsim' generate_monthly_report 'apps.totalsim.us' 'totalsim'
generate_monthly_report 'ondemand.osc.edu' 'ondemand' generate_monthly_report 'ondemand.osc.edu' 'ondemand'
...@@ -79,3 +85,8 @@ function main(){ ...@@ -79,3 +85,8 @@ function main(){
} }
main main
#Output directory -must be exported for metrics
#Data directory (current and previous)
#App directory -must be exported for ease of use in get____data, fxn doesn't know if current or previous dir
#Output files -handled by lower level
\ No newline at end of file
#!/bin/env ruby
require './lib/AppData'
require './lib/ClientData'
require './lib/LocationData'
require './lib/DataMethods'
#
# Set options here
#
PROJ_FILE = ENV["PROJ_DATA_FILE"] || "dbreport.txt"
APP_FILE = ENV["APP_DATA_FILE"] || "data.app.txt"
CLIENT_FILE = ENV["CLIENT_DATA_FILE"] || "data.client.txt"
LOCATION_FILE = ENV["LOCATION_DATA_FILE"] || "data.location.txt"
LAST_APP_FILE = ENV["LAST_APP_DATA_FILE"] || "data.app.txt"
LAST_CLIENT_FILE = ENV["LAST_CLIENT_DATA_FILE"] || "data.client.txt"
LAST_LOCATION_FILE = ENV["LAST_LOCATION_DATA_FILE"]|| "data.location.txt"
SESSION_TIME = (ENV["SESSION_TIME"] || 8).to_i # time in hours between sessions
SHOW_DEV = ENV["SHOW_DEV"] != nil
SHOW_USR = ENV["SHOW_USR"] != nil
SHOW_WEB_VER = ENV["SHOW_WEB_VER"] != nil
SHOW_OS_VER = ENV["SHOW_OS_VER"] != nil
DELIM = "|"
NUM_USR = (ENV["NUM_USR"] || 25).to_i
NUM_WEB = (ENV["NUM_WEB"] || 10).to_i
NUM_OS = (ENV["NUM_OS"] || 10).to_i
NUM_CITY = (ENV["NUM_CITY"] || 10).to_i
APP_TIME_COL = 0
APP_USER_COL = 1
APP_APP_COL = 2
CLNT_TIME_COL = 0
CLNT_USER_COL = 1
CLNT_BRWS_COL = 2
CLNT_BRWSV_COL = 3
CLNT_OS_COL = 4
CLNT_OSV_COL = 5
LOC_TIME_COL = 0
LOC_USER_COL = 1
LOC_CITY_COL = 2
LOC_STATE_COL = 3
LOC_CNTRY_COL = 4
#
# Do not modify below
#
require 'rubygems'
require 'bundler/setup'
require 'securerandom'
require 'time'
require 'csv'
class FormatData
class << self
def simple_table(rows)
lengths = rows.transpose.map {|v| v.map {|x| x.to_s.length}.max}
# print headers
puts wrap(rows[0].zip(lengths).map {|h, l| h.to_s.center(l)}.join(" | "))
puts(
wrap(
lengths.map.with_index do |l, i|
i == 0 ? ("-" * l) : ("-" * (l - 1) + ":")
end.join(" | ")
)
)
# print rows
rows.drop(1).each do |r|
puts(
wrap(
r.zip(lengths).map.with_index do |(v, l), i|
i == 0 ? v.to_s.ljust(l) : v.to_s.rjust(l)
end.join(" | ")
)
)
end
end
def wrap(str)
"| #{str} |"
end
end
end
class Report
def initialize (app_file, client_file, location_file, project_file)
@app = AppData.new(app_file, project_file)
@client = ClientData.new(client_file)
@location = LocationData.new(location_file)
end
attr_reader :app, :client, :location
end
def main
report1 = Report.new(APP_FILE, CLIENT_FILE, LOCATION_FILE, PROJ_FILE)
report2 = Report.new(LAST_APP_FILE, LAST_CLIENT_FILE, LAST_LOCATION_FILE, PROJ_FILE)
compare = DataMethods.new
totalUser = compare.return_percent_change(report1.app.user_cnt, report2.app.user_cnt)
totalApp = compare.return_percent_change(report1.app.app_launches, report2.app.app_launches)
avgLaunch = compare.return_percent_change(report1.app.avg_launches, report2.app.avg_launches)
totalUsed = compare.return_percent_change(report1.app.app_cnt, report2.app.app_cnt)
title = "Metrics for (#{report1.app.start_time.strftime("%m/%d/%Y")} - #{report1.app.final_time.strftime("%m/%d/%Y")}) "
subtitle = "Compared to (#{report2.app.start_time.strftime("%m/%d/%Y")} - #{report2.app.final_time.strftime("%m/%d/%Y")})"
puts title + subtitle
puts "=" * (title.length + subtitle.length)
puts ""
puts "- Total Users = #{report1.app.user_cnt} #{totalUser}"
puts "- Total App Launches = #{report1.app.app_launches} #{totalApp}"
puts "- Avg Launches per User = #{report1.app.avg_launches} #{avgLaunch}"
puts "- Total Used Apps = #{report1.app.app_cnt} #{totalUsed}"
title = "Used Apps"
puts ""
puts title
puts "-" * title.length
puts ""
FormatData.simple_table report1.app.format_app_table(report2.app)
title = "Top #{NUM_USR} Users"
puts ""
puts title
puts "-" * title.length
puts ""
FormatData.simple_table report1.app.format_user_table(report2.app)
title = "Top #{NUM_WEB} Browsers"
puts ""
puts title
puts "-" * title.length
puts ""
puts "- Total Browsers = #{report1.client.browser_table.size - 1}" #title block
puts ""
FormatData.simple_table report1.client.format_browser_table(report2.client)
title = "Top #{NUM_OS} Operating Systems"
puts ""
puts title
puts "-" * title.length
puts ""
puts "- Total Operating Systems = #{report1.client.os_table.size - 1}" #title block
puts ""
FormatData.simple_table report1.client.format_os_table(report2.client)
title = "Top #{NUM_CITY} Cities"
puts ""
puts title
puts "-" * title.length
puts ""
puts "- Total Cities = #{report1.location.location_table.size - 1}" #title block
puts ""
FormatData.simple_table report1.location.format_location_table(report2.location)
puts ""
puts "\\* Session = All activity within the #{SESSION_TIME} hour period of time from first user activity."
end
main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment