https://github.com/callumrollo/erddaplogs
Quick utilities for parsing nginx and apache logs for ERDDAP requests
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 4 committers (25.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Repository
Quick utilities for parsing nginx and apache logs for ERDDAP requests
Basic Info
Statistics
- Stars: 0
- Watchers: 4
- Forks: 4
- Open Issues: 2
- Releases: 4
Metadata Files
README.md
erddaplogs
A package for analysing traffic to an ERDDAP server by parsing nginx and apache logs.
Installation
- #### From pypi, using pip
sh
pip install erddaplogs
From conda-forge
sh
conda install -c conda-forge erddaplogs
- #### From the repo, using pip
```sh
First, clone the repo:
git clone https://github.com/callumrollo/erddaplogs.git cd erddaplogs pip install -r requirements-dev.txt # install the dependencies pip install -e . ```
Example usage
First, get the logs copied locally to a directory you can read and unzip them. e.g.:
bash
rsync /var/log/nginx/* logs
gzip -dfr * logs
Next, run erddaplogs
```python from erddaplogs.logparse import ErddapLogParser
parser = ErddapLogParser() parser.loadnginxlogs("exampledata/nginxexamplelogs/") # replace with the path to your logs parser.parsedatasetsxml("exampledata/datasets.xml") # replace with the path to your xml, or remove this line parser.temporalresolution = 'month' # can be any one of 'day', 'month' or 'year'. Defaults to 'month' parser.filternonerddap() parser.filterspam() parser.filterlocales() parser.filteruseragents() parser.filtercommonstrings() parser.getipinfo() # fetches info on ip addresses parser.filterorganisations() parser.parsecolumns() parser.exportdata(output_dir=".") # Put the path to the output dir here. Preferably somewhere your ERDDAP can read ```
This will read nginx logs from the user specified directory and write files <timestamp>_anonymized_requests.csv and <timestamp>_aggregated_locations.csv with anonymized requests and aggregated location data respectively.
timestamp will be YYYY YYYY-MM or YYYY-MM-DD depending on whether the user has set temporal_resolution to year, month or day.
ErddapLogParser can be run on a static directory of logs as a cron job e.g. once per day. If run repeatedly, it will create a new files for anonymized_requests and aggregated_locations using only requests that have been received since the last timestamp (by default, the first day of the current month).
To re-analyze all the input requests, first delete the output files in output_dir then re-run.
All of the filter_ functions are optional, and most take additional kwargs to fine-tune their behaviour.
Share results via ERDDAP
Optionally, the resulting anonymized data can be shared on your ERDDAP in two datasets requests and locations. To do this, add the contents of the example xml files requests.xml and locations.xml from the example_data directory to your datasets.xml. Make sure to update the values of fileDir, institution and change the date variable if not using the default monthly aggregation. The other fields can remain as-is.
You can see what the resulting stats look like on the VOTO ERDDAP server:
- https://erddap.observations.voiceoftheocean.org/erddap/tabledap/requests.html
- https://erddap.observations.voiceoftheocean.org/erddap/tabledap/locations.html
For more analysis options and plots, see the example jupyter notebook
Example Jupyter Notebook
You can find an example Jupyter Notebook weblogs-parse-demo.ipynb in the notebooks directory. It performs the following steps:
- Reads in apache and nginx logs, combine them into one consistent dataframe
- Find the ips that made the greatest number of requests. Get their info from ip-api.com
- Remove suspected spam/bot requests
- Classify user data by identifying user agents, matching requets to dataset type etc.
- Perform basic analysis to graph number of requests and users over time, most popular datasets/datatypes and geographic distribution of users
- Anonymize user data and write them to file
A rather out od date blog post explaining this notebook in more detail can be found at https://callumrollo.com/weblogparse.html
A second notebook called analyze_anonymized_usage shows some examples of plotting the anonymized datasets made available on the VOTO ERDDAP
A note on example data
If you don't have your own ERDDAP logs to hand, you can use the example data in example_data/nginx_example_logs. This is anonymized data from a production ERDDAP server erddap.observations.voiceoftheocean.org. The ip addresses have been randomly generated, as have the user agents. All subscription emails have been replaced with fake@example.com
Logging best practices
- The log loading function can be run sequentially over a series of directories if you have logs in sevaral places.
- You must retain logs for at least as long as your temporal resolution! If you only retain logs for 3 days, but aggregate data by month, some data will be lost.
- The default of many servers is to delete logs after a short period of time. Check the settings of logrotate in e.g.
/etc/logrotate.d/nginx - Check your institution's policies on log retention
- If you set a very fine temporal resolution like
dayon a server that receives little traffic, you may make enable partial re-identification, linking e.g. the full request url with the city/region of the user who sent it.
License
This project is licensed under MIT.
Owner
- Name: Callum Rollo
- Login: callumrollo
- Kind: user
- Location: Gothenburg, Sweden
- Company: Voice of the Ocean Foundation
- Website: https://callumrollo.github.io/
- Repositories: 86
- Profile: https://github.com/callumrollo
Oceanographer, Pythonista and data science-ish. Breaks things on Fridays
GitHub Events
Total
- Push event: 5
- Pull request event: 1
- Create event: 2
Last Year
- Push event: 5
- Pull request event: 1
- Create event: 2
Committers
Last synced: about 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Callum Rollo | c****o@o****m | 48 |
| Chris John | c****n@n****v | 11 |
| Ana Krelling | a****a@a****m | 6 |
| Tuomo S | t****a@g****m | 4 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 40
- Total pull requests: 65
- Average time to close issues: 4 days
- Average time to close pull requests: about 1 hour
- Total issue authors: 2
- Total pull request authors: 4
- Average comments per issue: 1.03
- Average comments per pull request: 0.35
- Merged pull requests: 61
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 4
- Pull requests: 19
- Average time to close issues: 8 days
- Average time to close pull requests: about 1 hour
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.5
- Average comments per pull request: 0.05
- Merged pull requests: 17
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- callumrollo (23)
- ChrisJohnNOAA (3)
Pull Request Authors
- callumrollo (61)
- ChrisJohnNOAA (9)
- apkrelling (8)
- aalloilla (6)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 49 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 8
- Total maintainers: 1
pypi.org: erddaplogs
Parse log files from an ERDDAP server
- Documentation: https://erddaplogs.readthedocs.io/
- License: MIT License Copyright (c) 2023 Callum Rollo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.1.4
published almost 2 years ago