-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Obmondo/add/puppet-agent-exporter
add puppet agent exporter
- Loading branch information
Showing
5 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Use the official Golang image to build the application | ||
FROM golang:1.23 AS builder | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the go.mod files first to leverage Docker cache | ||
COPY puppet-agent-exporter/exporter/go.mod ./ | ||
|
||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed | ||
RUN go mod download | ||
|
||
# Copy the source code into the container | ||
COPY puppet-agent-exporter/exporter/ ./ | ||
|
||
# Used for testings | ||
# COPY metrics/ metrics/ | ||
|
||
# Build the Go app | ||
RUN CGO_ENABLED=0 go build -o exporter . | ||
|
||
# Start a new stage from scratch | ||
FROM alpine:latest | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the Pre-built binary file from the previous stage | ||
COPY --from=builder /app/exporter . | ||
|
||
# Used for testing | ||
# COPY --from=builder /app/metrics/ /var/lib/prometheus-dropzone/ | ||
|
||
# Expose port 8080 | ||
EXPOSE 8080 | ||
|
||
# Command to run the executable | ||
ENTRYPOINT ["./exporter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module exporter | ||
|
||
go 1.22.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var metricsDirPath string // Path to your metrics directory | ||
|
||
func init() { | ||
// Get the value of the environment variable "METRICS_PATH" | ||
metricsDirPath = os.Getenv("METRICS_PATH") | ||
|
||
// Check if the environment variable is set | ||
if metricsDirPath == "" { | ||
metricsDirPath = "/var/lib/prometheus-dropzone" | ||
} | ||
} | ||
|
||
// readMetrics reads all metrics files in the specified directory and returns their contents. | ||
func readMetrics() (string, error) { | ||
var metricsBuilder strings.Builder | ||
|
||
err := filepath.Walk(metricsDirPath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() && strings.HasSuffix(info.Name(), ".prom") { // Only read .prom files | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
metricsBuilder.Write(data) | ||
metricsBuilder.WriteString("\n") // Add a newline between files | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
return metricsBuilder.String(), nil | ||
} | ||
|
||
// metricsHandler handles requests to the /metrics endpoint. | ||
func metricsHandler(w http.ResponseWriter, r *http.Request) { | ||
metrics, err := readMetrics() | ||
if err != nil { | ||
log.Printf("/metrics fail 500") | ||
http.Error(w, "Could not read metrics", http.StatusInternalServerError) | ||
return | ||
} | ||
w.Header().Set("Content-Type", "text/plain; version=0.0.4; charset=utf-8") | ||
w.Write([]byte(metrics)) | ||
log.Printf("/metrics success 200") | ||
} | ||
|
||
func main() { | ||
http.HandleFunc("/metrics", metricsHandler) | ||
|
||
// Start the HTTP server | ||
port := ":8080" | ||
fmt.Printf("Starting server on port %s...\n", port) | ||
if err := http.ListenAndServe(port, nil); err != nil { | ||
fmt.Printf("Error starting server: %s\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# cat /var/lib/node_exporter/textfile_collector/htzhel1-ax41na.enableit.prom | ||
# HELP puppet_report_resources Resources broken down by their state | ||
# TYPE puppet_report_resources gauge | ||
# HELP puppet_report_time Resource apply times | ||
# TYPE puppet_report_time gauge | ||
# HELP puppet_report_changes Changed resources in the last puppet run | ||
# TYPE puppet_report_changes gauge | ||
# HELP puppet_report_events Resource application events | ||
# TYPE puppet_report_events gauge | ||
# HELP puppet_report Unix timestamp of the last puppet run | ||
# TYPE puppet_report gauge | ||
# HELP puppet_transaction_completed transaction completed status of the last puppet run | ||
# TYPE puppet_transaction_completed gauge | ||
# HELP puppet_cache_catalog_status whether a cached catalog was used in the run, and if so, the reason that it was used | ||
# TYPE puppet_cache_catalog_status gauge | ||
# HELP puppet_status the status of the client run | ||
# TYPE puppet_status gauge | ||
# Old metrics | ||
# New metrics | ||
puppet_report_resources{name="Changed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Corrective change",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Failed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Failed to restart",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Out of sync",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Restarted",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Scheduled",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Skipped",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_time{name="Fact generation",environment="production",host="htzhel1-ax41na.enableit"} 6.693851238116622 | ||
puppet_report_time{name="Startup time",environment="production",host="htzhel1-ax41na.enableit"} 0.346151763 | ||
puppet_report_time{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 761.693690136 | ||
puppet_report_changes{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Failure",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Success",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report{environment="production",host="htzhel1-ax41na.enableit"} 1724301654.438 | ||
puppet_transaction_completed{environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_cache_catalog_status{state="not_used",environment="production",host="htzhel1-ax41na.enableit"} 1 | ||
puppet_cache_catalog_status{state="explicitly_requested",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_cache_catalog_status{state="on_failure",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_status{state="failed",environment="production",host="htzhel1-ax41na.enableit"} 1 | ||
puppet_status{state="changed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_status{state="unchanged",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
THIS IS PAGE 1 ENDING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# cat /var/lib/node_exporter/textfile_collector/htzhel1-ax41na.enableit.prom | ||
# HELP puppet_report_resources Resources broken down by their state | ||
# TYPE puppet_report_resources gauge | ||
# HELP puppet_report_time Resource apply times | ||
# TYPE puppet_report_time gauge | ||
# HELP puppet_report_changes Changed resources in the last puppet run | ||
# TYPE puppet_report_changes gauge | ||
# HELP puppet_report_events Resource application events | ||
# TYPE puppet_report_events gauge | ||
# HELP puppet_report Unix timestamp of the last puppet run | ||
# TYPE puppet_report gauge | ||
# HELP puppet_transaction_completed transaction completed status of the last puppet run | ||
# TYPE puppet_transaction_completed gauge | ||
# HELP puppet_cache_catalog_status whether a cached catalog was used in the run, and if so, the reason that it was used | ||
# TYPE puppet_cache_catalog_status gauge | ||
# HELP puppet_status the status of the client run | ||
# TYPE puppet_status gauge | ||
# Old metrics | ||
# New metrics | ||
puppet_report_resources{name="Changed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Corrective change",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Failed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Failed to restart",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Out of sync",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Restarted",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Scheduled",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Skipped",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_resources{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_time{name="Fact generation",environment="production",host="htzhel1-ax41na.enableit"} 6.693851238116622 | ||
puppet_report_time{name="Startup time",environment="production",host="htzhel1-ax41na.enableit"} 0.346151763 | ||
puppet_report_time{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 761.693690136 | ||
puppet_report_changes{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Failure",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Success",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report_events{name="Total",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_report{environment="production",host="htzhel1-ax41na.enableit"} 1724301654.438 | ||
puppet_transaction_completed{environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_cache_catalog_status{state="not_used",environment="production",host="htzhel1-ax41na.enableit"} 1 | ||
puppet_cache_catalog_status{state="explicitly_requested",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_cache_catalog_status{state="on_failure",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_status{state="failed",environment="production",host="htzhel1-ax41na.enableit"} 1 | ||
puppet_status{state="changed",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
puppet_status{state="unchanged",environment="production",host="htzhel1-ax41na.enableit"} 0 | ||
THIS IS PAGE 2 ENDING |