rrd based system stats
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

111 lines
3.2 KiB

  1. # Toplevel Makefile
  2. WITH_RRD?=yes
  3. PLUGINS := ctstat diskstat hwmon load memory mount netdev random rtstat stat uptime vmstat
  4. #PLUGINS += apache mysql conntrack alixusv ts2 diskstandby hddtemp
  5. DESTDIR =
  6. BINARY_DIR = /usr/local/bin
  7. CONFIG_DIR = /usr/local/etc
  8. PLUGIN_DIR = /usr/local/lib/sammler
  9. DATA_DIR = /var/lib/sammler
  10. LOG_DIR = /var/log
  11. PID_DIR = /var/run
  12. WWW_DIR = /var/www
  13. WWW_CONFIG = $(WWW_DIR)/sammler_graph.conf
  14. WWW_OWNER = www-data
  15. # ############################
  16. SRC := $(wildcard *.c)
  17. BUILD_DIR = build
  18. CFLAGS = -O2 -g -pipe -Wall -Wno-unused-result -I.
  19. CFLAGS += -MMD -MF $(BUILD_DIR)/$(*D)/$(*F).d
  20. LDFLAGS = -rdynamic -ldl
  21. # ############################
  22. ifeq ("$(WITH_RRD)", "yes")
  23. CFLAGS += -DWITH_RRD
  24. LDFLAGS_TARGET = -lrrd
  25. TARGET = sammler
  26. else
  27. LDFLAGS_TARGET =
  28. TARGET = sammler_norrd
  29. endif
  30. ifeq ($(strip $(wildcard $(DESTDIR)$(CONFIG_DIR)/sammler.conf)),)
  31. NEWCONF=sammler.conf
  32. else
  33. NEWCONF=sammler.conf.dist
  34. endif
  35. # ############################
  36. all: $(TARGET) plugins
  37. $(TARGET): $(patsubst %,$(BUILD_DIR)/%, $(SRC:.c=.o))
  38. @echo " Linking file: $@"
  39. @$(CC) $^ $(LDFLAGS) $(LDFLAGS_TARGET) -o $@
  40. $(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
  41. @echo " Building file: $<"
  42. @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
  43. @$(CC) $(CFLAGS) -o $@ -c $<
  44. .PHONY: plugins
  45. plugins: $(PLUGINS:%=plugins/%.so)
  46. .SECONDARY: $(patsubst %,$(BUILD_DIR)/%, $(PLUGINS:%=plugins/%.o))
  47. plugins/%.so: $(BUILD_DIR)/plugins/%.o
  48. @echo " Linking file: $@"
  49. @$(CC) $(LDFLAGS) -shared -o $@ $<
  50. plugins/apache.so: $(BUILD_DIR)/plugins/apache.o
  51. @echo " Linking file: $@"
  52. @$(CC) $(LDFLAGS) -shared -lcurl -o $@ $<
  53. plugins/conntrack.so: $(BUILD_DIR)/plugins/conntrack.o
  54. @echo " Linking file: $@"
  55. @$(CC) $(LDFLAGS) -shared -lnfnetlink -lnetfilter_conntrack -o $@ $<
  56. plugins/mysql.so: $(BUILD_DIR)/plugins/mysql.o $(BUILD_DIR)/plugins/mysql_helper.o
  57. @echo " Linking file: $@"
  58. @$(CC) $(LDFLAGS) -shared -lmysqlclient -o $@ $^
  59. plugins/diskstandby.so: $(BUILD_DIR)/plugins/diskstandby.o $(BUILD_DIR)/plugins/sgio.o
  60. @echo " Linking file: $@"
  61. @$(CC) $(LDFLAGS) -shared -o $@ $^
  62. install: all
  63. install -D -m 755 -s $(TARGET) $(DESTDIR)$(BINARY_DIR)/$(TARGET)
  64. install -D -m 644 sammler.conf $(DESTDIR)$(CONFIG_DIR)/$(NEWCONF)
  65. sed -i -e "s:^logfile .*$$:logfile $(LOG_DIR)/sammler.log:" \
  66. -e "s:^pidfile .*$$:pidfile $(PID_DIR)/sammler.pid:" \
  67. -e "s:^rrd_dir .*$$:rrd_dir $(DATA_DIR):" \
  68. -e "s:^plugin_dir .*$$:plugin_dir $(PLUGIN_DIR):" \
  69. $(DESTDIR)$(CONFIG_DIR)/$(NEWCONF)
  70. install -d -m 755 $(DESTDIR)$(PLUGIN_DIR)
  71. install -m 755 -s plugins/*.so $(DESTDIR)$(PLUGIN_DIR)
  72. install -d -m 755 $(DESTDIR)$(LOG_DIR)
  73. ifeq ("$(WITH_RRD)", "yes")
  74. install -d -m 755 $(DESTDIR)$(DATA_DIR)
  75. install -D -m 644 sammler.php $(DESTDIR)$(WWW_DIR)/sammler.php
  76. sed -i -e "s:%%WWW_CONFIG%%:$(WWW_CONFIG):" \
  77. -e "s:%%DATA_DIR%%:$(DATA_DIR)/:" \
  78. $(DESTDIR)$(WWW_DIR)/sammler.php
  79. ifeq ($(strip $(wildcard $(DESTDIR)$(WWW_CONFIG))),)
  80. -install -D -m 644 -o $(WWW_OWNER) /dev/null $(DESTDIR)$(WWW_CONFIG)
  81. endif
  82. else
  83. sed -i -e "s:^forward_only .*$$:forward_only true:" \
  84. $(DESTDIR)$(CONFIG_DIR)/$(NEWCONF)
  85. endif
  86. clean:
  87. rm -rf build plugins/*.so $(TARGET)
  88. include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)