|
7 | 7 | "context" |
8 | 8 | "crypto/tls" |
9 | 9 | "fmt" |
| 10 | + "io/fs" |
10 | 11 | "net/http" |
11 | 12 | "net/http/pprof" |
12 | 13 | "net/url" |
@@ -81,6 +82,14 @@ func (s *Server) setRouter(router *gin.Engine) { |
81 | 82 | router.UnescapePathValues = false |
82 | 83 | router.Use(s.PrometheusMiddleware) |
83 | 84 |
|
| 85 | + // Serve static files - need to create a sub-filesystem to strip the "static/" prefix |
| 86 | + staticFS, err := fs.Sub(StaticFiles, "static") |
| 87 | + if err != nil { |
| 88 | + s.logger.Error(err, "Failed to create static file sub-filesystem") |
| 89 | + } else { |
| 90 | + router.StaticFS("/static", http.FS(staticFS)) |
| 91 | + } |
| 92 | + |
84 | 93 | router.GET("/", s.IndexHandler) |
85 | 94 | router.GET("/debug/collector", s.CollectorHTMLHandler) |
86 | 95 | router.GET("/debug/job", s.JobHTMLHandler) |
@@ -294,35 +303,34 @@ func (s *Server) PrometheusMiddleware(c *gin.Context) { |
294 | 303 | func (s *Server) IndexHandler(c *gin.Context) { |
295 | 304 | c.Writer.Header().Set("Content-Type", "text/html") |
296 | 305 | WriteHTMLPageHeader(c.Writer, HeaderData{ |
297 | | - Title: "OpenTelemetry Target Allocator", |
| 306 | + Title: "Dashboard", |
298 | 307 | }) |
299 | 308 |
|
300 | | - WriteHTMLPropertiesTable(c.Writer, PropertiesTableData{ |
301 | | - Headers: []string{"Category", "Count"}, |
302 | | - Rows: [][]Cell{ |
303 | | - {scrapeConfigAnchorLink(), Text(strconv.Itoa(s.getScrapeConfigCount()))}, |
304 | | - {jobsAnchorLink(), Text(strconv.Itoa(s.getJobCount()))}, |
305 | | - {targetsAnchorLink(), Text(strconv.Itoa(len(s.allocator.TargetItems())))}, |
306 | | - }, |
307 | | - }) |
308 | | - WriteHTMLPropertiesTable(c.Writer, PropertiesTableData{ |
309 | | - Headers: []string{"Collector", "Job Count", "Target Count"}, |
310 | | - Rows: func() [][]Cell { |
311 | | - var rows [][]Cell |
312 | | - collectorNames := []string{} |
313 | | - for k := range s.allocator.Collectors() { |
314 | | - collectorNames = append(collectorNames, k) |
315 | | - } |
316 | | - sort.Strings(collectorNames) |
| 309 | + // Prepare collector data |
| 310 | + collectorNames := []string{} |
| 311 | + for k := range s.allocator.Collectors() { |
| 312 | + collectorNames = append(collectorNames, k) |
| 313 | + } |
| 314 | + sort.Strings(collectorNames) |
317 | 315 |
|
318 | | - for _, colName := range collectorNames { |
319 | | - jobCount := strconv.Itoa(s.getJobCountForCollector(colName)) |
320 | | - targetCount := strconv.Itoa(s.getTargetCountForCollector(colName)) |
321 | | - rows = append(rows, []Cell{collectorAnchorLink(colName), NewCell(jobCount), NewCell(targetCount)}) |
322 | | - } |
323 | | - return rows |
324 | | - }(), |
| 316 | + collectorData := []CollectorInfo{} |
| 317 | + for _, colName := range collectorNames { |
| 318 | + collectorData = append(collectorData, CollectorInfo{ |
| 319 | + Name: colName, |
| 320 | + JobCount: s.getJobCountForCollector(colName), |
| 321 | + TargetCount: s.getTargetCountForCollector(colName), |
| 322 | + }) |
| 323 | + } |
| 324 | + |
| 325 | + // Write dashboard |
| 326 | + WriteHTMLDashboard(c.Writer, DashboardData{ |
| 327 | + ScrapeConfigCount: s.getScrapeConfigCount(), |
| 328 | + JobCount: s.getJobCount(), |
| 329 | + TargetCount: len(s.allocator.TargetItems()), |
| 330 | + CollectorCount: len(s.allocator.Collectors()), |
| 331 | + CollectorData: collectorData, |
325 | 332 | }) |
| 333 | + |
326 | 334 | WriteHTMLPageFooter(c.Writer) |
327 | 335 | } |
328 | 336 |
|
|
0 commit comments