noctolog 0.1.0__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.
- noctolog-0.1.0/LICENSE +202 -0
- noctolog-0.1.0/MANIFEST.in +5 -0
- noctolog-0.1.0/PKG-INFO +205 -0
- noctolog-0.1.0/README.md +178 -0
- noctolog-0.1.0/examples/dashboard_demo.py +85 -0
- noctolog-0.1.0/examples/demo_app.py +61 -0
- noctolog-0.1.0/examples/make_sample_log.py +72 -0
- noctolog-0.1.0/examples/multi_worker_demo.py +76 -0
- noctolog-0.1.0/pyproject.toml +48 -0
- noctolog-0.1.0/setup.cfg +4 -0
- noctolog-0.1.0/src/noctolog/__init__.py +29 -0
- noctolog-0.1.0/src/noctolog/__main__.py +3 -0
- noctolog-0.1.0/src/noctolog/analyze.py +273 -0
- noctolog-0.1.0/src/noctolog/cli.py +377 -0
- noctolog-0.1.0/src/noctolog/display.py +163 -0
- noctolog-0.1.0/src/noctolog/durations.py +39 -0
- noctolog-0.1.0/src/noctolog/engine.py +259 -0
- noctolog-0.1.0/src/noctolog/masking.py +36 -0
- noctolog-0.1.0/src/noctolog/parse.py +168 -0
- noctolog-0.1.0/src/noctolog/patterns.py +242 -0
- noctolog-0.1.0/src/noctolog/protocol.py +6 -0
- noctolog-0.1.0/src/noctolog/redact.py +62 -0
- noctolog-0.1.0/src/noctolog/sdk.py +493 -0
- noctolog-0.1.0/src/noctolog/sender.py +198 -0
- noctolog-0.1.0/src/noctolog/server.py +605 -0
- noctolog-0.1.0/src/noctolog/static/dashboard.css +189 -0
- noctolog-0.1.0/src/noctolog/static/dashboard.html +77 -0
- noctolog-0.1.0/src/noctolog/static/dashboard.js +397 -0
- noctolog-0.1.0/src/noctolog/static/favicon.svg +1 -0
- noctolog-0.1.0/src/noctolog/static/login.html +24 -0
- noctolog-0.1.0/src/noctolog/static/login.js +34 -0
- noctolog-0.1.0/src/noctolog/stats.py +135 -0
- noctolog-0.1.0/src/noctolog/store.py +723 -0
- noctolog-0.1.0/src/noctolog.egg-info/PKG-INFO +205 -0
- noctolog-0.1.0/src/noctolog.egg-info/SOURCES.txt +49 -0
- noctolog-0.1.0/src/noctolog.egg-info/dependency_links.txt +1 -0
- noctolog-0.1.0/src/noctolog.egg-info/entry_points.txt +2 -0
- noctolog-0.1.0/src/noctolog.egg-info/requires.txt +3 -0
- noctolog-0.1.0/src/noctolog.egg-info/top_level.txt +1 -0
- noctolog-0.1.0/tests/test_analyze.py +52 -0
- noctolog-0.1.0/tests/test_cli.py +53 -0
- noctolog-0.1.0/tests/test_dashboard.py +221 -0
- noctolog-0.1.0/tests/test_engine.py +118 -0
- noctolog-0.1.0/tests/test_integration_safety.py +162 -0
- noctolog-0.1.0/tests/test_parse.py +59 -0
- noctolog-0.1.0/tests/test_patterns.py +69 -0
- noctolog-0.1.0/tests/test_redact_masking.py +27 -0
- noctolog-0.1.0/tests/test_sdk.py +152 -0
- noctolog-0.1.0/tests/test_server.py +141 -0
- noctolog-0.1.0/tests/test_stats.py +70 -0
- noctolog-0.1.0/tests/test_store.py +119 -0
noctolog-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
noctolog-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: noctolog
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Watches your logs while you sleep: groups log lines into patterns and flags new errors and spikes.
|
|
5
|
+
Author: noctolog contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: logging,logs,log-analysis,anomaly-detection,observability,monitoring
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: System Administrators
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: System :: Logging
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# noctolog
|
|
29
|
+
|
|
30
|
+
**Watches your logs while you sleep.**
|
|
31
|
+
|
|
32
|
+
noctolog turns thousands of log lines into a short list of patterns, then tells
|
|
33
|
+
you which ones are **new** and which ones are **spiking**. No servers, no
|
|
34
|
+
setup, no dependencies.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
50,000 lines -> 14 patterns -> "Login failures on site A are 60x normal since 12:00"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install noctolog
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Python 3.9+, no dependencies, works on Windows, macOS and Linux.
|
|
45
|
+
|
|
46
|
+
> Status: alpha (v0.1). Analyzer, SDK, collector and dashboard work today;
|
|
47
|
+
> AI explanations and Slack/webhook alerts are on the roadmap below.
|
|
48
|
+
|
|
49
|
+
## In your app: two lines
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import noctolog
|
|
53
|
+
noctolog.init()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
That's it. noctolog hooks into Python's standard `logging`, watches every log
|
|
57
|
+
call in the background, and prints an alert the moment something changes:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
noctolog 12:00:44 SPIKE 42x ERROR Login failed for user <*> on site A (66 in 1m, usually ~2)
|
|
61
|
+
noctolog 13:00:43 NEW ERROR Timeout connecting to payment gateway after <*> (7 in 1m)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When your app exits, it prints the full pattern report.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
noctolog.init(
|
|
68
|
+
window="1m", # counting window
|
|
69
|
+
warmup=5, # windows to learn "normal" before alerting
|
|
70
|
+
level=logging.INFO, # lowest level to watch
|
|
71
|
+
on_flag=callback, # your function, called with each alert
|
|
72
|
+
print_alerts=True,
|
|
73
|
+
report_at_exit=True,
|
|
74
|
+
)
|
|
75
|
+
noctolog.report() # snapshot at any time
|
|
76
|
+
noctolog.shutdown()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
It is built to never hurt your app:
|
|
80
|
+
|
|
81
|
+
- **Fast:** a log call costs about 2-3 µs extra on your app's thread. Everything else
|
|
82
|
+
runs on one background thread.
|
|
83
|
+
- **Never blocks:** if logs arrive faster than they can be analyzed, entries are
|
|
84
|
+
skipped and counted, never waited on.
|
|
85
|
+
- **Never crashes:** every internal error is swallowed.
|
|
86
|
+
- **Fork-safe:** works with gunicorn and multiprocessing workers.
|
|
87
|
+
- **Leaves your logging alone:** call `init()` before or after your own `logging.basicConfig()`.
|
|
88
|
+
Your log files and console output work exactly as before.
|
|
89
|
+
- **Exits promptly:** shutdown takes under about 1 second even if the collector is down
|
|
90
|
+
(no wait at all once it is known to be down).
|
|
91
|
+
|
|
92
|
+
Try the 20-second demo: `python examples/demo_app.py`
|
|
93
|
+
|
|
94
|
+
## Many workers and servers: the collector
|
|
95
|
+
|
|
96
|
+
One app process only sees its own logs. For gunicorn workers or a fleet of
|
|
97
|
+
servers, run one collector and point every process at it:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
noctolog keys create --name web-servers # prints a key, once
|
|
101
|
+
noctolog serve --host 0.0.0.0 --port 7000
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
noctolog.init(collector="http://monitor:7000", api_key="nlk_...", service="shop")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
or with no code change, via environment variables: `NOCTOLOG_COLLECTOR`,
|
|
109
|
+
`NOCTOLOG_KEY`, `NOCTOLOG_SERVICE`, `NOCTOLOG_HOST`.
|
|
110
|
+
|
|
111
|
+
Each worker groups its own lines and sends only **pattern counts plus one
|
|
112
|
+
redacted sample** every 5 seconds (a few KB). The collector merges them, so a
|
|
113
|
+
problem spread thinly across 20 workers is still caught, and it alerts once.
|
|
114
|
+
Try it: `python examples/multi_worker_demo.py`
|
|
115
|
+
|
|
116
|
+
**Security, on by default**
|
|
117
|
+
|
|
118
|
+
- Listens on `127.0.0.1` only. It refuses to listen on the network until an API key exists.
|
|
119
|
+
- Keys are stored hashed, can be revoked one at a time, and each has one scope
|
|
120
|
+
(`ingest` for apps, `read` for the API). Each key is rate-limited.
|
|
121
|
+
- HTTPS with `--cert`/`--key`, or put it behind nginx or Caddy. It warns if you're on the network without TLS.
|
|
122
|
+
- Secrets are redacted in the worker before sending, and again in the collector.
|
|
123
|
+
|
|
124
|
+
**Dashboard**
|
|
125
|
+
|
|
126
|
+
Open the collector's address in a browser (`http://127.0.0.1:7000/`). It shows
|
|
127
|
+
live summary cards, every pattern with its trend, and problems first. Filter by
|
|
128
|
+
service, host, time range or text. Click a pattern to see when it was flagged,
|
|
129
|
+
example lines from that moment, and **which hosts** it came from. Admins can
|
|
130
|
+
mute a noisy pattern: it is still counted, but stops alerting.
|
|
131
|
+
|
|
132
|
+
Until you create a user, the dashboard only opens on the collector's own
|
|
133
|
+
machine. To open it from elsewhere:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
noctolog users create --name ann --role admin # asks for a password (10+ chars)
|
|
137
|
+
noctolog users list | noctolog users password ann | noctolog users delete ann
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Passwords are hashed with scrypt. Sessions use HttpOnly, SameSite=Strict cookies.
|
|
141
|
+
Logins are rate-limited, and the page runs under a strict Content-Security-Policy.
|
|
142
|
+
Scripts can read the same data with a `read` API key: `GET /api/v1/dashboard`.
|
|
143
|
+
|
|
144
|
+
Try it with live fake traffic: `python examples/dashboard_demo.py`, then open http://127.0.0.1:7070
|
|
145
|
+
|
|
146
|
+
**Storage you control**
|
|
147
|
+
|
|
148
|
+
Only counts and a few samples are stored (SQLite), never raw logs.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
noctolog serve --detail-retention 24h --history-retention 90d --max-db-size 1GB
|
|
152
|
+
noctolog data clear --older-than 30d # or --host old-box, or --pattern 12 (asks to confirm)
|
|
153
|
+
noctolog keys list | noctolog keys revoke 3
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If the collector is down, workers keep batches for about 10 minutes and retry with
|
|
157
|
+
backoff. Apps are never affected.
|
|
158
|
+
|
|
159
|
+
## On log files
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install -e .
|
|
163
|
+
python examples/make_sample_log.py
|
|
164
|
+
noctolog analyze examples/sample.log
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## How it works
|
|
168
|
+
|
|
169
|
+
1. **Redact** secrets (passwords, tokens, emails, card numbers) before anything else.
|
|
170
|
+
2. **Mask** values that change every line (numbers, IPs, UUIDs, hex IDs).
|
|
171
|
+
3. **Group** similar lines into patterns with a fast tree-based algorithm (Drain).
|
|
172
|
+
Multi-line tracebacks count as one entry.
|
|
173
|
+
4. **Count** each pattern per time window (default 1 minute).
|
|
174
|
+
5. **Flag** patterns that appear for the first time (NEW) or jump far above their
|
|
175
|
+
usual rate (SPIKE).
|
|
176
|
+
|
|
177
|
+
## Command line
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
noctolog analyze FILE [FILE ...]
|
|
181
|
+
--window 1m counting window (30s, 1m, 5m, 1h)
|
|
182
|
+
--top 20 how many patterns to show (--all for every one)
|
|
183
|
+
--json machine-readable output
|
|
184
|
+
--similarity 0.7 how alike lines must be to share a pattern
|
|
185
|
+
--spike-factor 5 spike = this many times the usual count
|
|
186
|
+
--min-spike 10 ignore spikes smaller than this per window
|
|
187
|
+
--warmup 5 windows used to learn "normal" first
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Roadmap
|
|
191
|
+
|
|
192
|
+
- [x] File analyzer: patterns, new/spike detection, terminal report
|
|
193
|
+
- [x] SDK: `noctolog.init()` hooks into Python logging, never blocks your app
|
|
194
|
+
- [x] Collector (`noctolog serve`) for many workers and servers, with API keys
|
|
195
|
+
- [x] Live dashboard, with logins and muting
|
|
196
|
+
- [ ] Built-in error classifier and optional tiny local LLM explanations
|
|
197
|
+
- [ ] Alerts (Slack, webhooks)
|
|
198
|
+
|
|
199
|
+
## Privacy
|
|
200
|
+
|
|
201
|
+
noctolog never sends anything anywhere. There is no telemetry.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
Apache-2.0
|
noctolog-0.1.0/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# noctolog
|
|
2
|
+
|
|
3
|
+
**Watches your logs while you sleep.**
|
|
4
|
+
|
|
5
|
+
noctolog turns thousands of log lines into a short list of patterns, then tells
|
|
6
|
+
you which ones are **new** and which ones are **spiking**. No servers, no
|
|
7
|
+
setup, no dependencies.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
50,000 lines -> 14 patterns -> "Login failures on site A are 60x normal since 12:00"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install noctolog
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Python 3.9+, no dependencies, works on Windows, macOS and Linux.
|
|
18
|
+
|
|
19
|
+
> Status: alpha (v0.1). Analyzer, SDK, collector and dashboard work today;
|
|
20
|
+
> AI explanations and Slack/webhook alerts are on the roadmap below.
|
|
21
|
+
|
|
22
|
+
## In your app: two lines
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import noctolog
|
|
26
|
+
noctolog.init()
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
That's it. noctolog hooks into Python's standard `logging`, watches every log
|
|
30
|
+
call in the background, and prints an alert the moment something changes:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
noctolog 12:00:44 SPIKE 42x ERROR Login failed for user <*> on site A (66 in 1m, usually ~2)
|
|
34
|
+
noctolog 13:00:43 NEW ERROR Timeout connecting to payment gateway after <*> (7 in 1m)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
When your app exits, it prints the full pattern report.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
noctolog.init(
|
|
41
|
+
window="1m", # counting window
|
|
42
|
+
warmup=5, # windows to learn "normal" before alerting
|
|
43
|
+
level=logging.INFO, # lowest level to watch
|
|
44
|
+
on_flag=callback, # your function, called with each alert
|
|
45
|
+
print_alerts=True,
|
|
46
|
+
report_at_exit=True,
|
|
47
|
+
)
|
|
48
|
+
noctolog.report() # snapshot at any time
|
|
49
|
+
noctolog.shutdown()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It is built to never hurt your app:
|
|
53
|
+
|
|
54
|
+
- **Fast:** a log call costs about 2-3 µs extra on your app's thread. Everything else
|
|
55
|
+
runs on one background thread.
|
|
56
|
+
- **Never blocks:** if logs arrive faster than they can be analyzed, entries are
|
|
57
|
+
skipped and counted, never waited on.
|
|
58
|
+
- **Never crashes:** every internal error is swallowed.
|
|
59
|
+
- **Fork-safe:** works with gunicorn and multiprocessing workers.
|
|
60
|
+
- **Leaves your logging alone:** call `init()` before or after your own `logging.basicConfig()`.
|
|
61
|
+
Your log files and console output work exactly as before.
|
|
62
|
+
- **Exits promptly:** shutdown takes under about 1 second even if the collector is down
|
|
63
|
+
(no wait at all once it is known to be down).
|
|
64
|
+
|
|
65
|
+
Try the 20-second demo: `python examples/demo_app.py`
|
|
66
|
+
|
|
67
|
+
## Many workers and servers: the collector
|
|
68
|
+
|
|
69
|
+
One app process only sees its own logs. For gunicorn workers or a fleet of
|
|
70
|
+
servers, run one collector and point every process at it:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
noctolog keys create --name web-servers # prints a key, once
|
|
74
|
+
noctolog serve --host 0.0.0.0 --port 7000
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
noctolog.init(collector="http://monitor:7000", api_key="nlk_...", service="shop")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
or with no code change, via environment variables: `NOCTOLOG_COLLECTOR`,
|
|
82
|
+
`NOCTOLOG_KEY`, `NOCTOLOG_SERVICE`, `NOCTOLOG_HOST`.
|
|
83
|
+
|
|
84
|
+
Each worker groups its own lines and sends only **pattern counts plus one
|
|
85
|
+
redacted sample** every 5 seconds (a few KB). The collector merges them, so a
|
|
86
|
+
problem spread thinly across 20 workers is still caught, and it alerts once.
|
|
87
|
+
Try it: `python examples/multi_worker_demo.py`
|
|
88
|
+
|
|
89
|
+
**Security, on by default**
|
|
90
|
+
|
|
91
|
+
- Listens on `127.0.0.1` only. It refuses to listen on the network until an API key exists.
|
|
92
|
+
- Keys are stored hashed, can be revoked one at a time, and each has one scope
|
|
93
|
+
(`ingest` for apps, `read` for the API). Each key is rate-limited.
|
|
94
|
+
- HTTPS with `--cert`/`--key`, or put it behind nginx or Caddy. It warns if you're on the network without TLS.
|
|
95
|
+
- Secrets are redacted in the worker before sending, and again in the collector.
|
|
96
|
+
|
|
97
|
+
**Dashboard**
|
|
98
|
+
|
|
99
|
+
Open the collector's address in a browser (`http://127.0.0.1:7000/`). It shows
|
|
100
|
+
live summary cards, every pattern with its trend, and problems first. Filter by
|
|
101
|
+
service, host, time range or text. Click a pattern to see when it was flagged,
|
|
102
|
+
example lines from that moment, and **which hosts** it came from. Admins can
|
|
103
|
+
mute a noisy pattern: it is still counted, but stops alerting.
|
|
104
|
+
|
|
105
|
+
Until you create a user, the dashboard only opens on the collector's own
|
|
106
|
+
machine. To open it from elsewhere:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
noctolog users create --name ann --role admin # asks for a password (10+ chars)
|
|
110
|
+
noctolog users list | noctolog users password ann | noctolog users delete ann
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Passwords are hashed with scrypt. Sessions use HttpOnly, SameSite=Strict cookies.
|
|
114
|
+
Logins are rate-limited, and the page runs under a strict Content-Security-Policy.
|
|
115
|
+
Scripts can read the same data with a `read` API key: `GET /api/v1/dashboard`.
|
|
116
|
+
|
|
117
|
+
Try it with live fake traffic: `python examples/dashboard_demo.py`, then open http://127.0.0.1:7070
|
|
118
|
+
|
|
119
|
+
**Storage you control**
|
|
120
|
+
|
|
121
|
+
Only counts and a few samples are stored (SQLite), never raw logs.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
noctolog serve --detail-retention 24h --history-retention 90d --max-db-size 1GB
|
|
125
|
+
noctolog data clear --older-than 30d # or --host old-box, or --pattern 12 (asks to confirm)
|
|
126
|
+
noctolog keys list | noctolog keys revoke 3
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
If the collector is down, workers keep batches for about 10 minutes and retry with
|
|
130
|
+
backoff. Apps are never affected.
|
|
131
|
+
|
|
132
|
+
## On log files
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install -e .
|
|
136
|
+
python examples/make_sample_log.py
|
|
137
|
+
noctolog analyze examples/sample.log
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## How it works
|
|
141
|
+
|
|
142
|
+
1. **Redact** secrets (passwords, tokens, emails, card numbers) before anything else.
|
|
143
|
+
2. **Mask** values that change every line (numbers, IPs, UUIDs, hex IDs).
|
|
144
|
+
3. **Group** similar lines into patterns with a fast tree-based algorithm (Drain).
|
|
145
|
+
Multi-line tracebacks count as one entry.
|
|
146
|
+
4. **Count** each pattern per time window (default 1 minute).
|
|
147
|
+
5. **Flag** patterns that appear for the first time (NEW) or jump far above their
|
|
148
|
+
usual rate (SPIKE).
|
|
149
|
+
|
|
150
|
+
## Command line
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
noctolog analyze FILE [FILE ...]
|
|
154
|
+
--window 1m counting window (30s, 1m, 5m, 1h)
|
|
155
|
+
--top 20 how many patterns to show (--all for every one)
|
|
156
|
+
--json machine-readable output
|
|
157
|
+
--similarity 0.7 how alike lines must be to share a pattern
|
|
158
|
+
--spike-factor 5 spike = this many times the usual count
|
|
159
|
+
--min-spike 10 ignore spikes smaller than this per window
|
|
160
|
+
--warmup 5 windows used to learn "normal" first
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Roadmap
|
|
164
|
+
|
|
165
|
+
- [x] File analyzer: patterns, new/spike detection, terminal report
|
|
166
|
+
- [x] SDK: `noctolog.init()` hooks into Python logging, never blocks your app
|
|
167
|
+
- [x] Collector (`noctolog serve`) for many workers and servers, with API keys
|
|
168
|
+
- [x] Live dashboard, with logins and muting
|
|
169
|
+
- [ ] Built-in error classifier and optional tiny local LLM explanations
|
|
170
|
+
- [ ] Alerts (Slack, webhooks)
|
|
171
|
+
|
|
172
|
+
## Privacy
|
|
173
|
+
|
|
174
|
+
noctolog never sends anything anywhere. There is no telemetry.
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
Apache-2.0
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""See the dashboard with live, changing data.
|
|
2
|
+
|
|
3
|
+
python examples/dashboard_demo.py # then open http://127.0.0.1:7070
|
|
4
|
+
|
|
5
|
+
Runs a collector (5 second windows so things happen quickly) and three fake
|
|
6
|
+
servers sending real traffic through the SDK. After ~40s login failures
|
|
7
|
+
spike on one server; after ~70s a brand new timeout error appears.
|
|
8
|
+
Press Ctrl+C to stop.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import os
|
|
15
|
+
import random
|
|
16
|
+
import tempfile
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
|
|
20
|
+
from noctolog.engine import Engine
|
|
21
|
+
from noctolog.sdk import Watcher
|
|
22
|
+
from noctolog.server import Collector, ServerConfig, console_alert
|
|
23
|
+
from noctolog.store import Store
|
|
24
|
+
|
|
25
|
+
PORT = int(os.environ.get("PORT", "7070"))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fake_server(name: str, url: str, started: float, stop: threading.Event) -> None:
|
|
29
|
+
log = logging.getLogger(f"demo.{name}")
|
|
30
|
+
log.setLevel(logging.INFO)
|
|
31
|
+
log.propagate = False
|
|
32
|
+
watcher = Watcher(logger=log, collector=url, service="shop", host=name, send_every=1).start()
|
|
33
|
+
rng = random.Random(name)
|
|
34
|
+
users = ["ram", "sita", "john", "maria", "wei", "aisha"]
|
|
35
|
+
while not stop.is_set():
|
|
36
|
+
elapsed = time.time() - started
|
|
37
|
+
for _ in range(rng.randint(15, 25)):
|
|
38
|
+
log.info("Order %d accepted", rng.randint(1000, 99999))
|
|
39
|
+
for _ in range(rng.randint(5, 10)):
|
|
40
|
+
log.info("Fetched %d orders from 10.0.%d.%d", rng.randint(1, 50), rng.randint(0, 9), rng.randint(1, 254))
|
|
41
|
+
spiking = name == "web-2" and 40 <= elapsed % 120 < 55
|
|
42
|
+
for _ in range(rng.randint(25, 35) if spiking else rng.randint(0, 1)):
|
|
43
|
+
log.error("Login failed for user %s on site A", rng.choice(users))
|
|
44
|
+
if elapsed > 70:
|
|
45
|
+
for _ in range(rng.randint(1, 3)):
|
|
46
|
+
log.error("Timeout connecting to payment gateway after %ss", rng.choice([10, 30]))
|
|
47
|
+
if rng.random() < 0.05:
|
|
48
|
+
log.warning("Slow query on orders table took %dms", rng.randint(800, 3000))
|
|
49
|
+
if rng.random() < 0.02:
|
|
50
|
+
try:
|
|
51
|
+
{}["amount"]
|
|
52
|
+
except KeyError:
|
|
53
|
+
log.exception("Failed to process order %d", rng.randint(1000, 9999))
|
|
54
|
+
stop.wait(1.0)
|
|
55
|
+
watcher.stop()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main() -> None:
|
|
59
|
+
db = os.path.join(tempfile.mkdtemp(), "dashboard-demo.db")
|
|
60
|
+
store = Store(db)
|
|
61
|
+
engine = Engine(store, window=5, grace=1.5, warmup_windows=4, on_event=console_alert())
|
|
62
|
+
collector = Collector(store, engine, ServerConfig(port=PORT)).start()
|
|
63
|
+
print(f"dashboard: {collector.url}/ (Ctrl+C to stop)", flush=True)
|
|
64
|
+
|
|
65
|
+
stop = threading.Event()
|
|
66
|
+
started = time.time()
|
|
67
|
+
threads = [threading.Thread(target=fake_server, args=(f"web-{i}", collector.url, started, stop), daemon=True)
|
|
68
|
+
for i in range(1, 4)]
|
|
69
|
+
for t in threads:
|
|
70
|
+
t.start()
|
|
71
|
+
try:
|
|
72
|
+
while True:
|
|
73
|
+
time.sleep(1)
|
|
74
|
+
except KeyboardInterrupt:
|
|
75
|
+
pass
|
|
76
|
+
finally:
|
|
77
|
+
stop.set()
|
|
78
|
+
for t in threads:
|
|
79
|
+
t.join(3)
|
|
80
|
+
collector.stop()
|
|
81
|
+
store.close()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
main()
|