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

Add pgbouncer input plugin #3918

Merged
merged 3 commits into from
Aug 1, 2018
Merged

Add pgbouncer input plugin #3918

merged 3 commits into from
Aug 1, 2018

Conversation

nerzhul
Copy link
Contributor

@nerzhul nerzhul commented Mar 21, 2018

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:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

You will find a grafana output example below

capture d ecran de 2018-03-21 23-52-31

@nerzhul nerzhul changed the title Add pgbouncer support to telegraf Add pgbouncer input plugin Mar 21, 2018
@nerzhul
Copy link
Contributor Author

nerzhul commented Mar 21, 2018

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)

@danielnelson
Copy link
Contributor

Thanks for the pull request, I won't be able to review until 1.6 is out unfortunately.

@nerzhul
Copy link
Contributor Author

nerzhul commented Mar 22, 2018

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

@nerzhul
Copy link
Contributor Author

nerzhul commented Apr 24, 2018

@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

@nerzhul
Copy link
Contributor Author

nerzhul commented May 11, 2018

@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"
```
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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")
}
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@nerzhul
Copy link
Contributor Author

nerzhul commented May 14, 2018

Thanks for the review, i will fix the points soon

@nerzhul
Copy link
Contributor Author

nerzhul commented May 16, 2018

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

Copy link

@zaaraameera2014 zaaraameera2014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks u

@nerzhul
Copy link
Contributor Author

nerzhul commented May 16, 2018

@zaaraameera2014 i don't really understand why did you requested changes saying thanks you

Copy link
Contributor

@danielnelson danielnelson left a 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)
Copy link
Contributor

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.

@freeseacher
Copy link
Contributor

hey anybody :) ? do smthing :)

@nerzhul
Copy link
Contributor Author

nerzhul commented Jul 17, 2018

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
@nerzhul
Copy link
Contributor Author

nerzhul commented Jul 17, 2018

@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) {
Copy link
Contributor

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
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right

@glinton
Copy link
Contributor

glinton commented Jul 24, 2018

I think once the last things daniel requested are complete, this will be good to go

@nerzhul
Copy link
Contributor Author

nerzhul commented Jul 24, 2018

@glinton i think i lost a commit when rebasing... yeah :(

@glinton
Copy link
Contributor

glinton commented Jul 24, 2018

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

@nerzhul
Copy link
Contributor Author

nerzhul commented Jul 24, 2018

@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

@nerzhul
Copy link
Contributor Author

nerzhul commented Jul 24, 2018

@glinton i think we are good. I found the original commit history after updating on my own GH repo (see nerzhul@c4c3838)
The ignored tags are handled. The other case is handled in this subcommit: nerzhul@0c41e8d

@nerzhul
Copy link
Contributor Author

nerzhul commented Aug 1, 2018

@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

@freeseacher
Copy link
Contributor

pretty crazy pgbouncer history with telegraf :)

@glinton glinton added this to the 1.8.0 milestone Aug 1, 2018
@glinton
Copy link
Contributor

glinton commented Aug 1, 2018

I think this can be merged once @danielnelson verifies this review comment has been resolved. Thanks for the patience

@glinton glinton merged commit 429d141 into influxdata:master Aug 1, 2018
@nerzhul
Copy link
Contributor Author

nerzhul commented Aug 2, 2018

Thanks for your time and the merge

rgitzel pushed a commit to rgitzel/telegraf that referenced this pull request Oct 17, 2018
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

postgresql_extensible.query cannot connect to pgbouncer
5 participants