diff --git a/README.md b/README.md index e81eee0..e3c27af 100644 --- a/README.md +++ b/README.md @@ -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 @@ -48,7 +48,6 @@ You can also consult the API documentation: - ## Puppet Reporting The puppet-server has integrated support for submitting reports to @@ -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 @@ -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 @@ -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: @@ -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. @@ -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 diff --git a/cmd_serve.go b/cmd_serve.go index a7e9ded..2df295f 100644 --- a/cmd_serve.go +++ b/cmd_serve.go @@ -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 diff --git a/db.go b/db.go index 345b7f8..a7d0e9f 100644 --- a/db.go +++ b/db.go @@ -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 @@ -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. // @@ -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. diff --git a/db_test.go b/db_test.go index f576ab1..695b4b1 100644 --- a/db_test.go +++ b/db_test.go @@ -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) } @@ -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) } diff --git a/samples/systemd_service.txt b/samples/systemd_service.txt new file mode 100644 index 0000000..32d8d1e --- /dev/null +++ b/samples/systemd_service.txt @@ -0,0 +1,18 @@ +To have puppet-summary start as a daemon: + +cd /etc/systemd/system + +cat < 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