ambareesha7
i hava this plain text(metrics):
"""
# HELP app_name_self_repair_duration
# TYPE app_name_self_repair_duration gauge
app_name_self_repair_duration 0.265227453
# HELP app_name_db_duration
# TYPE app_name_db_duration histogram
app_name_db_duration_bucket{query="get_transaction",le="0.01"} 443481
app_name_db_duration_bucket{query="get_transaction",le="0.025"} 447919
app_name_db_duration_bucket{query="get_transaction",le="0.05"} 456449
app_name_db_duration_bucket{query="get_transaction",le="0.1"} 472222
app_name_db_duration_bucket{query="get_transaction",le="0.3"} 472571
app_name_db_duration_bucket{query="get_transaction",le="0.5"} 472605
app_name_db_duration_bucket{query="get_transaction",le="0.8"} 472617
app_name_db_duration_bucket{query="get_transaction",le="1"} 472621
app_name_db_duration_bucket{query="get_transaction",le="1.5"} 472624
app_name_db_duration_bucket{query="get_transaction",le="+Inf"} 472624
app_name_db_duration_sum{query="get_transaction"} 1894.9452645920032
app_name_db_duration_count{query="get_transaction"} 472624
app_name_db_duration_bucket{query="get_transaction_chain",le="0.01"} 54589
app_name_db_duration_bucket{query="get_transaction_chain",le="0.025"} 55305
app_name_db_duration_bucket{query="get_transaction_chain",le="0.05"} 56016
app_name_db_duration_bucket{query="get_transaction_chain",le="0.1"} 59266
app_name_db_duration_bucket{query="get_transaction_chain",le="0.3"} 1461041
app_name_db_duration_bucket{query="get_transaction_chain",le="0.5"} 2154344
app_name_db_duration_bucket{query="get_transaction_chain",le="0.8"} 2159971
app_name_db_duration_bucket{query="get_transaction_chain",le="1"} 2160450
app_name_db_duration_bucket{query="get_transaction_chain",le="1.5"} 2160851
app_name_db_duration_bucket{query="get_transaction_chain",le="+Inf"} 2161614
app_name_db_duration_sum{query="get_transaction_chain"} 589251.955250992
app_name_db_duration_count{query="get_transaction_chain"} 2161614
# HELP app_name_replication_validation_duration
# TYPE app_name_replication_validation_duration histogram
app_name_replication_validation_duration_bucket{le="0.01"} 953
app_name_replication_validation_duration_bucket{le="0.025"} 17268
app_name_replication_validation_duration_bucket{le="0.05"} 17598
app_name_replication_validation_duration_bucket{le="0.1"} 17705
app_name_replication_validation_duration_bucket{le="0.3"} 17837
app_name_replication_validation_duration_bucket{le="0.5"} 17913
app_name_replication_validation_duration_bucket{le="0.8"} 18019
app_name_replication_validation_duration_bucket{le="1"} 18099
app_name_replication_validation_duration_bucket{le="1.5"} 18266
app_name_replication_validation_duration_bucket{le="+Inf"} 18285
app_name_replication_validation_duration_sum 697.9178646500011
app_name_replication_validation_duration_count 18285
# HELP app_name_crypto_tpm_sign_duration
# TYPE app_name_crypto_tpm_sign_duration histogram
app_name_crypto_tpm_sign_duration_bucket{le="0.01"} 3663
app_name_crypto_tpm_sign_duration_bucket{le="0.025"} 209901
app_name_crypto_tpm_sign_duration_bucket{le="0.05"} 254318
app_name_crypto_tpm_sign_duration_bucket{le="0.1"} 264880
app_name_crypto_tpm_sign_duration_bucket{le="0.2"} 265617
app_name_crypto_tpm_sign_duration_bucket{le="0.3"} 266163
app_name_crypto_tpm_sign_duration_bucket{le="0.4"} 266329
app_name_crypto_tpm_sign_duration_bucket{le="0.5"} 266329
app_name_crypto_tpm_sign_duration_bucket{le="1"} 266329
app_name_crypto_tpm_sign_duration_bucket{le="+Inf"} 266330
app_name_crypto_tpm_sign_duration_sum 5177.010243896026
app_name_crypto_tpm_sign_duration_count 266330
"""
i wanted to convert it into JSON format
[
{
"help": "app_name_db_duration",
"type": "histogram",
"metrics": [
{
"labels": {
"method": "query",
"label_handler": "get_transaction"
},
"quantiles": {
"0.01": "443481",
"0.025": "447919",
"0.05": "456449",
"0.1": "472222"
},
"count": "472624",
"sum": "1894.9452645920032"
},
{
"labels": {
"method": "query",
"label_handler": "get_transaction_chain"
},
"quantiles": {
"0.99": "3542.9",
"0.9": "1202.3",
"0.5": "1002.8"
},
"count": "4",
"sum": "345.01"
}
]
},
{
"help": "app_name_replication_validation_duration",
"type": "histogram",
"metrics": [
{
"quantiles": {
"0.99": "3542.9",
"0.9": "1202.3",
"0.5": "1002.8"
},
"count": "4",
"sum": "345.01"
}
]
},
{
"help": "app_name_crypto_tpm_sign_duration",
"type": "histogram",
"metrics": [
{
"quantiles": {
"0.99": "3542.9",
"0.9": "1202.3",
"0.5": "1002.8"
},
"count": "4",
"sum": "345.01"
}
]
}
]
i’m trying since a week to achieve this json format out of that text but with no luck i stuck there
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
stefanchrobot
Where did you get stuck?
I’d split the task into two problems: parsing the text and building the output. The first one seems a bit more challenging since you need to build a parser. You can do it by hand, but you can also use Nimble Parsec here which could help make the code more readable.
kokolegorille
While You should use a parser… You can also use Regex.
ambareesha7
with this code i’m in half way but the challenge is updating nested maps, if you see json format above the
metricshas two layer’s of nesting, updating this laters i’m facing challenges and other challenge is some lines has multiple labels and bucket values i have to capture that alsoambareesha7
I like your approach, can you please elaborate it more
stefanchrobot
The idea would be to split the parsing phase from the transformation phase, so you end up with two, but smaller and isolated problems to solve. On a high-level the code would be:
The job of
parsewould be to turn the text into some data structure, probably one that is close to the input. The job ofto_jsonwould be to transform the intermediate data structure to the desired JSON.Looking just at the example you gave, I’d go with something like this for the data structure:
It should be pretty straightforward to build a list of
%Metric{}s from the input you’re given and then transform it to the output JSON.ambareesha7
thank you @stefanchrobot i’m working on some idea given by my senior
ambareesha7
i’m done with converting text into JSON structure,
now i wanted to do Aggregate histogram metrics,
to know what is the response time in given milliseconds
i have these below details:
prometheus has built-in tools for it
elastic search also has its own tools
but i could not get what logic they applied?
because i wanted to do my own functions to calculate and then use echarts to show results on graph
what logic to apply? to calculate response time