-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add pgbouncer input plugin #3918
Conversation
I don't know if a such module can be merged for 1.6, this could be nice as we are finishing the qualification to use telegraf in our production farm to replace collectd, and currently we have some lacks in the postgresql queries & no pgbouncer support (i will provide postgresql queries later, for 1.7 i think) |
Thanks for the pull request, I won't be able to review until 1.6 is out unfortunately. |
No problem i can wait for 1.7 if needed, it's an internal qualification atm and we can keep collectd for a moment to finish our configurations |
@danielnelson i hope you get time to review it i need to have it for 1.7 :) after merge i will improve the postgresql connector itself which has many missing data |
@danielnelson i solved the conflict with master branch. I will continue working on postgres metrics as soon as you take this PR for an action or a merge on master to improve the poor pg support in telegraf |
``` | ||
[[inputs.pgbouncer]] | ||
address = "postgres://telegraf@localhost/pgbouncer" | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add details about the measurement/tags/fields you are collecting, check the EXAMPLE_README.md
## Without the dbname parameter, the driver will default to a database | ||
## with the same name as the user. This dbname is just for instantiating a | ||
## connection with the server and doesn't restrict the databases we are trying | ||
## to grab metrics for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this info about the dbname can be removed from the sample config, it will be enough to have it in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return "Read metrics from one or many pgbouncer servers" | ||
} | ||
|
||
func (p *PgBouncer) IgnoredColumns() map[string]bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function is used, instead the map is access directly. Probably just remove this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dbname.WriteString((*columnMap["database"]).(string)) | ||
} else { | ||
dbname.WriteString("postgres") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too general purpose of a way to parse the stats. There are other columns we would probably want as tags such as pool_mode
and user
and I think it may be difficult to use a single function to parse all commands.
When new stats are added we will want to have a chance to decide if they are fields or tags, so I think they should be included manually, this does require a bit more upkeep but once a string is added as a field we can't switch it easily.
Unfortunately, I don't think we can specify the exact columns we are interested in, it would really nice to just be able to say select database,total_requests,... from stats;
I think we should return a map[string]interface{} from this function and have a function for each query to assign tags and call AddFields
. For SHOW STATS
the only tag would be database, and for SHOW POOLS
you would have database, user, and pool_mode as tags.
Optionally, consider not even reporting avg_req | avg_recv | avg_sent | avg_query
since these can all be calculated using the difference in totals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's fixed
fields[col] = *val | ||
} | ||
} | ||
acc.AddFields("pgbouncer", fields, tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be best to have two measurements: pgbouncer
and pgbouncer_pools
since the values are unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thanks for the review, i will fix the points soon |
except the documentation points, all technical points are fixed @danielnelson . Can you review another time please ? i will complete the doc as soon as you are okay with the technical fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks u
@zaaraameera2014 i don't really understand why did you requested changes saying thanks you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either whitelist the addition of fields or only add the fields if they are a numeric type; float or int. This will protect us against new string fields being added to pgbouncer that are either too long or would be better as tags.
} | ||
|
||
tags["user"] = (*columnMap["user"]).(string) | ||
tags["pool_mode"] = (*columnMap["pool_mode"]).(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add checks around these in case they don't exist or are not strings.
hey anybody :) ? do smthing :) |
Hey, thanks to remember me i need this, i need it myself at work but i'm on the metrology these days :) |
Properly load it & ignore database column Add pgbouncer docker image for tests
@danielnelson i know i'm late but i fixed the issue, it's mergeable now, i hope for 1.8 ? |
@@ -98,8 +98,15 @@ func (p *PgBouncer) Gather(acc telegraf.Accumulator) error { | |||
return err | |||
} | |||
|
|||
tags["user"] = (*columnMap["user"]).(string) | |||
tags["pool_mode"] = (*columnMap["pool_mode"]).(string) | |||
switch (*columnMap["user"]).(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this switch
, maybe do:
if s, ok := (*columnMap["pool_mode"]).(string); ok && s != "" {
tags["user"] = s
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right
I think once the last things daniel requested are complete, this will be good to go |
@glinton i think i lost a commit when rebasing... yeah :( |
ooh, not fun. You can merge master into your branch, rather than rebase, and push since we squash and merge, if that's more convenient for you |
@glinton generally i never do that to have a proper history, but the problem was the force push on a non locally updated branch, which loose some commits |
@glinton i think we are good. I found the original commit history after updating on my own GH repo (see nerzhul@c4c3838) |
@glinton can we expect this on 1.8 ? the PR is waiting for a merge since a long time (i know i lost time too at a point), we really need this in production to replace our collectd |
pretty crazy pgbouncer history with telegraf :) |
I think this can be merged once @danielnelson verifies this review comment has been resolved. Thanks for the patience |
Thanks for your time and the merge |
This requires an update on jackc/pgx to support a specific feature (v3.1.0 was chosen)
This PR will fix #3253 and normalize the pgbouncer component properly
Required for all PRs:
You will find a grafana output example below