Skip to content

Commit

Permalink
feat: add devtools metrics
Browse files Browse the repository at this point in the history
Adds a metrics implementation that broadcasts metrics to a browser
DevTools plugin.
  • Loading branch information
achingbrain committed May 17, 2024
1 parent 1cc6a94 commit dba0ca3
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/metrics-devtools/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions packages/metrics-devtools/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions packages/metrics-devtools/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

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.
68 changes: 68 additions & 0 deletions packages/metrics-devtools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# @libp2p/devtools-metrics

[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)

> Collect libp2p metrics and send them to browser DevTools
# About

<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->

Configure your browser-based libp2p node with DevTools metrics:

```typescript
import { createLibp2p } from 'libp2p'
import { devToolsMetrics } from '@libp2p/devtools-metrics'

const node = await createLibp2p({
metrics: devToolsMetrics()
})
```

Then use the [DevTools plugin](https://github.com/ipfs-shipyard/js-libp2p-devtools)
for Chrome or Firefox to inspect the state of your running node.

# Install

```console
$ npm i @libp2p/devtools-metrics
```

## Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `Libp2pDevtoolsMetrics` in the global namespace.

```html
<script src="https://unpkg.com/@libp2p/devtools-metrics/dist/index.min.js"></script>
```

# API Docs

- <https://libp2p.github.io/js-libp2p/modules/_libp2p_devtools_metrics.html>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-devtools/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-devtools/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
63 changes: 63 additions & 0 deletions packages/metrics-devtools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@libp2p/devtools-metrics",
"version": "0.0.0",
"description": "Collect libp2p metrics and send them to browser DevTools",
"author": "",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-devtools#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"project": true,
"sourceType": "module"
}
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test -t browser",
"test:chrome": "aegir test -t browser --cov"
},
"dependencies": {
"@libp2p/interface": "^1.3.1",
"@libp2p/interface-internal": "^1.2.1",
"@libp2p/logger": "^4.0.12",
"@libp2p/simple-metrics": "^1.0.1",
"multiformats": "^13.1.0"
},
"devDependencies": {
"@libp2p/peer-id-factory": "^4.1.1",
"aegir": "^42.2.5",
"race-event": "^1.3.0",
"sinon-ts": "^2.0.0"
},
"sideEffects": false
}
Loading

0 comments on commit dba0ca3

Please sign in to comment.