rda-python-metrics 1.0.7__tar.gz → 1.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rda-python-metrics might be problematic. Click here for more details.
- rda_python_metrics-1.0.9/MANIFEST.in +1 -0
- {rda_python_metrics-1.0.7/src/rda_python_metrics.egg-info → rda_python_metrics-1.0.9}/PKG-INFO +4 -1
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/pyproject.toml +8 -14
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillawsusage.usg +1 -2
- rda_python_metrics-1.0.9/src/rda_python_metrics/fillcdgusage.py +408 -0
- rda_python_metrics-1.0.9/src/rda_python_metrics/fillcdgusage.usg +18 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillcodusage.usg +1 -1
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillcountry.py +4 -5
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillglobususage.usg +1 -1
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filloneorder.py +3 -4
- rda_python_metrics-1.0.9/src/rda_python_metrics/pgsyspath.py +36 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewordusage.py +17 -17
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebfile.py +14 -14
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9/src/rda_python_metrics.egg-info}/PKG-INFO +4 -1
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/SOURCES.txt +3 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/entry_points.txt +1 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/requires.txt +3 -0
- rda_python_metrics-1.0.9/tests/test_metrics.py +31 -0
- rda_python_metrics-1.0.7/MANIFEST.in +0 -19
- rda_python_metrics-1.0.7/tests/test_metrics.py +0 -6
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/LICENSE +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/README.md +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/setup.cfg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/PgIPInfo.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/PgView.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/__init__.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillawsusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillcodusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillendtime.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillglobususage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillipinfo.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillipinfo.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filloneorder.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillosdfusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillosdfusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillrdadb.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillrdadb.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filltdsusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filltdsusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filluser.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filluser.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/logarch.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/logarch.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/pgperson.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/pgusername.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewallusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewallusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcheckusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcheckusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcodusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcodusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewordusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewrqstusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewrqstusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewtdsusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewtdsusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebfile.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebusage.py +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebusage.usg +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/dependency_links.txt +0 -0
- {rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include src/rda_python_metrics/*.usg
|
{rda_python_metrics-1.0.7/src/rda_python_metrics.egg-info → rda_python_metrics-1.0.9}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_metrics
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.9
|
|
4
4
|
Summary: RDA Python Package to gather and view data usage metrics
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-metrics
|
|
@@ -13,6 +13,9 @@ Description-Content-Type: text/markdown
|
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: rda_python_common
|
|
15
15
|
Requires-Dist: rda_python_setuid
|
|
16
|
+
Requires-Dist: geoip2
|
|
17
|
+
Requires-Dist: ipinfo
|
|
18
|
+
Requires-Dist: httplib2
|
|
16
19
|
Dynamic: license-file
|
|
17
20
|
|
|
18
21
|
RDA Python Package to gather and view data usage metrics.
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "rda_python_metrics"
|
|
9
|
-
version = "1.0.
|
|
9
|
+
version = "1.0.9"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name="Zaihua Ji", email="zji@ucar.edu" },
|
|
12
12
|
]
|
|
@@ -22,21 +22,14 @@ classifiers = [
|
|
|
22
22
|
dependencies = [
|
|
23
23
|
"rda_python_common",
|
|
24
24
|
"rda_python_setuid",
|
|
25
|
+
"geoip2",
|
|
26
|
+
"ipinfo",
|
|
27
|
+
"httplib2"
|
|
25
28
|
]
|
|
26
29
|
|
|
27
|
-
[tool.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[tool.setuptools.packages.find]
|
|
31
|
-
where = ["src"]
|
|
32
|
-
|
|
33
|
-
[tool.setuptools.package-data]
|
|
34
|
-
"rda_python_metrics" = [
|
|
35
|
-
"logarch.usg", "fillawsusage.usg", "fillcodusage.usg", "fillglobususage.usg",
|
|
36
|
-
"fillipinfo.usg", "filloneorder.usg", "fillosdfusage.usg", "fillrdadb.usg",
|
|
37
|
-
"filltdsusage.usg", "viewallusage.usg", "viewcheckusage.usg", "viewcodusage.usg",
|
|
38
|
-
"viewordusage.usg", "viewrqstusage.usg", "viewtdsusage.usg", "viewwebfile.usg",
|
|
39
|
-
"viewwebusage.usg"
|
|
30
|
+
[tool.pytest.ini_options]
|
|
31
|
+
pythonpath = [
|
|
32
|
+
"src"
|
|
40
33
|
]
|
|
41
34
|
|
|
42
35
|
[project.urls]
|
|
@@ -45,6 +38,7 @@ where = ["src"]
|
|
|
45
38
|
[project.scripts]
|
|
46
39
|
"logarch.py" = "rda_python_metrics.logarch:main"
|
|
47
40
|
"fillawsusage" = "rda_python_metrics.fillaswusage:main"
|
|
41
|
+
"fillcdgusage" = "rda_python_metrics.fillcdgusage:main"
|
|
48
42
|
"fillcodusage" = "rda_python_metrics.fillcodusage:main"
|
|
49
43
|
"fillcountry" = "rda_python_metrics.fillcountry:main"
|
|
50
44
|
"fillendtime" = "rda_python_metrics.fillendtime:main"
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillawsusage.usg
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
Retrieves usage information from AWS Server logs under directory
|
|
3
|
-
|
|
4
|
-
database 'dssdb'.
|
|
3
|
+
../rda/transer/AWSera5log/ to fill table 'wusage' in database 'rdadb'.
|
|
5
4
|
|
|
6
5
|
Usage: fillawsusage [-b] [-d LogFileDates] [-N NumberDay] [-p BeginDate [Enddate]]
|
|
7
6
|
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
###############################################################################
|
|
4
|
+
#
|
|
5
|
+
# Title : fillcdgusage
|
|
6
|
+
# Author : Zaihua Ji, zji@ucar.edu
|
|
7
|
+
# Date : 2025-04-14
|
|
8
|
+
# Purpose : python program to retrieve info from GDEX Postgres database for GDS
|
|
9
|
+
# file accesses and backup fill table tdsusage in PostgreSQL database dssdb.
|
|
10
|
+
#
|
|
11
|
+
# Github : https://github.com/NCAR/rda-python-metrics.git
|
|
12
|
+
#
|
|
13
|
+
###############################################################################
|
|
14
|
+
#
|
|
15
|
+
import sys
|
|
16
|
+
import re
|
|
17
|
+
import glob
|
|
18
|
+
from os import path as op
|
|
19
|
+
from rda_python_common import PgLOG
|
|
20
|
+
from rda_python_common import PgUtil
|
|
21
|
+
from rda_python_common import PgFile
|
|
22
|
+
from rda_python_common import PgDBI
|
|
23
|
+
from rda_python_common import PgSplit
|
|
24
|
+
from . import PgIPInfo
|
|
25
|
+
|
|
26
|
+
USAGE = {
|
|
27
|
+
'TDSTBL' : "tdsusage",
|
|
28
|
+
'WEBTBL' : "webusage",
|
|
29
|
+
'CDATE' : PgUtil.curdate(),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
DSIDS = {
|
|
33
|
+
'ucar.cgd.cesm2.cam6.prescribed_sst_amip' : ['d651010'],
|
|
34
|
+
'ucar.cgd.ccsm4.CLM_LAND_ONLY' : ['d651011'],
|
|
35
|
+
'ucar.cgd.artmip' : ['d651012', 'd651016', 'd651017', 'd651018'],
|
|
36
|
+
'tamip' : ['d651013'],
|
|
37
|
+
'ucar.cgd.ccsm4.CLIVAR_LE' : ['d651014'],
|
|
38
|
+
'ucar.cgd.cesm2.Gettelman_CESM2_ECS' : ['d651015'],
|
|
39
|
+
'ucar.cgd.ccsm4.geomip.ssp5' : ['d651024'],
|
|
40
|
+
'ucar.cgd.ccsm4.IOD-PACEMAKER' : ['d651021'],
|
|
41
|
+
'ucar.cgd.ccsm4.past2k_transient' : ['651023'],
|
|
42
|
+
'ucar.cgd.ccsm4.lowwarming' : ['d651025'],
|
|
43
|
+
'ucar.cgd.ccsm4.CESM_CAM5_BGC_ME' : ['d651000'],
|
|
44
|
+
'ucar.cgd.ccsm4.iTRACE' : ['d651022'],
|
|
45
|
+
'ucar.cgd.ccsm4.so2_geoeng' : ['d651026'],
|
|
46
|
+
'ucar.cgd.ccsm4.cesmLE' : ['d651027'],
|
|
47
|
+
'ucar.cgd.ccsm4.CESM1-CAM5-DP' : ['d651028'],
|
|
48
|
+
'ucar.cgd.ccsm4.amv_lens' : ['d651031'],
|
|
49
|
+
'ucar.cgd.ccsm4.ATL-PACEMAKER' : ['d651032'],
|
|
50
|
+
'ucar.cgd.ccsm4.pac-pacemaker' : ['d651033'],
|
|
51
|
+
'ucar.cgd.ccsm4.SD-WACCM-X_v2.1' : ['d651034'],
|
|
52
|
+
'ucar.cgd.ccsm4.amv_lens' : ['d651035'],
|
|
53
|
+
'ucar.cgd.cesm2.cism_ismip6' : ['d651036'],
|
|
54
|
+
'ucar.cgd.ccsm4.pliomip2' : ['d651037']
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# main function to run this program
|
|
60
|
+
#
|
|
61
|
+
def main():
|
|
62
|
+
|
|
63
|
+
params = {} # array of input values
|
|
64
|
+
argv = sys.argv[1:]
|
|
65
|
+
opt = None
|
|
66
|
+
|
|
67
|
+
for arg in argv:
|
|
68
|
+
if arg == "-b":
|
|
69
|
+
PgLOG.PGLOG['BCKGRND'] = 1
|
|
70
|
+
elif re.match(r'^-[msNy]$', arg):
|
|
71
|
+
opt = arg[1]
|
|
72
|
+
params[opt] = []
|
|
73
|
+
elif re.match(r'^-', arg):
|
|
74
|
+
PgLOG.pglog(arg + ": Invalid Option", PgLOG.LGWNEX)
|
|
75
|
+
elif opt:
|
|
76
|
+
params[opt].append(arg)
|
|
77
|
+
else:
|
|
78
|
+
PgLOG.pglog(arg + ": Value passed in without leading option", PgLOG.LGWNEX)
|
|
79
|
+
|
|
80
|
+
if not opt:
|
|
81
|
+
PgLOG.show_usage('fillcdgusage')
|
|
82
|
+
elif 's' not in params:
|
|
83
|
+
PgLOG.pglog("-s: Missing dataset short name to gather CDG metrics", PgLOG.LGWNEX)
|
|
84
|
+
elif len(params) < 2:
|
|
85
|
+
PgLOG.pglog("-(m|N|y): Missing Month, NumberDays or Year to gather CDG metrics", PgLOG.LGWNEX)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
PgLOG.cmdlog("fillcdgusage {}".format(' '.join(argv)))
|
|
89
|
+
dsids = get_dataset_ids(params['s'])
|
|
90
|
+
if dsids:
|
|
91
|
+
del params['s']
|
|
92
|
+
for o in params:
|
|
93
|
+
dranges = get_date_ranges(o, params[o])
|
|
94
|
+
fill_cdg_usages(dsids, dranges)
|
|
95
|
+
|
|
96
|
+
PgLOG.pglog(None, PgLOG.LOGWRN|PgLOG.SNDEML) # send email out if any
|
|
97
|
+
|
|
98
|
+
sys.exit(0)
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# connect to the gdex database esg-production
|
|
102
|
+
#
|
|
103
|
+
def gdex_dbname():
|
|
104
|
+
PgDBI.set_scname('esg-production', 'metrics', 'gateway-reader', None, 'sagedbprodalma.ucar.edu')
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# get datasets
|
|
108
|
+
#
|
|
109
|
+
def get_dataset_ids(dsnames):
|
|
110
|
+
|
|
111
|
+
gdex_dbname()
|
|
112
|
+
dsids = []
|
|
113
|
+
tbname = 'metadata.dataset'
|
|
114
|
+
for dsname in dsnames:
|
|
115
|
+
if dsname not in DSIDS:
|
|
116
|
+
PgLOG.pglog(dsname + ": Unknown CDG dataset short name", PgLOG.LOGWRN)
|
|
117
|
+
continue
|
|
118
|
+
rdaid = DSIDS[dsname]
|
|
119
|
+
pgrec = PgDBI.pgget(tbname, 'id', "short_name = '{}'".format(dsname))
|
|
120
|
+
if not (pgrec and pgrec['id']): continue
|
|
121
|
+
dsid = pgrec['id']
|
|
122
|
+
if dsid in dsids: continue
|
|
123
|
+
dsids.append([dsid, rdaid])
|
|
124
|
+
recursive_dataset_ids(dsid, rdaid, dsids)
|
|
125
|
+
|
|
126
|
+
if not dsids: PgLOG.pglog("No Dataset Id identified to gather CDG metrics", PgLOG.LOGWRN)
|
|
127
|
+
|
|
128
|
+
return dsids
|
|
129
|
+
|
|
130
|
+
#
|
|
131
|
+
# get dsids recursivley
|
|
132
|
+
#
|
|
133
|
+
def recursive_dataset_ids(pdsid, rdaid, dsids):
|
|
134
|
+
|
|
135
|
+
tbname = 'metadata.dataset'
|
|
136
|
+
pgrecs = PgDBI.pgmget(tbname, 'id', "parent_dataset_id = '{}'".format(pdsid))
|
|
137
|
+
if not pgrecs: return
|
|
138
|
+
|
|
139
|
+
for dsid in pgrecs['id']:
|
|
140
|
+
if dsid in dsids: continue
|
|
141
|
+
dsids.append([dsid, rdaid])
|
|
142
|
+
recursive_dataset_ids(dsid, rdaid, dsids)
|
|
143
|
+
|
|
144
|
+
#
|
|
145
|
+
# get the date ranges for given condition
|
|
146
|
+
#
|
|
147
|
+
def get_date_ranges(option, inputs):
|
|
148
|
+
|
|
149
|
+
dranges = []
|
|
150
|
+
for input in inputs:
|
|
151
|
+
# get date range
|
|
152
|
+
dates = []
|
|
153
|
+
if option == 'N':
|
|
154
|
+
dates[1] = USAGE['CDATE']
|
|
155
|
+
dates[0] = PgUtil.adddate(USAGE['CDATE'], 0, 0, -int(input))
|
|
156
|
+
elif option == 'm':
|
|
157
|
+
tms = input.split('-')
|
|
158
|
+
dates[0] = PgUtil.fmtdate(int(tms[0]), int(tms[1]), 1)
|
|
159
|
+
dates[1] = PgUtil.enddate(dates[0])
|
|
160
|
+
else:
|
|
161
|
+
dates[0] = input + "-01-01"
|
|
162
|
+
dates[1] = input + "-12-31"
|
|
163
|
+
dranges.append(dates)
|
|
164
|
+
|
|
165
|
+
return dranges
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
# get file download records for given dsid
|
|
169
|
+
#
|
|
170
|
+
def get_dsid_records(dsid, dates):
|
|
171
|
+
|
|
172
|
+
gdex_dbname()
|
|
173
|
+
tbname = 'metrics.file_download'
|
|
174
|
+
fields = ('date_completed, remote_address, logical_file_size, logical_file_name, file_access_point_uri, user_agent_name, bytes_sent, '
|
|
175
|
+
'subset_file_size, range_request, dataset_file_size, dataset_file_name, dataset_file_file_access_point_uri')
|
|
176
|
+
cond = "dataset_id = '{}' AND completed = True AND date_completed BETWEEN '{}' AND '{}' ORDER BY date_completed".format(dsid, dates[0], dates[1])
|
|
177
|
+
pgrecs = PgDBI.pgmget(tbname, fields, cond)
|
|
178
|
+
PgDBI.dssdb_dbname()
|
|
179
|
+
|
|
180
|
+
return pgrecs
|
|
181
|
+
|
|
182
|
+
#
|
|
183
|
+
# Fill TDS usages into table dssdb.tdsusage from cdg access records
|
|
184
|
+
#
|
|
185
|
+
def fill_cdg_usages(dsids, dranges):
|
|
186
|
+
|
|
187
|
+
allcnt = awcnt = atcnt = 0
|
|
188
|
+
for dsid in dsids:
|
|
189
|
+
cdgid = dsid[0]
|
|
190
|
+
rdaid = dsid[1]
|
|
191
|
+
for dates in dranges:
|
|
192
|
+
pgrecs = get_dsid_records(cdgid, dates)
|
|
193
|
+
pgcnt = len(pgrecs['dataset_file_name']) if pgrecs else 0
|
|
194
|
+
if pgcnt == 0:
|
|
195
|
+
PgLOG.pglog("{}: No record found to gather CDG usage between {} and {}".format(rdaid, dates[0], dates[1]), PgLOG.LOGWRN)
|
|
196
|
+
continue
|
|
197
|
+
PgLOG.pglog("{}: gather {} records for CDG usage between {} and {}".format(rdaid, pgcnt, dates[0], dates[1]), PgLOG.LOGWRN)
|
|
198
|
+
tcnt = wcnt = 0
|
|
199
|
+
pwkey = wrec = cdate = None
|
|
200
|
+
trecs = {}
|
|
201
|
+
for i in range(pgcnt):
|
|
202
|
+
if (i+1)%20000 == 0:
|
|
203
|
+
PgLOG.pglog("{}/{}/{} CDG/TDS/WEB records processed to add".format(i, tcnt, wcnt), PgLOG.WARNLG)
|
|
204
|
+
|
|
205
|
+
pgrec = PgUtil.onerecord(i, pgrecs)
|
|
206
|
+
dsize = pgrec['bytes_sent']
|
|
207
|
+
if not dsize: continue
|
|
208
|
+
(year, quarter, date, time) = get_record_date_time(pgrec['date_completed'])
|
|
209
|
+
url = pgrec['dataset_file_file_access_point_uri']
|
|
210
|
+
if not url: url = pgrec['file_access_point_uri']
|
|
211
|
+
ip = pgrec['remote_address']
|
|
212
|
+
engine = pgrec['user_agent_name']
|
|
213
|
+
ms = re.search(r'^https://tds.ucar.edu/thredds/(\w+)/', url)
|
|
214
|
+
if ms:
|
|
215
|
+
# tds usage
|
|
216
|
+
method = ms.group(1)
|
|
217
|
+
if pgrec['subset_file_size']:
|
|
218
|
+
etype = 'S'
|
|
219
|
+
elif pgrec['range_request']:
|
|
220
|
+
etype = 'R'
|
|
221
|
+
else:
|
|
222
|
+
etype = 'F'
|
|
223
|
+
|
|
224
|
+
if date != cdate:
|
|
225
|
+
if trecs:
|
|
226
|
+
tcnt += add_tdsusage_records(year, trecs, cdate)
|
|
227
|
+
trecs = {}
|
|
228
|
+
cdate = date
|
|
229
|
+
tkey = "{}:{}:{}:{}".format(ip, rdaid, method, etype)
|
|
230
|
+
if tkey in trecs:
|
|
231
|
+
trecs[tkey]['size'] += dsize
|
|
232
|
+
trecs[tkey]['fcount'] += 1
|
|
233
|
+
else:
|
|
234
|
+
trecs[tkey] = {'ip' : ip, 'dsid' : rdaid, 'date' : cdate, 'time' : time, 'size' : dsize,
|
|
235
|
+
'fcount' : 1, 'method' : method, 'etype' : etype, 'engine' : engine}
|
|
236
|
+
else:
|
|
237
|
+
# web usage
|
|
238
|
+
wfile = pgrec['dataset_file_name']
|
|
239
|
+
if not wfile: wfile = pgrec['logic_file_name']
|
|
240
|
+
fsize = pgrec['dataset_file_size']
|
|
241
|
+
if not fsize: fsize = pgrec['logic_file_size']
|
|
242
|
+
method = 'CDP'
|
|
243
|
+
if pgrec['subset_file_size'] or pgrec['range_request'] or dsize < fsize:
|
|
244
|
+
wkey = "{}:{}:{}".format(ip, rdaid, wfile)
|
|
245
|
+
else:
|
|
246
|
+
wkey = None
|
|
247
|
+
|
|
248
|
+
if wrec:
|
|
249
|
+
if wkey == pwkey:
|
|
250
|
+
wrec['size'] += dsize
|
|
251
|
+
continue
|
|
252
|
+
wcnt += add_webfile_usage(year, wrec)
|
|
253
|
+
wrec = {'ip' : ip, 'dsid' : rdaid, 'wfile' : wfile, 'date' : date,
|
|
254
|
+
'time' : time, 'quarter' : quarter, 'size' : dsize,
|
|
255
|
+
'locflag' : 'C', 'method' : method}
|
|
256
|
+
pwkey = wkey
|
|
257
|
+
if not pwkey:
|
|
258
|
+
wcnt += add_webfile_usage(year, wrec)
|
|
259
|
+
wrec = None
|
|
260
|
+
|
|
261
|
+
if trecs: tcnt += add_tdsusage_records(year, trecs, cdate)
|
|
262
|
+
if wrec: wcnt += add_webfile_usage(year, wrec)
|
|
263
|
+
atcnt += tcnt
|
|
264
|
+
awcnt += wcnt
|
|
265
|
+
allcnt += pgcnt
|
|
266
|
+
|
|
267
|
+
PgLOG.pglog("{}/{} TDS/WEB usage records added for {} CDG entries at {}".format(atcnt, awcnt, allcnt, PgLOG.current_datetime()), PgLOG.LOGWRN)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def get_record_date_time(ctime):
|
|
271
|
+
|
|
272
|
+
ms = re.search(r'^(\d+)/(\w+)/(\d+) (\d+:\d+:\d+)(\.|$)', str(ctime))
|
|
273
|
+
if ms:
|
|
274
|
+
d = int(ms.group(1))
|
|
275
|
+
m = PgUtil.get_month(ms.group(2))
|
|
276
|
+
q = 1 + int((m-1)/3)
|
|
277
|
+
y = ms.group(3)
|
|
278
|
+
t = ms.group(4)
|
|
279
|
+
return (y, q, "{}-{:02}-{:02}".format(y, m, d), t)
|
|
280
|
+
else:
|
|
281
|
+
PgLOG.pglog("time: Invalid date format", PgLOG.LGEREX)
|
|
282
|
+
|
|
283
|
+
def add_tdsusage_records(year, records, date):
|
|
284
|
+
|
|
285
|
+
cnt = 0
|
|
286
|
+
for key in records:
|
|
287
|
+
record = records[key]
|
|
288
|
+
cond = "date = '{}' AND time = '{}' AND ip = '{}'".format(date, record['time'], record['ip'])
|
|
289
|
+
if PgDBI.pgget(USAGE['TDSTBL'], '', cond, PgLOG.LGEREX): continue
|
|
290
|
+
record['org_type'] = record['country'] = '-'
|
|
291
|
+
ipinfo = PgIPInfo.set_ipinfo(record['ip'])
|
|
292
|
+
if ipinfo:
|
|
293
|
+
record['org_type'] = ipinfo['org_type']
|
|
294
|
+
record['country'] = ipinfo['country']
|
|
295
|
+
record['email'] = 'unknown@' + ipinfo['hostname']
|
|
296
|
+
|
|
297
|
+
if add_tds_allusage(year, record):
|
|
298
|
+
cnt += PgDBI.pgadd(USAGE['TDSTBL'], record, PgLOG.LOGWRN)
|
|
299
|
+
|
|
300
|
+
PgLOG.pglog("{}: {} TDS usage records added at {}".format(date, cnt, PgLOG.current_datetime()), PgLOG.LOGWRN)
|
|
301
|
+
|
|
302
|
+
return cnt
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def add_tds_allusage(year, pgrec):
|
|
306
|
+
|
|
307
|
+
record = {'method' : 'CDP', 'source' : 'C'}
|
|
308
|
+
|
|
309
|
+
for fld in pgrec:
|
|
310
|
+
if re.match(r'^(engine|method|etype|fcount)$', fld): continue
|
|
311
|
+
record[fld] = pgrec[fld]
|
|
312
|
+
|
|
313
|
+
return PgDBI.add_yearly_allusage(year, record)
|
|
314
|
+
|
|
315
|
+
#
|
|
316
|
+
# Fill usage of a single online data file into table dssdb.wusage of DSS PgSQL database
|
|
317
|
+
#
|
|
318
|
+
def add_webfile_usage(year, logrec):
|
|
319
|
+
|
|
320
|
+
pgrec = get_wfile_wid(logrec['dsid'], logrec['wfile'])
|
|
321
|
+
if not pgrec: return 0
|
|
322
|
+
|
|
323
|
+
table = "{}_{}".format(USAGE['WEBTBL'], year)
|
|
324
|
+
cond = "wid = {} AND method = '{}' AND date_read = '{}' AND time_read = '{}'".format(pgrec['wid'], logrec['method'], logrec['date'], logrec['time'])
|
|
325
|
+
if PgDBI.pgget(table, "", cond, PgLOG.LOGWRN): return 0
|
|
326
|
+
|
|
327
|
+
wurec = get_wuser_record(logrec['ip'], logrec['date'])
|
|
328
|
+
if not wurec: return 0
|
|
329
|
+
record = {'wid' : pgrec['wid'], 'dsid' : pgrec['dsid']}
|
|
330
|
+
record['wuid_read'] = wurec['wuid']
|
|
331
|
+
record['date_read'] = logrec['date']
|
|
332
|
+
record['time_read'] = logrec['time']
|
|
333
|
+
record['size_read'] = logrec['size']
|
|
334
|
+
record['method'] = logrec['method']
|
|
335
|
+
record['locflag'] = logrec['locflag']
|
|
336
|
+
record['ip'] = logrec['ip']
|
|
337
|
+
record['quarter'] = logrec['quarter']
|
|
338
|
+
|
|
339
|
+
if add_web_allusage(year, logrec, wurec):
|
|
340
|
+
return PgDBI.add_yearly_wusage(year, record)
|
|
341
|
+
else:
|
|
342
|
+
return 0
|
|
343
|
+
|
|
344
|
+
def add_web_allusage(year, logrec, wurec):
|
|
345
|
+
|
|
346
|
+
pgrec = {'email' : wurec['email'], 'org_type' : wurec['org_type'], 'country' : wurec['country']}
|
|
347
|
+
pgrec['dsid'] = logrec['dsid']
|
|
348
|
+
pgrec['date'] = logrec['date']
|
|
349
|
+
pgrec['quarter'] = logrec['quarter']
|
|
350
|
+
pgrec['time'] = logrec['time']
|
|
351
|
+
pgrec['size'] = logrec['size']
|
|
352
|
+
pgrec['method'] = logrec['method']
|
|
353
|
+
pgrec['ip'] = logrec['ip']
|
|
354
|
+
pgrec['source'] = 'C'
|
|
355
|
+
return PgDBI.add_yearly_allusage(year, pgrec)
|
|
356
|
+
|
|
357
|
+
#
|
|
358
|
+
# return wfile.wid upon success, 0 otherwise
|
|
359
|
+
#
|
|
360
|
+
def get_wfile_wid(dsid, wfile):
|
|
361
|
+
|
|
362
|
+
wfcond = "wfile = '{}'".format(wfile)
|
|
363
|
+
pgrec = PgSplit.pgget_wfile(dsid, "*", wfcond)
|
|
364
|
+
if pgrec:
|
|
365
|
+
pgrec['dsid'] = dsid
|
|
366
|
+
else:
|
|
367
|
+
pgrec = PgDBI.pgget("wfile_delete", "*", "{} AND dsid = '{}'".format(wfcond, dsid))
|
|
368
|
+
if not pgrec:
|
|
369
|
+
pgrec = PgDBI.pgget("wmove", "wid, dsid", wfcond)
|
|
370
|
+
if pgrec:
|
|
371
|
+
pgrec = PgSplit.pgget_wfile(pgrec['dsid'], "*", "wid = {}".format(pgrec['wid']))
|
|
372
|
+
if pgrec: pgrec['dsid'] = dsid
|
|
373
|
+
|
|
374
|
+
return pgrec
|
|
375
|
+
|
|
376
|
+
# return wuser record upon success, None otherwise
|
|
377
|
+
def get_wuser_record(ip, date):
|
|
378
|
+
|
|
379
|
+
ipinfo = PgIPInfo.set_ipinfo(ip)
|
|
380
|
+
if not ipinfo: return None
|
|
381
|
+
|
|
382
|
+
record = {'org_type' : ipinfo['org_type'], 'country' : ipinfo['country']}
|
|
383
|
+
email = 'unknown@' + ipinfo['hostname']
|
|
384
|
+
emcond = "email = '{}'".format(email)
|
|
385
|
+
flds = 'wuid, email, org_type, country, start_date'
|
|
386
|
+
pgrec = PgDBI.pgget("wuser", flds, emcond, PgLOG.LOGERR)
|
|
387
|
+
if pgrec:
|
|
388
|
+
if PgUtil.diffdate(pgrec['start_date'], date) > 0:
|
|
389
|
+
pgrec['start_date'] = record['start_date'] = date
|
|
390
|
+
PgDBI.pgupdt('wuser', record, emcond)
|
|
391
|
+
return pgrec
|
|
392
|
+
|
|
393
|
+
# now add one in
|
|
394
|
+
record['email'] = email
|
|
395
|
+
record['stat_flag'] = 'A'
|
|
396
|
+
record['start_date'] = date
|
|
397
|
+
wuid = PgDBI.pgadd("wuser", record, PgLOG.LOGERR|PgLOG.AUTOID)
|
|
398
|
+
if wuid:
|
|
399
|
+
record['wuid'] = wuid
|
|
400
|
+
PgLOG.pglog("{} Added as wuid({})".format(email, wuid), PgLOG.LGWNEM)
|
|
401
|
+
return record
|
|
402
|
+
|
|
403
|
+
return None
|
|
404
|
+
|
|
405
|
+
#
|
|
406
|
+
# call main() to start program
|
|
407
|
+
#
|
|
408
|
+
if __name__ == "__main__": main()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
Retrieves CDG usage information from GDEX metrics database to
|
|
3
|
+
fill table 'tdsusage' and 'webusage' in PostgreSQL database 'rdadb'.
|
|
4
|
+
|
|
5
|
+
Usage: fillcdgusage [-b] -s DatasetShortNames [-m MonthList] [-N NumberDays] [-y YearList]
|
|
6
|
+
|
|
7
|
+
select option -s and one of the options, -m, -N or -y each time to run
|
|
8
|
+
this application.
|
|
9
|
+
|
|
10
|
+
- Option -b, log process information into logfile only;
|
|
11
|
+
|
|
12
|
+
- Option -s, retrieve usage info for given dataset short names;
|
|
13
|
+
|
|
14
|
+
- Option -m, retrieve usage info in given months (YYYY-MM);
|
|
15
|
+
|
|
16
|
+
- Option -N, retrieve usage info in recent Number of days;
|
|
17
|
+
|
|
18
|
+
- Option -y, retrieve usage info in given years (YYYY).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
1
|
+
#!/usr/bin/env python3/
|
|
2
2
|
#
|
|
3
3
|
###############################################################################
|
|
4
4
|
#
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
import sys
|
|
18
18
|
import re
|
|
19
19
|
from rda_python_common import PgLOG
|
|
20
|
-
from rda_python_common import PgIMMA
|
|
21
20
|
from rda_python_common import PgUtil
|
|
22
21
|
from rda_python_common import PgDBI
|
|
23
22
|
|
|
@@ -29,7 +28,7 @@ def main():
|
|
|
29
28
|
argv = sys.argv[1:]
|
|
30
29
|
tables = ['allusage', 'user', 'wuser']
|
|
31
30
|
table = None
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
# check command line
|
|
34
33
|
for arg in argv:
|
|
35
34
|
if arg == "-b":
|
|
@@ -40,7 +39,7 @@ def main():
|
|
|
40
39
|
table = arg
|
|
41
40
|
else:
|
|
42
41
|
PgLOG.pglog(arg + ": one table name at a time", PgLOG.LGEREX)
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
if not table:
|
|
45
44
|
print("Usage: fillcountry TableName\n")
|
|
46
45
|
sys.exit(0)
|
|
@@ -51,7 +50,7 @@ def main():
|
|
|
51
50
|
PgLOG.cmdlog("fillcountry {}".format(' '.join(argv)))
|
|
52
51
|
|
|
53
52
|
process_countries(table)
|
|
54
|
-
|
|
53
|
+
|
|
55
54
|
sys.exit(0)
|
|
56
55
|
|
|
57
56
|
def process_countries(table):
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillglobususage.usg
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Retrieves usage information from GLlobus Server logs under directory
|
|
3
3
|
/gpfs/fs1/collections/rda/work/logs/gridftp/ to fill table 'wusage' in
|
|
4
|
-
database '
|
|
4
|
+
database 'rdadb'.
|
|
5
5
|
|
|
6
6
|
Usage: fillglobususage [-b] [-d LogFileDates] [-N NumberDay] [-p BeginDate [Enddate]]
|
|
7
7
|
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filloneorder.py
RENAMED
|
@@ -17,12 +17,11 @@ import sys
|
|
|
17
17
|
import re
|
|
18
18
|
from rda_python_common import PgLOG
|
|
19
19
|
from rda_python_common import PgDBI
|
|
20
|
-
from rda_python_common import PgIMMA
|
|
21
20
|
from rda_python_common import PgUtil
|
|
22
21
|
|
|
23
22
|
# -t dsid, -e email, -v request data volume, -i data input volume,
|
|
24
23
|
# -m delivery method, -a amount charged, -p pay method, -d request date, -x close date,
|
|
25
|
-
# -y close time, -c file count, -s specialist login name, -o order id,
|
|
24
|
+
# -y close time, -c file count, -s specialist login name, -o order id,
|
|
26
25
|
# mandatory options: -t, -e, -v, and -m
|
|
27
26
|
|
|
28
27
|
#
|
|
@@ -63,7 +62,7 @@ def add_one_order(params):
|
|
|
63
62
|
|
|
64
63
|
year = None
|
|
65
64
|
record = {}
|
|
66
|
-
|
|
65
|
+
|
|
67
66
|
record['dsid'] = params['t']
|
|
68
67
|
record['wuid_request'] = params['u']
|
|
69
68
|
record['dss_uname'] = params['s']
|
|
@@ -100,7 +99,7 @@ def add_to_allusage(record, year, ctime):
|
|
|
100
99
|
pgrec['method'] = record['method']
|
|
101
100
|
pgrec['source'] = 'O'
|
|
102
101
|
return PgDBI.add_yearly_allusage(year, pgrec)
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
return 0
|
|
105
104
|
|
|
106
105
|
#
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#
|
|
2
|
+
##################################################################################
|
|
3
|
+
#
|
|
4
|
+
# Title: pgsyspath
|
|
5
|
+
# Author: Zaihua Ji, zji@ucar.edu
|
|
6
|
+
# Date: 10/21/2020
|
|
7
|
+
# Purpose: python script to set sys.path properly to include paths for local
|
|
8
|
+
# modules
|
|
9
|
+
#
|
|
10
|
+
# Work File: $DSSHOME/bin/python/pgsyspath.py*
|
|
11
|
+
# Github: https://github.com/NCAR/rda-utility-programs.git
|
|
12
|
+
#
|
|
13
|
+
##################################################################################
|
|
14
|
+
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# intinialize the sys.path to include paths for local modules
|
|
21
|
+
#
|
|
22
|
+
def include_local_paths():
|
|
23
|
+
|
|
24
|
+
rpath = '/glade/u/home/rdadata'
|
|
25
|
+
if re.match('PG', rpath): rpath = os.getenv('DSSHOME', '/glade/u/home/rdadata')
|
|
26
|
+
|
|
27
|
+
# add more path to pgpaths list as needed
|
|
28
|
+
pgpaths = [rpath + '/lib/python',
|
|
29
|
+
rpath + '/lib/python/site-packages']
|
|
30
|
+
for pgpath in pgpaths:
|
|
31
|
+
if pgpath not in sys.path: sys.path.insert(0, pgpath)
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# call to include local paths when this module is imported or run independently
|
|
35
|
+
#
|
|
36
|
+
include_local_paths()
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewordusage.py
RENAMED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
import os
|
|
15
15
|
import re
|
|
16
16
|
import sys
|
|
17
|
-
import pgsyspath
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import PgDBI
|
|
17
|
+
from . import pgsyspath
|
|
18
|
+
from . import PgView
|
|
19
|
+
from rda_python_common import PgLOG
|
|
20
|
+
from rda_python_common import PgUtil
|
|
21
|
+
from rda_python_common import PgDBI
|
|
22
22
|
|
|
23
23
|
VUSG = {
|
|
24
24
|
'SNMS' : "ABCDEFGHIJKLMNOPQRSTVWYZ", # all available short field names in FLDS
|
|
@@ -38,7 +38,7 @@ VUSG = {
|
|
|
38
38
|
# column 0 - column title showing in usage view
|
|
39
39
|
# column 1 - field name in format as shown in select clauses
|
|
40
40
|
# column 2 - field name shown in where condition query string
|
|
41
|
-
# column 3 - table name that the field belongs to
|
|
41
|
+
# column 3 - table name that the field belongs to
|
|
42
42
|
# column 4 - output field length, the longer one of data size and comlun title, determine
|
|
43
43
|
# dynamically if it is 0. Negative values indicate right justification
|
|
44
44
|
# column 5 - precision for floating point value if positive and show total value if not zero
|
|
@@ -76,7 +76,7 @@ FLDS = {
|
|
|
76
76
|
# column 0 - expand ID for group of fields
|
|
77
77
|
# column 1 - field name shown in where condition query string
|
|
78
78
|
# column 2 - field name in format as shown in select clauses
|
|
79
|
-
# column 3 - table name that the field belongs to
|
|
79
|
+
# column 3 - table name that the field belongs to
|
|
80
80
|
EXPAND = {
|
|
81
81
|
# SHRTNM EXPID CNDSTR FIELDNAME TBLNAM
|
|
82
82
|
'D' : ["TIME", "dDmy"],
|
|
@@ -105,7 +105,7 @@ EXPAND = {
|
|
|
105
105
|
# A -- number or records to return
|
|
106
106
|
# c -- array of specified country codes
|
|
107
107
|
# C -- a string of short field names for viewing usages
|
|
108
|
-
# d -- array of specified dates
|
|
108
|
+
# d -- array of specified dates
|
|
109
109
|
# D -- dates range, array of 1 or 2 dates in format of YYYY-MM-DD
|
|
110
110
|
# e -- array of specified email addresses
|
|
111
111
|
# E -- use given date or date range for email notice of data update
|
|
@@ -116,13 +116,13 @@ EXPAND = {
|
|
|
116
116
|
# j -- array of specified projects
|
|
117
117
|
# l -- array of specified last names
|
|
118
118
|
# L -- column delimiter for output
|
|
119
|
-
# m -- array of specified months
|
|
120
|
-
# M -- array of specified download methods
|
|
121
|
-
# n -- array of specified order numbers
|
|
119
|
+
# m -- array of specified months
|
|
120
|
+
# M -- array of specified download methods
|
|
121
|
+
# n -- array of specified order numbers
|
|
122
122
|
# N -- number request range, arrage of 1 or 2 integers
|
|
123
123
|
# o -- array of specified orginization types
|
|
124
124
|
# O -- a string of short field names for sorting on
|
|
125
|
-
# p -- array of specified payment methods
|
|
125
|
+
# p -- array of specified payment methods
|
|
126
126
|
# s -- output data size range, arrage of 1 or 2 sizes in unit of MByte
|
|
127
127
|
# S -- array of login names of specialists who processed the orders
|
|
128
128
|
# t -- array of specified dataset names
|
|
@@ -130,12 +130,12 @@ EXPAND = {
|
|
|
130
130
|
# U -- use given unit for file or data sizes
|
|
131
131
|
# v -- aray of specified roder numbers
|
|
132
132
|
# w -- generate view without totals
|
|
133
|
-
# y -- array of specified years
|
|
133
|
+
# y -- array of specified years
|
|
134
134
|
# z -- generate view including entries without usage
|
|
135
135
|
params = {}
|
|
136
136
|
|
|
137
137
|
# relationship between parameter options and short field names, A option is not
|
|
138
|
-
# related to a field name if it is not in keys %SNS
|
|
138
|
+
# related to a field name if it is not in keys %SNS
|
|
139
139
|
SNS = {
|
|
140
140
|
'c' : 'N', 'd' : 'D', 'D' : 'D', 'e' : 'E', 'g' : 'G', 'i' : 'I', 'j' : 'J',
|
|
141
141
|
'l' : 'L', 'm' : 'M', 'M' : 'W', 'n' : 'V', 'N' : 'H', 'o' : 'O', 'p' : 'K',
|
|
@@ -194,18 +194,18 @@ def main():
|
|
|
194
194
|
params[option] = 1
|
|
195
195
|
elif inputs:
|
|
196
196
|
params[option] = inputs # record input array
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
if not params:
|
|
199
199
|
PgLOG.show_usage(pgname)
|
|
200
200
|
else:
|
|
201
201
|
check_enough_options()
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
if 'o' not in params:
|
|
204
204
|
if 'e' not in params:
|
|
205
205
|
params['o'] = ['!', "'DSS'"] # default to exclude 'DSS' for organization
|
|
206
206
|
elif params['o'][0] == "'ALL'":
|
|
207
207
|
del params['o']
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
usgtable = "ousage"
|
|
210
210
|
build_query_strings(usgtable) # build tablenames, fieldnames, and conditions
|
|
211
211
|
records = PgDBI.pgmget(tablenames, fieldnames, condition, PgLOG.UCLWEX)
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
import os
|
|
17
17
|
import re
|
|
18
18
|
import sys
|
|
19
|
-
import PgLOG
|
|
20
|
-
import PgUtil
|
|
21
|
-
import PgDBI
|
|
19
|
+
from rda_python_common import PgLOG
|
|
20
|
+
from rda_python_common import PgUtil
|
|
21
|
+
from rda_python_common import PgDBI
|
|
22
22
|
from . import PgView
|
|
23
23
|
|
|
24
24
|
FILE = {
|
|
@@ -38,9 +38,9 @@ FILE = {
|
|
|
38
38
|
# column 0 - column title showing in mss file view
|
|
39
39
|
# column 1 - field name in format as shown in select clauses
|
|
40
40
|
# column 2 - field name shown in where condition query string
|
|
41
|
-
# column 3 - table name that the field belongs to
|
|
41
|
+
# column 3 - table name that the field belongs to
|
|
42
42
|
# column 4 - output field length, the longer one of data size and comlun title, determine
|
|
43
|
-
# dynamically if it is 0. Negative values indicate right justification
|
|
43
|
+
# dynamically if it is 0. Negative values indicate right justification
|
|
44
44
|
# column 5 - precision for floating point value if positive and show total value if not zero
|
|
45
45
|
# column 6 - field flag to indicate it is a group, distinct or sum field
|
|
46
46
|
FLDS = {
|
|
@@ -77,7 +77,7 @@ FLDS = {
|
|
|
77
77
|
# a -- 1 to view all usage info available
|
|
78
78
|
# A -- number or records to return
|
|
79
79
|
# C -- a string of short field names for viewing usages
|
|
80
|
-
# d -- array of specified dates of file last written
|
|
80
|
+
# d -- array of specified dates of file last written
|
|
81
81
|
# D -- last written dates range, array of 1 or 2 dates in format of YYYY-MM-DD
|
|
82
82
|
# e -- array of specified email addresses
|
|
83
83
|
# f -- array of specified online file names
|
|
@@ -90,16 +90,16 @@ FLDS = {
|
|
|
90
90
|
# J -- 1 to include group title for GROUP
|
|
91
91
|
# l -- array of specified last names
|
|
92
92
|
# L -- column delimiter for output
|
|
93
|
-
# m -- array of specified months of file last written
|
|
94
|
-
# M -- array of specified months of file created
|
|
95
|
-
# n -- array of specified user numbers
|
|
93
|
+
# m -- array of specified months of file last written
|
|
94
|
+
# M -- array of specified months of file created
|
|
95
|
+
# n -- array of specified user numbers
|
|
96
96
|
# D -- dates range, datasets created between, array of 1 or 2 dates in format of YYYY-MM-DD
|
|
97
97
|
# o -- array of specified file status
|
|
98
98
|
# O -- a string of short field names for sorting on
|
|
99
99
|
# p -- array of web file types, Data, Document, and etc.
|
|
100
100
|
# r -- group index range, array of 1 or 2 group indices
|
|
101
101
|
# s -- file size range, arrage of 1 or 2 sizes in unit of MByte
|
|
102
|
-
# S -- specialist lognames who handle the datasets
|
|
102
|
+
# S -- specialist lognames who handle the datasets
|
|
103
103
|
# t -- array of specified dataset names
|
|
104
104
|
# T -- dataset range, array of 1 or 2 dataset names
|
|
105
105
|
# u -- array of specified specialist user names
|
|
@@ -113,7 +113,7 @@ FLDS = {
|
|
|
113
113
|
params = {}
|
|
114
114
|
|
|
115
115
|
# relationship between parameter options and short field names, A option is not
|
|
116
|
-
# related to a field name if it is not in keys %SNS
|
|
116
|
+
# related to a field name if it is not in keys %SNS
|
|
117
117
|
SNS = {
|
|
118
118
|
'd' : 'D', 'D' : 'D', 'e' : 'E', 'f' : 'F', 'F' : 'F', 'g' : 'G', 'i' : 'I',
|
|
119
119
|
'l' : 'L', 'm' : 'M', 'M' : 'H', 'N' : 'N', 'o' : 'O', 'p' : 'P', 'r' : 'G',
|
|
@@ -174,7 +174,7 @@ def main():
|
|
|
174
174
|
params[option] = 1
|
|
175
175
|
elif inputs:
|
|
176
176
|
params[option] = inputs # record input array
|
|
177
|
-
|
|
177
|
+
|
|
178
178
|
if not params:
|
|
179
179
|
PgLOG.show_usage(pgname)
|
|
180
180
|
else:
|
|
@@ -196,7 +196,7 @@ def main():
|
|
|
196
196
|
PgView.simple_output(params, FLDS, records, totals)
|
|
197
197
|
|
|
198
198
|
PgLOG.pgexit(0)
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
#
|
|
201
201
|
# cehck if enough information entered on command line for generate view/report, exit if not
|
|
202
202
|
#
|
|
@@ -209,7 +209,7 @@ def check_enough_options():
|
|
|
209
209
|
if sn == 'X': continue # do not process INDEX field
|
|
210
210
|
if FILE['SNMS'].find(sn) < 0:
|
|
211
211
|
PgLOG.pglog("{}: Field {} must be in field names '{}X'".format(pgname, sn, FILE['SNMS']), PgLOG.LGWNEX)
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
if 'g' in params or 'G' in params:
|
|
214
214
|
if 't' not in params:
|
|
215
215
|
PgLOG.pglog("Miss dataset condition via Option -t for processing Group", PgLOG.LGWNEX)
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9/src/rda_python_metrics.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_metrics
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.9
|
|
4
4
|
Summary: RDA Python Package to gather and view data usage metrics
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-metrics
|
|
@@ -13,6 +13,9 @@ Description-Content-Type: text/markdown
|
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: rda_python_common
|
|
15
15
|
Requires-Dist: rda_python_setuid
|
|
16
|
+
Requires-Dist: geoip2
|
|
17
|
+
Requires-Dist: ipinfo
|
|
18
|
+
Requires-Dist: httplib2
|
|
16
19
|
Dynamic: license-file
|
|
17
20
|
|
|
18
21
|
RDA Python Package to gather and view data usage metrics.
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/SOURCES.txt
RENAMED
|
@@ -7,6 +7,8 @@ src/rda_python_metrics/PgView.py
|
|
|
7
7
|
src/rda_python_metrics/__init__.py
|
|
8
8
|
src/rda_python_metrics/fillawsusage.py
|
|
9
9
|
src/rda_python_metrics/fillawsusage.usg
|
|
10
|
+
src/rda_python_metrics/fillcdgusage.py
|
|
11
|
+
src/rda_python_metrics/fillcdgusage.usg
|
|
10
12
|
src/rda_python_metrics/fillcodusage.py
|
|
11
13
|
src/rda_python_metrics/fillcodusage.usg
|
|
12
14
|
src/rda_python_metrics/fillcountry.py
|
|
@@ -28,6 +30,7 @@ src/rda_python_metrics/filluser.usg
|
|
|
28
30
|
src/rda_python_metrics/logarch.py
|
|
29
31
|
src/rda_python_metrics/logarch.usg
|
|
30
32
|
src/rda_python_metrics/pgperson.py
|
|
33
|
+
src/rda_python_metrics/pgsyspath.py
|
|
31
34
|
src/rda_python_metrics/pgusername.py
|
|
32
35
|
src/rda_python_metrics/viewallusage.py
|
|
33
36
|
src/rda_python_metrics/viewallusage.usg
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[console_scripts]
|
|
2
2
|
fillawsusage = rda_python_metrics.fillaswusage:main
|
|
3
|
+
fillcdgusage = rda_python_metrics.fillcdgusage:main
|
|
3
4
|
fillcodusage = rda_python_metrics.fillcodusage:main
|
|
4
5
|
fillcountry = rda_python_metrics.fillcountry:main
|
|
5
6
|
fillendtime = rda_python_metrics.fillendtime:main
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# test_metrics.py
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_metrics():
|
|
8
|
+
import rda_python_metrics.fillawsusage
|
|
9
|
+
import rda_python_metrics.fillcodusage
|
|
10
|
+
import rda_python_metrics.fillcountry
|
|
11
|
+
import rda_python_metrics.fillendtime
|
|
12
|
+
import rda_python_metrics.fillglobususage
|
|
13
|
+
import rda_python_metrics.fillipinfo
|
|
14
|
+
import rda_python_metrics.filloneorder
|
|
15
|
+
import rda_python_metrics.fillosdfusage
|
|
16
|
+
import rda_python_metrics.fillrdadb
|
|
17
|
+
import rda_python_metrics.filltdsusage
|
|
18
|
+
import rda_python_metrics.filluser
|
|
19
|
+
import rda_python_metrics.logarch
|
|
20
|
+
import rda_python_metrics.PgIPInfo
|
|
21
|
+
import rda_python_metrics.pgperson
|
|
22
|
+
import rda_python_metrics.pgusername
|
|
23
|
+
import rda_python_metrics.PgView
|
|
24
|
+
import rda_python_metrics.viewallusage
|
|
25
|
+
import rda_python_metrics.viewcheckusage
|
|
26
|
+
import rda_python_metrics.viewcodusage
|
|
27
|
+
import rda_python_metrics.viewordusage
|
|
28
|
+
import rda_python_metrics.viewrqstusage
|
|
29
|
+
import rda_python_metrics.viewtdsusage
|
|
30
|
+
import rda_python_metrics.viewwebfile
|
|
31
|
+
import rda_python_metrics.viewwebusage
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
include src/rda_python_metrics/fillawsusage.usg
|
|
2
|
-
include src/rda_python_metrics/fillcodusage.usg
|
|
3
|
-
include src/rda_python_metrics/fillglobususage.usg
|
|
4
|
-
include src/rda_python_metrics/fillipinfo.usg
|
|
5
|
-
include src/rda_python_metrics/filloneorder.usg
|
|
6
|
-
include src/rda_python_metrics/fillosdfusage.usg
|
|
7
|
-
include src/rda_python_metrics/fillrdadb.usg
|
|
8
|
-
include src/rda_python_metrics/filltdsusage.usg
|
|
9
|
-
include src/rda_python_metrics/filluser.usg
|
|
10
|
-
include src/rda_python_metrics/logarch.usg
|
|
11
|
-
include src/rda_python_metrics/viewallusage.usg
|
|
12
|
-
include src/rda_python_metrics/viewcheckusage.usg
|
|
13
|
-
include src/rda_python_metrics/viewcodusage.usg
|
|
14
|
-
include src/rda_python_metrics/viewordusage.usg
|
|
15
|
-
include src/rda_python_metrics/viewrqstusage.usg
|
|
16
|
-
include src/rda_python_metrics/viewtdsusage.usg
|
|
17
|
-
include src/rda_python_metrics/viewwebfile.usg
|
|
18
|
-
include src/rda_python_metrics/viewallusage.usg
|
|
19
|
-
include src/rda_python_metrics/viewwebusage.usg
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillawsusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillcodusage.py
RENAMED
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillglobususage.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filloneorder.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillosdfusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/fillosdfusage.usg
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filltdsusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/filltdsusage.usg
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewallusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewallusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcheckusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcheckusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcodusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewcodusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewordusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewrqstusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewrqstusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewtdsusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewtdsusage.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebfile.usg
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebusage.py
RENAMED
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics/viewwebusage.usg
RENAMED
|
File without changes
|
|
File without changes
|
{rda_python_metrics-1.0.7 → rda_python_metrics-1.0.9}/src/rda_python_metrics.egg-info/top_level.txt
RENAMED
|
File without changes
|