Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphite format - willing to submit pull request #22

Open
JohnnyMarnell opened this issue Apr 23, 2019 · 2 comments
Open

Graphite format - willing to submit pull request #22

JohnnyMarnell opened this issue Apr 23, 2019 · 2 comments

Comments

@JohnnyMarnell
Copy link

JohnnyMarnell commented Apr 23, 2019

Hey there, love the details with these metrics!

I wrote a NodeJS script to flatten / convert json output into a graphite line protocol ready format here:
https://gist.github.com/JohnnyMarnell/0ab7e95e2994b7960fe7a32667a529df

If I were to start porting it to Go (n00b), would you consider a pull request?

Something like pgmetrics -f graphite?

@JohnnyMarnell
Copy link
Author

Here's how I use it, by the way:

pgmetrics -wfjson | node pgmetrics.js | nc $GRAPHITE_HOST $GRAPHITE_PORT

And this is a snippet example of the translated graphite line protocol metrics being translated from pgmetrics json via this script, and fed to graphite server via netcat:

pgmetrics.start_time 1556036264 1556041852
pgmetrics.checkpoint_time 1556036564 1556041852
pgmetrics.databases.postgres.datdba 10 1556041852
pgmetrics.databases.postgres.dattablespace 1663 1556041852
pgmetrics.databases.postgres.datconnlimit -1 1556041852
pgmetrics.databases.postgres.tup_returned 19048457 1556041852
pgmetrics.databases.postgres.tup_fetched 186900 1556041852
pgmetrics.databases.postgres.tup_inserted 1392 1556041852
pgmetrics.databases.postgres.tup_updated 200 1556041852
pgmetrics.databases.postgres.tup_deleted 2 1556041852
pgmetrics.wal_archiving.archived_count 0 1556041852
pgmetrics.wal_archiving.last_archived_time 0 1556041852
pgmetrics.wal_archiving.failed_count 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.heap_blks_hit 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.idx_blks_read 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.idx_blks_hit 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.toast_blks_read 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.toast_blks_hit 0 1556041852
pgmetrics.tables.__DATABASE_NAME__.public.root.__TABLE_NAME__.tidx_blks_read 0 1556041852

@mdevan
Copy link
Contributor

mdevan commented Apr 24, 2019

Yes, a PR for native graphite support is welcome!

I suggest starting off by copying cmd/pgmetrics/csv.go to cmd/pgmetrics/graphite.go, and esstentially port your JS code to a top-level function:

func model2graphite(m *pgmetrics.Model, w io.Writer) (err error) {
    // ...
}

similar to the existing model2csv function. Then modify main.go, add an option for graphite wherever you find a csv.

  • Your JS code is incredibly compact, be warned that the Go version might end up with a lot more lines -- but this is ok!
  • The CSV version outputs only a subset of the full json. It'd be nice to have the at least these in the graphite version also.
  • If you're new to Go, you might find it's easier to experiment on a direct checkout of this repo (although without being able to push your commits) than if you fork it (the code would still reference the original module). Once you get the hang of it, you can fork and send in a PR the usual way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants