https://github.com/skjolber/inline-histogram
Inline text histogram
https://github.com/skjolber/inline-histogram
histogram java logging stackdriver text
Last synced: 9 months ago
JSON representation
Inline text histogram
- Host: GitHub
- URL: https://github.com/skjolber/inline-histogram
- Owner: skjolber
- License: apache-2.0
- Created: 2023-10-14T16:30:09.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T09:59:31.000Z (over 1 year ago)
- Last Synced: 2025-02-13T00:29:40.130Z (11 months ago)
- Topics: histogram, java, logging, stackdriver, text
- Language: Java
- Homepage:
- Size: 84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://mvnrepository.com/artifact/com.github.skjolber.histogram/inline)
# inline-histogram
Simple utility for visualizing a histogram in a single line of text, using [box-drawing-characters](https://en.wikipedia.org/wiki/Box-drawing_character).
Features:
* generate normalized text histograms:
* Vanilla:
* ▁▂▃▅▆▇
* Labels:
* 0s▕ ▁▂▃▃▅▆▇ ▏5s
* Indicator:
* ▁▂▃▅⭐▆▇
The library is primarily intended for simple visualization of HTTP request durations in logs.
## License
[Apache 2.0]
## Obtain
The project is built with [Maven] and is available on the central Maven repository.
Maven coordinates
Add the property
```xml
1.0.0
```
then add
```xml
com.github.skjolber.histogram
inline
${inline-histogram.version}
```
or
Gradle coordinates
For
```groovy
ext {
inlineHistogramVersion = '1.0.0'
}
```
add
```groovy
api ("com.github.skjolber.histogram:inline:${inlineHistogramVersion}")
```
# Usage
So we want to create a `HistogramCharSequence`. The `DefaultHistogram` implementation is a fixed size histogram with thread-safe counters.
```
DefaultHistogram histogram = DefaultHistogram.newBuilder()
.add(0, "0s")
.add(250)
.add(500)
.add(750)
.add(1000, "1000s")
.build();
```
then update by index
```
histogram.incrementByIndex(1);
```
or value
```
histogram.incrementByValue(444);
```
when it is time to see the results, get the `HistogramCharSequence` and print it.
```
HistogramCharSequence sequence = HistogramCharSequenceFactory.newInstance(histogram);
LOGGER.info("https://... HTTP 200 in 444ms " + sequence);
```
Note that resolution is limited to 9 levels.
# Supported tools
Support depends on the font used in the log accumulation tool. This implementation has been tested with
* GCP's Stackdriver
Example:
* 0 to 10 second histogram, with
* 250 ms slots, and
* labels, with
* indicator (⭐) for the current request

[Apache 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html
[issue-tracker]: https://github.com/skjolber/inline-histogram/issues
[Maven]: http://maven.apache.org/