Skip to content

Commit

Permalink
Merge branch 'master' of github.com:skx/puppet-summary
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed May 4, 2024
2 parents bc98a42 + 8ecc44b commit 2f0d343
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Table of Contents
* [Puppet Summary](#puppet-summary)
* [Puppet Reporting](#puppet-reporting)
* [Installation](#installation)
* [Source Installation go <= 1.11](#source-installation-go---111)
* [Source installation go >= 1.12](#source-installation-go---112)
* [Source Installation](#source-installation)
* [Execution](#execution)
* [Importing Puppet State](#importing-puppet-state)
* [Maintenance](#maintenance)
* [Metrics](#metrics)
* [Notes On Deployment](#notes-on-deployment)
* [Service file for systemd](#service-file-for-systemd)
* [Github Setup](#github-setup)

Puppet Summary
Expand Down Expand Up @@ -48,7 +48,6 @@ You can also consult the API documentation:




## Puppet Reporting

The puppet-server has integrated support for submitting reports to
Expand All @@ -67,26 +66,33 @@ only contains a summary of the available data it will not grow excessively.
> The software has [been reported](https://github.com/skx/puppet-summary/issues/42) to cope with 16k reports per day, archive approximately 27Gb of data over 14 days!


## Installation

There are two ways to install this project from source, which depend on the version of the [go](https://golang.org/) version you're using.
Installing the service can be done in one of two ways, depending on whether you have the [go](https://golang.org/) toolchain available:

If you just need the binaries you can find them upon the [project release page](https://github.com/skx/puppet-summary/releases).
* Download the appropriate binary from our [project release page](https://github.com/skx/puppet-summary/releases).
* Install from source, as documented below.


### Source Installation go <= 1.11
### Source Installation

If you're using `go` before 1.11 then the following command should fetch/update the project and install it upon your system:
If you're planning to make changes to the code, or examine it, then the obvious approach to installing from source is to clone the code, then build and install it from that local clone:

$ go get -u github.com/skx/puppet-summary
git clone https://github.com/skx/puppet-summary
cd puppet-summary
go install .

### Source installation go >= 1.12
You could install directly from source, without cloning the repository as an interim step, by running:

If you're using a more recent version of `go` (which is _highly_ recommended), you need to clone to a directory which is not present upon your `GOPATH`:
go install github.com/skx/puppet-summary@master

In either case you'll find a binary named `puppet-summary` placed inside a directory named `bin` beneath the golang GOPATH directory. To see exactly where this is please run:

echo $(go env GOPATH)/bin

(Typically you'd find binaries deployed to the directory `~/go/bin`, however this might vary.)

git clone https://github.com/skx/puppet-summary
cd puppet-summary
go install


## Execution
Expand All @@ -101,11 +107,17 @@ If you wish to change the host/port you can do so like this:
$ puppet-summary serve -host 10.10.10.10 -port 4321
Launching the server on http://10.10.10.10:4321

To have it listen on any available IP address, use one of these examples:

$ puppet-summary serve -host "" -port 4321
$ puppet-summary serve -host 0.0.0.0 -port 4321

Other sub-commands are described later, or can be viewed via:

$ puppet-summary help



## Importing Puppet State

Once you've got an instance of `puppet-summary` installed and running
Expand Down Expand Up @@ -133,6 +145,7 @@ but that is a reasonable default.
* It also assumes you're running the `puppet-summary` instance upon the puppet-master, if you're on a different host remember to change the URI.



## Maintenance

Over time your reports will start to consuming ever-increasing amounts of disk-space so they should be pruned. To prune (read: delete) old reports run:
Expand Down Expand Up @@ -166,6 +179,7 @@ to it :
The metrics include the count of nodes in each state, `changed`, `unchanged`, `failed`, and `orphaned` and can be used to raise alerts when things fail. When running with `-nop` the metrics will be dumped to the console instead of submitted.



## Notes On Deployment

If you can run this software upon your puppet-master then that's the ideal, that way your puppet-master would be configured to uploaded your reports to `127.0.0.1:3001/upload`, and the dashboard itself may be viewed via a reverse-proxy.
Expand Down Expand Up @@ -197,6 +211,12 @@ The appeal of allowing submissions from the loopback is that your reverse-proxy
* For example "`puppet-summary serve -db-file ./new.db`", "`puppet-summary metrics -db-file ./new.db`", and "`puppet-summary prune -db-file ./new.db`".


### Service file for systemd

You can find instructions on how to create a service file for systemd in the [samples](samples) directory.



## Github Setup

This repository is configured to run tests upon every commit, and when
Expand Down
2 changes: 1 addition & 1 deletion cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ func IndexHandler(res http.ResponseWriter, req *http.Request) {
//
// Get the graph-data
//
graphs, err := getHistory(environment)
graphs, err := getHistory(environment, 30)
if err != nil {
status = http.StatusInternalServerError
return
Expand Down
13 changes: 10 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func getReports(fqdn string) ([]PuppetReportSummary, error) {
//
// Get data for our stacked bar-graph
//
func getHistory(environment string) ([]PuppetHistory, error) {
func getHistory(environment string, limit int) ([]PuppetHistory, error) {

//
// Ensure we have a DB-handle
Expand All @@ -667,15 +667,19 @@ func getHistory(environment string) ([]PuppetHistory, error) {
//
var res []PuppetHistory

if limit < 2 {
limit = 60
}
//
// An array to hold the unique dates we've seen.
//
var dates []string

sel := "SELECT DISTINCT(strftime('%d/%m/%Y', DATE(executed_at, 'unixepoch'))) FROM reports"
sel := "SELECT DISTINCT(strftime('%d/%m/%Y', DATE(executed_at, 'unixepoch', 'localtime'))) FROM reports"
if len(environment) > 0 {
sel = sel + " WHERE environment = '" + environment + "'"
}
sel = sel + " ORDER BY executed_at DESC"
//
// Get all the distinct dates we have data for.
//
Expand Down Expand Up @@ -707,12 +711,15 @@ func getHistory(environment string) ([]PuppetHistory, error) {
if err != nil {
return nil, err
}
if ( len(dates) < limit ){
limit = len(dates)
}

//
// Now we have all the unique dates in `dates`.
//
loc, _ := time.LoadLocation("Local")
for _, known := range dates {
for _, known := range dates[:limit] { // but we only get the first limit days PuppetHistory.

//
// The result for this date.
Expand Down
4 changes: 2 additions & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestMissingInit(t *testing.T) {
t.Errorf("Got wrong error: %v", err)
}

_, err = getHistory("")
_, err = getHistory("", 60)
if !reg.MatchString(err.Error()) {
t.Errorf("Got wrong error: %v", err)
}
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestHistory(t *testing.T) {
//
// We have three fake nodes now, two of which have the same hostname.
//
runs, err := getHistory("")
runs, err := getHistory("", 60)
if err != nil {
t.Errorf("getHistory failed: %v", err)
}
Expand Down
18 changes: 18 additions & 0 deletions samples/systemd_service.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
To have puppet-summary start as a daemon:

cd /etc/systemd/system

cat <<EOF > puppet-summary.service
[Unit]
Description=Web interface providing reporting features for Puppet
[Service]
Type=simple
WorkingDirectory=/opt/puppet-summary
ExecStart=/opt/puppet-summary/puppet-summary serve -auto-prune -host 0.0.0.0
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && \
systemctl enable --now puppet-summary.service && \
systemctl status puppet-summary.service

0 comments on commit 2f0d343

Please sign in to comment.